git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@131036 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9e228feb92
commit
382e2b32cb
|
@ -266,7 +266,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
@Override
|
||||
public List<Policy> getPolicies(String context) throws Exception{
|
||||
final String methodPath = "/policyManager/";
|
||||
|
||||
|
||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(getInfrastructureHashfromContext(context))).append(methodPath).append("?").append(CONTEXT_PARAM).append("=").append(context);
|
||||
|
||||
URL url = new URL(callUrl.toString());
|
||||
|
@ -283,8 +283,10 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
|
||||
private HttpURLConnection makeRequest(URL url, String method, boolean includeTokenInHeader) throws Exception{
|
||||
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||
if (includeTokenInHeader)
|
||||
if (includeTokenInHeader){
|
||||
if (SecurityTokenProvider.instance.get()==null) throw new RuntimeException("null token passed");
|
||||
connection.setRequestProperty(Constants.TOKEN_HEADER_ENTRY,SecurityTokenProvider.instance.get());
|
||||
}
|
||||
connection.setRequestMethod(method);
|
||||
return connection;
|
||||
}
|
||||
|
@ -300,6 +302,6 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
public void setEndpoint(Map<Integer,AuthorizationEndpoint> endpoints) {
|
||||
this.endpoints = endpoints;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,23 +17,30 @@ import org.gcube.common.authorization.library.provider.UserInfo;
|
|||
import org.junit.Test;
|
||||
public class CallTest {
|
||||
|
||||
@Test
|
||||
public void resolveNodeToken() throws Exception{
|
||||
System.out.println(resolveToken("81caac0f-8a0d-4923-9312-7ff0eb3f2d5e|98187548"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestNodeToken() throws Exception {
|
||||
String token = authorizationService().requestActivation(new ContainerInfo("dlib29.isti.cnr.it",8080), "/gcube");
|
||||
String token = authorizationService().requestActivation(new ContainerInfo("dlib29.isti.cnr.it",8080), "/gcube/devNext/NextNext");
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addPolicy() throws Exception {
|
||||
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devsec/devVRE"));
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
policies.add(new User2ServicePolicy("/gcube/devsec", new ServiceAccess(), Users.one("lucio.lelii"), Action.ACCESS ));
|
||||
policies.add(new User2ServicePolicy("/gcube/devsec/devVRE", new ServiceAccess(), Users.one("lucio.lelii"), Action.ACCESS ));
|
||||
authorizationService().addPolicies(policies);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getPolicies() throws Exception{
|
||||
List<Policy> policies = authorizationService().getPolicies("/gcube/devsec");
|
||||
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devsec/devVRE"));
|
||||
List<Policy> policies = authorizationService().getPolicies("/gcube/devsec/devVRE");
|
||||
System.out.println(policies);
|
||||
}
|
||||
|
||||
|
@ -49,13 +56,17 @@ public class CallTest {
|
|||
|
||||
@Test
|
||||
public void createKey() throws Exception {
|
||||
String token = requestTestToken("/gcube");
|
||||
String token = requestTestToken("/gcube/devNext");
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
String key = authorizationService().generateApiKey("TEST");
|
||||
System.out.println("key : "+key);
|
||||
System.out.println(resolveToken(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTestToken() throws Exception {
|
||||
System.out.println(requestTestToken("/gcube/devsec"));
|
||||
}
|
||||
|
||||
private String requestTestToken(String context) throws Exception{
|
||||
return authorizationService().generateUserToken(new UserInfo("test.token", new ArrayList<String>()), context);
|
||||
|
|
Loading…
Reference in New Issue