Creating a jar can be invoke from cli to generate tokens for all scopes refs #11584
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/context-enumeration@165652 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
commit
e7fb9d0d1d
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>context-enumeration</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,152 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>context-enumeration</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>Context Creation</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<serviceClass>InformationSystem</serviceClass>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
<connection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId}</connection>
|
||||
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube//trunk/information-system/${project.artifactId}</developerConnection>
|
||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>information-system-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portlets.admin</groupId>
|
||||
<artifactId>rmp-common-library</artifactId>
|
||||
<version>[2.7.1-SNAPSHOT,)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>discovery-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-configuration-scanner</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test Dependency -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>org.gcube.context.authorization.TokensUtil</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,43 @@
|
|||
package org.gcube.context;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class ContextElaborator {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public ContextElaborator(){
|
||||
|
||||
}
|
||||
|
||||
public void all(File voFile) throws Exception{
|
||||
try {
|
||||
|
||||
LinkedHashMap<String, ScopeBean> map = ScopeManager.readScopes(voFile.getAbsolutePath());
|
||||
for(String scope : map.keySet()) {
|
||||
try {
|
||||
String context = map.get(scope).toString();
|
||||
logger.debug("Going to elaborate {}", context);
|
||||
elaborateContext(map.get(scope));
|
||||
}catch (Exception e) {
|
||||
logger.error("Error while elaborating {}", scope, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void elaborateContext(ScopeBean scopeBean) throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package org.gcube.context.authorization;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
public class TokensUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TokensUtil.class);
|
||||
|
||||
|
||||
public static Map<String, String> getTokenForContexts(File voFile, String username, String serviceName) throws Exception{
|
||||
Map<String, String> scopeTokenMap = new HashMap<String, String>();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
|
||||
try {
|
||||
|
||||
LinkedHashMap<String, ScopeBean> map = ScopeManager.readScopes(voFile.getAbsolutePath());
|
||||
for(String scope : map.keySet()) {
|
||||
try {
|
||||
String context = map.get(scope).toString();
|
||||
System.out.println("Going to generate Token for Context " + context);
|
||||
logger.info("Going to generate Token for Context {}", context);
|
||||
UserInfo userInfo = new UserInfo(username, new ArrayList<>());
|
||||
String userToken = authorizationService().generateUserToken(userInfo, context);
|
||||
SecurityTokenProvider.instance.set(userToken);
|
||||
String generatedToken = authorizationService().generateExternalServiceToken(serviceName);
|
||||
scopeTokenMap.put(context, generatedToken);
|
||||
objectNode.put(context, generatedToken);
|
||||
|
||||
logger.info("Token for Context {} is {}", context, generatedToken);
|
||||
}catch (Exception e) {
|
||||
logger.error("Error while elaborating {}", scope, e);
|
||||
throw e;
|
||||
} finally {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw ex;
|
||||
}
|
||||
|
||||
File tokenFile = new File("tokens-"+serviceName+".json");
|
||||
objectMapper.writeValue(tokenFile, objectNode);
|
||||
|
||||
return scopeTokenMap;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println(args);
|
||||
if(args.length!=4) {
|
||||
System.out.println("Please provide 'vo file path' as first argument 'username' as second and 'external application name' as third");
|
||||
return;
|
||||
}
|
||||
File voFile = new File(args[1]);
|
||||
if(!voFile.exists()) {
|
||||
System.out.println(args[1] + " does not exists");
|
||||
return;
|
||||
}
|
||||
getTokenForContexts(voFile, args[2], args[3]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package org.gcube.context.names;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.context.ContextElaborator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ContextList extends ContextElaborator {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(ContextList.class);
|
||||
|
||||
protected File outputFile;
|
||||
|
||||
public ContextList(File outputFile) {
|
||||
this.outputFile = outputFile;
|
||||
}
|
||||
|
||||
public static void printLine(File file, String line) throws Exception {
|
||||
synchronized (file) {
|
||||
try (FileWriter fw = new FileWriter(file, true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
PrintWriter out = new PrintWriter(bw)) {
|
||||
out.println(line);
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void elaborateContext(ScopeBean scopeBean) throws Exception {
|
||||
printLine(outputFile, scopeBean.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.gcube.context.names;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestContextList {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File src = new File("src");
|
||||
File test = new File(src, "test");
|
||||
File resources = new File(test, "resources");
|
||||
|
||||
File voFile = new File(resources, "scopedata.xml");
|
||||
|
||||
File outputFile = new File(resources, "output.txt");
|
||||
|
||||
ContextList contextList = new ContextList(outputFile);
|
||||
contextList.all(voFile);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="org.gcube" level="TRACE" />
|
||||
<!-- logger name="org.gcube.accounting.aggregator" level="TRACE" / -->
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<infrastructures>
|
||||
<infrastructure>
|
||||
<name>d4science</name>
|
||||
<vos>
|
||||
<vo>
|
||||
<name>d4science</name>
|
||||
<src>ServiceMap_d4science.research-infrastructures.eu.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/D4Research</name>
|
||||
<src>ServiceMap_D4Research.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/D4Research</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/Edison</name>
|
||||
<src>ServiceMap_Edison.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/Edison</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/FARM</name>
|
||||
<src>ServiceMap_FARM.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/FARM</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/gCubeApps</name>
|
||||
<src>ServiceMap_gCubeApps.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/gCubeApps</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/OpenAIRE</name>
|
||||
<src>ServiceMap_OpenAIRE.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/OpenAIRE</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/ParthenosVO</name>
|
||||
<src>ServiceMap_ParthenosVO.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/ParthenosVO</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/SmartArea</name>
|
||||
<src>ServiceMap_SmartArea.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/SmartArea</scope>
|
||||
</vo>
|
||||
<vo>
|
||||
<name>d4science/SoBigData</name>
|
||||
<src>ServiceMap_SoBigData.xml</src>
|
||||
<scope>/d4science.research-infrastructures.eu/SoBigData</scope>
|
||||
</vo>
|
||||
</vos>
|
||||
</infrastructure>
|
||||
</infrastructures>
|
Loading…
Reference in New Issue