Fixing project
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/resource-registry-database-creator@169892 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d14ec3329f
commit
d94a7a4436
2
pom.xml
2
pom.xml
|
@ -54,11 +54,13 @@
|
||||||
<artifactId>gcube-resources</artifactId>
|
<artifactId>gcube-resources</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.information-system</groupId>
|
<groupId>org.gcube.information-system</groupId>
|
||||||
<artifactId>parthenos-entities</artifactId>
|
<artifactId>parthenos-entities</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.informationsystem.resourceregistry;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.client.Constants;
|
||||||
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
|
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ScopedTest {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class);
|
||||||
|
|
||||||
|
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||||
|
|
||||||
|
private static final String GCUBE_VARNAME = "GCUBE";
|
||||||
|
public static final String GCUBE;
|
||||||
|
|
||||||
|
private static final String PROD_VARNAME = "PROD";
|
||||||
|
public static final String PROD;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// load the properties file
|
||||||
|
properties.load(input);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
GCUBE = properties.getProperty(GCUBE_VARNAME);
|
||||||
|
|
||||||
|
PROD = properties.getProperty(PROD_VARNAME);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
|
||||||
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||||
|
String context = authorizationEntry.getContext();
|
||||||
|
logger.info("Context of token {} is {}", token, context);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void setContext(String token) throws ObjectNotFound, Exception{
|
||||||
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||||
|
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||||
|
logger.info("Owner of token is {}", clientInfo.getId());
|
||||||
|
|
||||||
|
String qualifier = authorizationEntry.getQualifier();
|
||||||
|
Caller caller = new Caller(clientInfo, qualifier);
|
||||||
|
AuthorizationProvider.instance.set(caller);
|
||||||
|
ScopeProvider.instance.set(getCurrentScope(token));
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() throws Exception{
|
||||||
|
setContext(GCUBE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() throws Exception{
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import java.util.UUID;
|
||||||
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
||||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.ScopedTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -48,11 +49,14 @@ public class ContextManagementTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createProductionContext() throws Exception {
|
public void createContexts() throws Exception {
|
||||||
ContextCreator contextCreator = new ContextCreator();
|
ContextCreator contextCreator = new ContextCreator();
|
||||||
contextCreator.all();
|
contextCreator.all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContext() throws Exception {
|
||||||
|
ScopedTest.setContext(ScopedTest.PROD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
|
|
||||||
<logger name="org.gcube" level="ERROR" />
|
<logger name="org.gcube" level="ERROR" />
|
||||||
<logger name="org.gcube.informationsystem.resourceregistry.context" level="INFO" />
|
<logger name="org.gcube.informationsystem.resourceregistry.context" level="TRACE" />
|
||||||
|
|
||||||
<root level="WARN">
|
<root level="WARN">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
<?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