git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@132578 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
202183e928
commit
93101b776f
|
@ -38,10 +38,14 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String getRealToken(String token) {
|
protected static String getRealToken(String token) {
|
||||||
Pattern pattern = Pattern.compile(REAL_TOKEN_REGEXPR);
|
try{
|
||||||
Matcher matcher = pattern.matcher(token);
|
Pattern pattern = Pattern.compile(REAL_TOKEN_REGEXPR);
|
||||||
matcher.find();
|
Matcher matcher = pattern.matcher(token);
|
||||||
String realToken = matcher.group(1);
|
matcher.find();
|
||||||
return realToken;
|
String realToken = matcher.group(1);
|
||||||
|
return realToken;
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new RuntimeException("token required for this method", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,14 @@ public class CallTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNodeToken() throws Exception{
|
public void resolveNodeToken() throws Exception{
|
||||||
System.out.println(resolveToken("36501a0d-a205-4bf1-87ad-4c7185faa0d6")); //81caac0f-8a0d-4923-9312-7ff0eb3f2d5e|98187548"));
|
System.out.println(resolveToken("d7a6b96b-97eb-40fd-96ff-c8e5f37a91c7-98187548")); //81caac0f-8a0d-4923-9312-7ff0eb3f2d5e|98187548"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestNodeToken() throws Exception {
|
public void requestNodeToken() throws Exception {
|
||||||
System.out.println(_requestNodeToken());
|
System.out.println(_requestNodeToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addPolicy() throws Exception {
|
public void addPolicy() throws Exception {
|
||||||
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
|
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
|
||||||
|
@ -35,32 +35,36 @@ public class CallTest {
|
||||||
policies.add(new User2ServicePolicy("/gcube/devNext/NextNext", new ServiceAccess(), Users.one("lucio.lelii"), Action.ACCESS ));
|
policies.add(new User2ServicePolicy("/gcube/devNext/NextNext", new ServiceAccess(), Users.one("lucio.lelii"), Action.ACCESS ));
|
||||||
authorizationService().addPolicies(policies);
|
authorizationService().addPolicies(policies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPolicies() throws Exception{
|
public void getPolicies() throws Exception{
|
||||||
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
|
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
|
||||||
List<Policy> policies = authorizationService().getPolicies("/gcube/devsec/devVRE");
|
List<Policy> policies = authorizationService().getPolicies("/gcube/devsec/devVRE");
|
||||||
System.out.println(policies);
|
System.out.println(policies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removePolicy() throws Exception {
|
public void removePolicy() throws Exception {
|
||||||
authorizationService().removePolicies(2, 3, 4);
|
authorizationService().removePolicies(2, 3, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void requestToken() throws Exception{
|
||||||
|
System.out.println(authorizationService().generateUserToken(new UserInfo("andrea.dellamico", new ArrayList<String>()), "/gcube"));
|
||||||
|
}
|
||||||
@Test(expected=RuntimeException.class)
|
@Test(expected=RuntimeException.class)
|
||||||
public void createKeyWithError() throws Exception {
|
public void createKeyWithError() throws Exception {
|
||||||
authorizationService().generateApiKey("TEST");
|
authorizationService().generateApiKey("TEST");
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@Test
|
@Test
|
||||||
public void getSymmKey() throws Exception{
|
public void getSymmKey() throws Exception{
|
||||||
SecurityTokenProvider.instance.set(_requestNodeToken());
|
SecurityTokenProvider.instance.set(_requestNodeToken());
|
||||||
authorizationService().getSymmKey("/tmp");
|
authorizationService().getSymmKey("/tmp");
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createKey() throws Exception {
|
public void createKey() throws Exception {
|
||||||
String token = requestTestToken("/gcube");
|
String token = requestTestToken("/gcube");
|
||||||
|
@ -69,30 +73,31 @@ public class CallTest {
|
||||||
System.out.println("key : "+key);
|
System.out.println("key : "+key);
|
||||||
System.out.println(resolveToken(key));
|
System.out.println(resolveToken(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retrieveApiKeys() throws Exception {
|
public void retrieveApiKeys() throws Exception {
|
||||||
String token = requestTestToken("/gcube/devNext");
|
String token = requestTestToken("/gcube/devNext");
|
||||||
SecurityTokenProvider.instance.set(token);
|
SecurityTokenProvider.instance.set(token);
|
||||||
Map<String, String> keys = authorizationService().retrieveApiKeys();
|
Map<String, String> keys = authorizationService().retrieveApiKeys();
|
||||||
System.out.println("keys : "+keys);
|
System.out.println("keys : "+keys);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String _requestNodeToken() throws Exception {
|
public String _requestNodeToken() throws Exception {
|
||||||
|
SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
|
||||||
String token = authorizationService().requestActivation(new ContainerInfo("mynode",8080), "/gcube/devSec");
|
String token = authorizationService().requestActivation(new ContainerInfo("mynode",8080), "/gcube/devSec");
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createTestToken() throws Exception {
|
public void createTestToken() throws Exception {
|
||||||
System.out.println(requestTestToken("/gcube/devNext/NextNext"));
|
System.out.println(requestTestToken("/gcube/devNext/NextNext"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String requestTestToken(String context) throws Exception{
|
private String requestTestToken(String context) throws Exception{
|
||||||
return authorizationService().generateUserToken(new UserInfo("test.token", new ArrayList<String>()), context);
|
return authorizationService().generateUserToken(new UserInfo("test.token", new ArrayList<String>()), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthorizationEntry resolveToken(String token) throws Exception{
|
private AuthorizationEntry resolveToken(String token) throws Exception{
|
||||||
AuthorizationEntry entry = authorizationService().get(token);
|
AuthorizationEntry entry = authorizationService().get(token);
|
||||||
return entry;
|
return entry;
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package org.gcube.common.authorizationservice.cl;
|
||||||
|
|
||||||
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.client.proxy.AuthorizationProxy;
|
||||||
|
import org.gcube.common.authorization.library.provider.ContainerInfo;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
|
||||||
|
public class TokenGenerator {
|
||||||
|
|
||||||
|
//call with parameters : token host port filePath scope1 ... scopeN
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String host = args[0];
|
||||||
|
String adminToken = args[1];
|
||||||
|
int port = Integer.parseInt(args[2]);
|
||||||
|
File file = new File(args[3]);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
System.out.println("error creating file "+file.getAbsolutePath());
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ContainerInfo containerInfo = new ContainerInfo(host, port);
|
||||||
|
|
||||||
|
AuthorizationProxy proxy = authorizationService();
|
||||||
|
|
||||||
|
try(FileWriter fw = new FileWriter(file)){
|
||||||
|
for (int index =4; index<args.length; index++ ){
|
||||||
|
SecurityTokenProvider.instance.set(adminToken);
|
||||||
|
try {
|
||||||
|
String token = proxy.requestActivation(containerInfo, args[index] );
|
||||||
|
fw.write("<token>"+token+"</token>");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("error generating token for context "+args[index]);
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally{
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("error writing file "+file.getAbsolutePath());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue