diff --git a/.classpath b/.classpath
index f9b0575..fae1a2b 100644
--- a/.classpath
+++ b/.classpath
@@ -22,7 +22,11 @@
-
+
+
+
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index ec4300d..714351a 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,5 @@
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/pom.xml b/pom.xml
index 4066031..1e77947 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.gcube.common
authorization-client
- 2.0.2-SNAPSHOT
+ 2.0.3-SNAPSHOT
authorization service client library
diff --git a/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java b/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java
index 0ca8912..ddac43c 100644
--- a/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java
+++ b/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java
@@ -73,7 +73,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
-
+
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
Binder.getContext().createMarshaller().marshal(client, os);
}
@@ -515,9 +515,11 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
@Override
public AuthorizationEndpoint getEndpoint(int infrastructureHash) {
- if (!endpoints.getEndpoints().containsKey(infrastructureHash))
- throw new RuntimeException("Authorization Endpoint not found for the required infrastructure");
- return endpoints.getEndpoints().get(infrastructureHash);
+ for (String infra: endpoints.getEndpoints().keySet()) {
+ if (Utils.getInfrastructureHashfromContext(infra)==infrastructureHash)
+ return endpoints.getEndpoints().get(infra);
+ }
+ throw new RuntimeException("Authorization Endpoint not found for the required infrastructure");
}
@Override
diff --git a/src/main/java/org/gcube/common/authorization/client/proxy/Utils.java b/src/main/java/org/gcube/common/authorization/client/proxy/Utils.java
index 9048554..a80cb99 100644
--- a/src/main/java/org/gcube/common/authorization/client/proxy/Utils.java
+++ b/src/main/java/org/gcube/common/authorization/client/proxy/Utils.java
@@ -11,11 +11,16 @@ public class Utils {
private static final String REAL_TOKEN_REGEXPR ="([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(-[0-9]+)?";
+
protected static int getInfrastructureHashfromContext(String context) {
try{
- String infrastructure = context.split("/")[1];
- return infrastructure.hashCode();
+ String infrastructure = context;
+ if (context.startsWith("/"))
+ infrastructure = context.substring(1);
+
+ int hashcode= infrastructure.hashCode();
+ return Math.abs(hashcode);
}catch(Exception e){
throw new RuntimeException("invalid context");
}
diff --git a/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java b/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java
index d6a9fb9..dc505b2 100644
--- a/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java
+++ b/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java
@@ -29,10 +29,15 @@ public class CallTest {
@Test
public void resolveNodeToken() throws Exception{
- System.out.println(resolveToken("d29fdd99-0e88-4f13-ae33-f52258e9f578-843339462")); //81caac0f-8a0d-4923-9312-7ff0eb3f2d5e|98187548"));
- System.out.println(resolveToken("d29fdd99-0e88-4f13-ae33-f52258e9f578-843339462").getClientInfo());
+ System.out.println(resolveToken("7f106b0f-e444-41a7-b101-4583ae8da3f8-980114272")); //81caac0f-8a0d-4923-9312-7ff0eb3f2d5e|98187548"));
+ System.out.println(resolveToken("7f106b0f-e444-41a7-b101-4583ae8da3f8-980114272").getClientInfo().getId());
}
+ @Test
+ public void haspred4s() {
+ System.out.println("pred4s".hashCode() & 0xfffffff);
+ }
+
@Test
public void requestUserTokenViaUserNameAndScope() throws Exception {
System.out.println(authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube/devNext/NextNext"));
@@ -45,8 +50,8 @@ public class CallTest {
@Test
public void requestExternalServiceToken() throws Exception {
- SecurityTokenProvider.instance.set(requestTestToken("/gcube/devsec/NextNext"));
- System.out.println(authorizationService().generateExternalServiceToken("org.gcube.datacatalogue.GRSFNotifier"));
+ SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
+ System.out.println(authorizationService().generateExternalServiceToken("URIResolver"));
}
@Test
@@ -83,7 +88,7 @@ public class CallTest {
@Test
public void generateToken() throws Exception{
- System.out.println(authorizationService().generateUserToken(new UserInfo("yankarlos.panikos", new ArrayList()), "/gcube/devNext/NextNext"));
+ System.out.println(authorizationService().generateUserToken(new UserInfo("guest", new ArrayList()), "/pred4s"));
}
@Test(expected=RuntimeException.class)
public void createKeyWithError() throws Exception {
@@ -117,17 +122,17 @@ public class CallTest {
public String _requestNodeToken() throws Exception {
SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
- String token = authorizationService().requestActivation(new ContainerInfo("workspace-repository1-d.d4science.org",80), "/gcube");
+ String token = authorizationService().requestActivation(new ContainerInfo("workspace-repository1-d.d4science.org",80), "/gcube/devsec");
return token;
}
@Test
public void createTestToken() throws Exception {
- System.out.println(requestTestToken("/gcube/devsec/devVRE"));
+ System.out.println(requestTestToken("/pred4s"));
}
private String requestTestToken(String context) throws Exception{
- return authorizationService().generateUserToken(new UserInfo("giancarlo.panichi", new ArrayList()), context);
+ return authorizationService().generateUserToken(new UserInfo("lucio.lelii", new ArrayList()), context);
}
private AuthorizationEntry resolveToken(String token) throws Exception{