git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@177199 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ecd3b1535c
commit
2bf6b03a8a
|
@ -22,7 +22,11 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
org.eclipse.jdt.core.compiler.source=1.7
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>authorization-client</artifactId>
|
<artifactId>authorization-client</artifactId>
|
||||||
<version>2.0.2-SNAPSHOT</version>
|
<version>2.0.3-SNAPSHOT</version>
|
||||||
<name>authorization service client library</name>
|
<name>authorization service client library</name>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setRequestProperty("Content-type", "application/xml");
|
connection.setRequestProperty("Content-type", "application/xml");
|
||||||
|
|
||||||
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
||||||
Binder.getContext().createMarshaller().marshal(client, os);
|
Binder.getContext().createMarshaller().marshal(client, os);
|
||||||
}
|
}
|
||||||
|
@ -515,9 +515,11 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthorizationEndpoint getEndpoint(int infrastructureHash) {
|
public AuthorizationEndpoint getEndpoint(int infrastructureHash) {
|
||||||
if (!endpoints.getEndpoints().containsKey(infrastructureHash))
|
for (String infra: endpoints.getEndpoints().keySet()) {
|
||||||
throw new RuntimeException("Authorization Endpoint not found for the required infrastructure");
|
if (Utils.getInfrastructureHashfromContext(infra)==infrastructureHash)
|
||||||
return endpoints.getEndpoints().get(infrastructureHash);
|
return endpoints.getEndpoints().get(infra);
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Authorization Endpoint not found for the required infrastructure");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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]+)?";
|
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) {
|
protected static int getInfrastructureHashfromContext(String context) {
|
||||||
try{
|
try{
|
||||||
String infrastructure = context.split("/")[1];
|
String infrastructure = context;
|
||||||
return infrastructure.hashCode();
|
if (context.startsWith("/"))
|
||||||
|
infrastructure = context.substring(1);
|
||||||
|
|
||||||
|
int hashcode= infrastructure.hashCode();
|
||||||
|
return Math.abs(hashcode);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new RuntimeException("invalid context");
|
throw new RuntimeException("invalid context");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,15 @@ public class CallTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNodeToken() throws Exception{
|
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("7f106b0f-e444-41a7-b101-4583ae8da3f8-980114272")); //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").getClientInfo().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void haspred4s() {
|
||||||
|
System.out.println("pred4s".hashCode() & 0xfffffff);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestUserTokenViaUserNameAndScope() throws Exception {
|
public void requestUserTokenViaUserNameAndScope() throws Exception {
|
||||||
System.out.println(authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube/devNext/NextNext"));
|
System.out.println(authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube/devNext/NextNext"));
|
||||||
|
@ -45,8 +50,8 @@ public class CallTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestExternalServiceToken() throws Exception {
|
public void requestExternalServiceToken() throws Exception {
|
||||||
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devsec/NextNext"));
|
SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
|
||||||
System.out.println(authorizationService().generateExternalServiceToken("org.gcube.datacatalogue.GRSFNotifier"));
|
System.out.println(authorizationService().generateExternalServiceToken("URIResolver"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -83,7 +88,7 @@ public class CallTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateToken() throws Exception{
|
public void generateToken() throws Exception{
|
||||||
System.out.println(authorizationService().generateUserToken(new UserInfo("yankarlos.panikos", new ArrayList<String>()), "/gcube/devNext/NextNext"));
|
System.out.println(authorizationService().generateUserToken(new UserInfo("guest", new ArrayList<String>()), "/pred4s"));
|
||||||
}
|
}
|
||||||
@Test(expected=RuntimeException.class)
|
@Test(expected=RuntimeException.class)
|
||||||
public void createKeyWithError() throws Exception {
|
public void createKeyWithError() throws Exception {
|
||||||
|
@ -117,17 +122,17 @@ public class CallTest {
|
||||||
|
|
||||||
public String _requestNodeToken() throws Exception {
|
public String _requestNodeToken() throws Exception {
|
||||||
SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
|
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;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createTestToken() throws Exception {
|
public void createTestToken() throws Exception {
|
||||||
System.out.println(requestTestToken("/gcube/devsec/devVRE"));
|
System.out.println(requestTestToken("/pred4s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String requestTestToken(String context) throws Exception{
|
private String requestTestToken(String context) throws Exception{
|
||||||
return authorizationService().generateUserToken(new UserInfo("giancarlo.panichi", new ArrayList<String>()), context);
|
return authorizationService().generateUserToken(new UserInfo("lucio.lelii", new ArrayList<String>()), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthorizationEntry resolveToken(String token) throws Exception{
|
private AuthorizationEntry resolveToken(String token) throws Exception{
|
||||||
|
|
Loading…
Reference in New Issue