diff --git a/smartgears/smartgears/files/TokenGenerator.class b/smartgears/smartgears/files/TokenGenerator.class new file mode 100644 index 00000000..56247ca2 Binary files /dev/null and b/smartgears/smartgears/files/TokenGenerator.class differ diff --git a/smartgears/smartgears/files/TokenGenerator.java b/smartgears/smartgears/files/TokenGenerator.java new file mode 100644 index 00000000..ba92ce10 --- /dev/null +++ b/smartgears/smartgears/files/TokenGenerator.java @@ -0,0 +1,53 @@ +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; + +import static org.gcube.common.authorization.client.Constants.authorizationService; + +public class TokenGenerator { + + 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]); + + try { + file.createNewFile(); + } catch (IOException e1) { + System.out.println("error creating file "+file.getAbsolutePath()); + 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"+token+""); + } catch (Exception e) { + System.out.println("error generating token for context "+args[index]); + } + } + } catch (Exception e) { + System.out.println("error writing file "+file.getAbsolutePath()); + e.printStackTrace(); + } + + + + } + +} + + diff --git a/smartgears/smartgears/tasks/smartgears-app.yml b/smartgears/smartgears/tasks/smartgears-app.yml index 0e62b7a6..ec0eb05a 100644 --- a/smartgears/smartgears/tasks/smartgears-app.yml +++ b/smartgears/smartgears/tasks/smartgears-app.yml @@ -47,15 +47,48 @@ notify: Restart smartgears tags: [ 'smartgears', 'tomcat' ] -- name: Install the smartgears configuration file +- name: Create the directory where we put the smartgears configuration snippets become: True become_user: '{{ smartgears_user }}' - template: src=container.xml.j2 dest={{ smartgears_install_path }}/container.xml - with_items: '{{ tomcat_m_instances }}' - register: containerxml_state - notify: Restart smartgears + file: dest={{ smartgears_user_home }}/.containerxml tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] +- name: Install the token generator class + file: src=TokenGeneartor.class dest=/usr/local/lib/TokenGenerator.class owner=root group=root mode=0644 + +- name: Install the script that fetches the scope tokens + template: src=get-scopes.j2 dest=/usr/local/bin/get-scopes owner=root group={{ smartgears_user }} mode=0750 + when: gcube_admin_token is defined + tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] + +- name: Get the scope tokens from the authorization service + become: True + become_user: '{{ smartgears_user }}' + shell: + when: gcube_admin_token is defined + tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] + +- name: Install the smartgears template configuration. First part + become: True + become_user: '{{ smartgears_user }}' + template: src=container.xml.j2 dest={{ smartgears_user_home }}/.containerxml/1-container.xml + with_items: '{{ tomcat_m_instances }}' + tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] + +- name: Install the smartgears template configuration file. Third part + become: True + become_user: '{{ smartgears_user }}' + template: src=container-end.xml.j2 dest={{ smartgears_user_home }}/.containerxml/3-container.xml + with_items: '{{ tomcat_m_instances }}' + tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] + +- name: Assemble the smartgears container.xml + become: True + become_user: '{{ smartgears_user }}' + assemble: src={{ smartgears_user_home }}/.containerxml dest={{ smartgears_install_path }}/container.xml + register: containerxml_state + tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] + - name: Remove the smartgears application state if the configuration changed file: dest={{ smartgears_install_path }}/state state=absent when: ( containerxml_state | changed ) diff --git a/smartgears/smartgears/templates/container-end.xml.j2 b/smartgears/smartgears/templates/container-end.xml.j2 new file mode 100644 index 00000000..41e32629 --- /dev/null +++ b/smartgears/smartgears/templates/container-end.xml.j2 @@ -0,0 +1 @@ + diff --git a/smartgears/smartgears/templates/container.xml.j2 b/smartgears/smartgears/templates/container.xml.j2 index ee1649e6..74a863fc 100644 --- a/smartgears/smartgears/templates/container.xml.j2 +++ b/smartgears/smartgears/templates/container.xml.j2 @@ -10,13 +10,7 @@ {% else %} {{ item.http_port }} {% endif %} - {{ smartgears_infrastructure_name }} - {% if smartgears_vo %} - {% for vo_n in smartgears_vo_name %} - {{ vo_n }} - {% endfor %} - {% endif %} - + {{ smartgears_country }} {{ smartgears_location }} @@ -27,6 +21,15 @@ 60 + {{ smartgears_infrastructure_name }} + + {% if smartgears_distribution_version | version_compare('2.0.0', '<') %} + {% if smartgears_vo %} + {% for vo_n in smartgears_vo_name %} + {{ vo_n }} + {% endfor %} + {% endif %} + {% if smartgears_define_context_vo %} {% for context in smartgears_context %} @@ -42,4 +45,5 @@ {% endfor %} {% endif %} - + +{% endif %} diff --git a/smartgears/smartgears/templates/get-scopes.j2 b/smartgears/smartgears/templates/get-scopes.j2 new file mode 100644 index 00000000..cd149d2a --- /dev/null +++ b/smartgears/smartgears/templates/get-scopes.j2 @@ -0,0 +1,20 @@ +#!/bin/bash + +DESTFILE={{ smartgears_user_home }}/.containerxml/2-container.xml +TOKEN= + +{%if setup_nginx %} +{%if https_port is defined %} +HTTP_PORT={{ https_port }} +{% else %} +HTTP_PORT={{ http_port }} +{% endif %} +{% else %} +HTTP_PORT={{ item.http_port }} +{% endif %} + +export CLASSPATH="/usr/local/lib:{{ smartgears_install_path }}/lib:$CLASSPATH" + +java TokenGenerator {{ gcube_admin_token }} {{ smartgears_hostname }} $HTTP_PORT $DESTFILE {% for scope in smartgears_scopes %}{{ scope }} {% endfor %} + +exit 0