library/roles/smartgears/smartgears: The new smartgears distributions are going to use the new authorization service. The container configuration changes heavily.

This commit is contained in:
Andrea Dell'Amico 2016-09-27 15:31:23 +02:00
parent 36e589b826
commit e8ffed284b
6 changed files with 124 additions and 13 deletions

Binary file not shown.

View File

@ -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<args.length; index++ ){
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]);
}
}
} catch (Exception e) {
System.out.println("error writing file "+file.getAbsolutePath());
e.printStackTrace();
}
}
}

View File

@ -47,13 +47,46 @@
notify: Restart smartgears notify: Restart smartgears
tags: [ 'smartgears', 'tomcat' ] tags: [ 'smartgears', 'tomcat' ]
- name: Install the smartgears configuration file - name: Create the directory where we put the smartgears configuration snippets
become: True become: True
become_user: '{{ smartgears_user }}' become_user: '{{ smartgears_user }}'
template: src=container.xml.j2 dest={{ smartgears_install_path }}/container.xml 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 }}' 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 register: containerxml_state
notify: Restart smartgears
tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ]
- name: Remove the smartgears application state if the configuration changed - name: Remove the smartgears application state if the configuration changed

View File

@ -0,0 +1 @@
</container>

View File

@ -10,12 +10,6 @@
{% else %} {% else %}
<port>{{ item.http_port }}</port> <port>{{ item.http_port }}</port>
{% endif %} {% endif %}
<infrastructure>{{ smartgears_infrastructure_name }}</infrastructure>
{% if smartgears_vo %}
{% for vo_n in smartgears_vo_name %}
<vo>{{ vo_n }}</vo>
{% endfor %}
{% endif %}
<site> <site>
<country>{{ smartgears_country }}</country> <country>{{ smartgears_country }}</country>
@ -27,6 +21,15 @@
<property name='SmartGearsDistributionBundle' value='UnBundled' /> <property name='SmartGearsDistributionBundle' value='UnBundled' />
<property name='SmartGearsDistribution' value='{{ smartgears_distribution_version }}' /> <property name='SmartGearsDistribution' value='{{ smartgears_distribution_version }}' />
<publication-frequency>60</publication-frequency> <publication-frequency>60</publication-frequency>
<infrastructure>{{ smartgears_infrastructure_name }}</infrastructure>
{% if smartgears_distribution_version | version_compare('2.0.0', '<') %}
{% if smartgears_vo %}
{% for vo_n in smartgears_vo_name %}
<vo>{{ vo_n }}</vo>
{% endfor %}
{% endif %}
{% if smartgears_define_context_vo %} {% if smartgears_define_context_vo %}
{% for context in smartgears_context %} {% for context in smartgears_context %}
@ -42,4 +45,5 @@
</application> </application>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</container>
{% endif %}

View File

@ -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