library/roles/smartgears/smartgears: New TokenGenerator. Fix the container.xml template.

This commit is contained in:
Andrea Dell'Amico 2016-10-04 16:58:05 +02:00
parent 6a1ae88190
commit b7776c583a
4 changed files with 22 additions and 17 deletions

View File

@ -48,7 +48,7 @@ smartgears_context:
- '/ScalableDataMining'
smartgears_scopes:
- '{{ smartgears_infrastructure_name }}'
- '/{{ smartgears_infrastructure_name }}'
# The iptables rules use this
http_port: '{{ smartgears_http_port }}'

View File

@ -1,44 +1,46 @@
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 : host port filePath adminToken1 ... adminTokenN
//call with parameters : token host port filePath scope1 ... scopeN
public static void main(String[] args) {
String host = args[0];
int port = Integer.parseInt(args[1]);
File file = new File(args[2]);
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 =3; index<args.length; index++ ){
SecurityTokenProvider.instance.set(args[index]);
try {
String token = proxy.requestActivation(containerInfo);
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();
SecurityTokenProvider.instance.reset();
}
}
} catch (Exception e) {
@ -49,4 +51,3 @@ public class TokenGenerator {
}
}

View File

@ -2,12 +2,16 @@
<hostname>{{ smartgears_hostname }}</hostname>
{%if setup_nginx %}
{%if https_port is defined %}
{% if https_port is defined %}
{% if http_redirect_to_https is defined and http_redirect_to_https %}
<port>{{ https_port }}</port>
{% else %}
<port>{{ http_port }}</port>
{% endif %}
{% else %}
{%if http_port is defined %}
<port>{{ http_port }}</port>
{% endif %}
{% endif %}
{% else %}
<port>{{ item.http_port }}</port>