forked from ISTI-ansible-roles/ansible-roles
library/roles/smartgears/smartgears/files/TokenGenerator.java: New version of the token generator.
This commit is contained in:
parent
0fb19da11a
commit
9714cc66ee
|
@ -1,3 +1,5 @@
|
|||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
@ -6,16 +8,15 @@ import org.gcube.common.authorization.client.proxy.AuthorizationProxy;
|
|||
import org.gcube.common.authorization.library.provider.ContainerInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
public class TokenGenerator {
|
||||
|
||||
//call with parameters : host port filePath adminToken1 ... adminTokenN
|
||||
public static void main(String[] args) {
|
||||
|
||||
String adminToken = args[0];
|
||||
String host = args[1];
|
||||
int port = Integer.parseInt(args[2]);
|
||||
File file = new File(args[3]);
|
||||
String host = args[0];
|
||||
int port = Integer.parseInt(args[1]);
|
||||
File file = new File(args[2]);
|
||||
|
||||
|
||||
try {
|
||||
file.createNewFile();
|
||||
|
@ -24,19 +25,20 @@ public class TokenGenerator {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
SecurityTokenProvider.instance.set(adminToken);
|
||||
|
||||
ContainerInfo containerInfo = new ContainerInfo(host, port);
|
||||
|
||||
AuthorizationProxy proxy = authorizationService();
|
||||
|
||||
try(FileWriter fw = new FileWriter(file)){
|
||||
for (int index =4; index<args.length; index++ ){
|
||||
for (int index =3; index<args.length; index++ ){
|
||||
SecurityTokenProvider.instance.set(args[index]);
|
||||
try {
|
||||
String token = proxy.requestActivation(containerInfo, args[index]);
|
||||
String token = proxy.requestActivation(containerInfo);
|
||||
fw.write("<token>"+token+"</token>");
|
||||
} catch (Exception e) {
|
||||
System.out.println("error generating token for context "+args[index]);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -44,10 +46,7 @@ public class TokenGenerator {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue