70: Authetication Token
Task-Url: https://support.d4science.org/issues/70 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@115159 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3558ff0bdb
commit
d969cd1624
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>authorization-common-client</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -0,0 +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.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -1,10 +1,15 @@
|
|||
package org.gcube.common.authorization.client.proxy;
|
||||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.Service;
|
||||
|
||||
public interface AuthorizationProxy {
|
||||
|
||||
String generate(String userName, String role);
|
||||
|
||||
AuthorizationEntry get(String token);
|
||||
|
||||
void deny(String userName, Service service);
|
||||
|
||||
void allow(String userName, Service service);
|
||||
}
|
||||
|
|
|
@ -13,8 +13,10 @@ import java.util.Map;
|
|||
import org.gcube.common.authorization.client.Binder;
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.Service;
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.clients.stubs.jaxws.JAXWSUtils.Empty;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||
|
@ -47,6 +49,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
if (reader!=null)
|
||||
reader.close();
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
};
|
||||
|
@ -86,4 +89,44 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deny(final String userName, final Service service) {
|
||||
Call<String, Empty> call = new Call<String, Empty>() {
|
||||
@Override
|
||||
public Empty call(String endpoint) throws Exception {
|
||||
URL url = new URL(endpoint+"/deny/add/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
||||
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
return new Empty();
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
delegate.make(call);
|
||||
} catch (Exception e) {
|
||||
throw again(e).asServiceException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void allow(final String userName, final Service service) {
|
||||
Call<String, Empty> call = new Call<String, Empty>() {
|
||||
|
||||
@Override
|
||||
public Empty call(String endpoint) throws Exception {
|
||||
URL url = new URL(endpoint+"/deny/remove/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
||||
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
return new Empty();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
delegate.make(call);
|
||||
} catch (Exception e) {
|
||||
throw again(e).asServiceException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,24 +2,26 @@ package org.gcube.common.authorizationservice.cl;
|
|||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.Test;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.junit.Test;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.*;
|
||||
public class CallTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void call(){
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
String token = authorizationService().build().generate("lucio.lelii", "God");
|
||||
|
||||
System.out.println("token is "+token);
|
||||
|
||||
AuthorizationEntry entry = authorizationService().build().get(token);
|
||||
|
||||
System.out.println("entry is "+entry.toString());
|
||||
SimpleQuery query = queryFor(GenericResource.class);
|
||||
query.addCondition("$resource/Profile/SecondaryType eq 'StatisticalManagerAlgorithm' ");
|
||||
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
|
||||
List<GenericResource> resources = client.submit(query);
|
||||
for (GenericResource res : resources)
|
||||
System.out.println(res);
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,7 +29,7 @@ public class CallTest {
|
|||
public void requestToken(){
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
String token = authorizationService().build().generate("lucio.lelii", "God");
|
||||
String token = authorizationService().build().generate("lucio.le", "User");
|
||||
System.out.println("token is: "+token);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue