Compare commits
1 Commits
master
...
Smartgears
Author | SHA1 | Date |
---|---|---|
Lucio Lelii | 1fcd10412c |
|
@ -27,7 +27,6 @@
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -31,7 +31,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-smartgears-bom</artifactId>
|
<artifactId>gcube-smartgears-bom</artifactId>
|
||||||
<version>2.1.0</version>
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -4,18 +4,21 @@ import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.AuthorizedTasks;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery.FIELD_TYPE;
|
import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery.FIELD_TYPE;
|
||||||
import org.gcube.datatransfer.resolver.util.ScopeUtil;
|
import org.gcube.datatransfer.resolver.util.ScopeUtil;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
@ -80,87 +83,84 @@ public class ApplicationProfileReader {
|
||||||
*/
|
*/
|
||||||
private ApplicationProfile readProfileFromInfrastrucure() {
|
private ApplicationProfile readProfileFromInfrastrucure() {
|
||||||
|
|
||||||
String originalScope = ScopeProvider.instance.get();
|
|
||||||
ApplicationProfile appProf = new ApplicationProfile();
|
|
||||||
String queryString = GcubeQuery.getGcubeGenericResource(secondaryType, FIELD_TYPE.APP_ID, appId);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
originalScope = ScopeProvider.instance.get();
|
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scope):scope;
|
||||||
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scope):scope;
|
|
||||||
ScopeProvider.instance.set(discoveryScope);
|
|
||||||
logger.info("Trying to fetch Generic Resource in the scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", AppId: " + appId);
|
|
||||||
Query q = new QueryBox(queryString);
|
|
||||||
DiscoveryClient<String> client = client();
|
|
||||||
List<String> appProfile = client.submit(q);
|
|
||||||
|
|
||||||
if (appProfile == null || appProfile.size() == 0)
|
Secret secret = ContextProvider.get().container().configuration().authorizationProvider().getSecretForContext(discoveryScope);
|
||||||
throw new ApplicationProfileNotFoundException("Generic Resource with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the scope: "+discoveryScope);
|
|
||||||
else {
|
return AuthorizedTasks.executeSafely(new Callable<ApplicationProfile>() {
|
||||||
String elem = appProfile.get(0);
|
|
||||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
|
||||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
|
||||||
XPathHelper helper = new XPathHelper(node);
|
|
||||||
|
|
||||||
//set scope
|
public ApplicationProfile call() throws Exception{
|
||||||
appProf.setScope(discoveryScope);
|
logger.info("Trying to fetch Generic Resource in the scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", AppId: " + appId);
|
||||||
|
ApplicationProfile appProf = new ApplicationProfile();
|
||||||
|
String queryString = GcubeQuery.getGcubeGenericResource(secondaryType, FIELD_TYPE.APP_ID, appId);
|
||||||
|
Query q = new QueryBox(queryString);
|
||||||
|
DiscoveryClient<String> client = client();
|
||||||
|
List<String> appProfile = client.submit(q);
|
||||||
|
|
||||||
List<String> currValue = null;
|
if (appProfile == null || appProfile.size() == 0)
|
||||||
currValue = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT);
|
throw new ApplicationProfileNotFoundException("Generic Resource with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the scope: "+discoveryScope);
|
||||||
if (currValue != null && currValue.size() > 0) {
|
else {
|
||||||
appProf.setName(currValue.get(0));
|
String elem = appProfile.get(0);
|
||||||
|
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||||
|
XPathHelper helper = new XPathHelper(node);
|
||||||
|
|
||||||
|
//set scope
|
||||||
|
appProf.setScope(discoveryScope);
|
||||||
|
|
||||||
|
List<String> currValue = null;
|
||||||
|
currValue = helper.evaluate(RESOURCE_PROFILE_NAME_TEXT);
|
||||||
|
if (currValue != null && currValue.size() > 0) {
|
||||||
|
appProf.setName(currValue.get(0));
|
||||||
|
}
|
||||||
|
else throw new ApplicationProfileNotFoundException("Your ApplicationProfile NAME was not found in the profile");
|
||||||
|
|
||||||
|
currValue = helper.evaluate(RESOURCE_PROFILE_DESCRIPTION_TEXT);
|
||||||
|
if (currValue != null && currValue.size() > 0) {
|
||||||
|
appProf.setDescription(currValue.get(0));
|
||||||
|
}
|
||||||
|
else logger.warn("No Description exists for " + appProf.getName());
|
||||||
|
|
||||||
|
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_APP_ID_TEXT);
|
||||||
|
if (currValue != null && currValue.size() > 0) {
|
||||||
|
appProf.setKey(currValue.get(0));
|
||||||
|
}
|
||||||
|
else throw new ApplicationProfileNotFoundException("Your ApplicationProfile ID was not found in the profile, consider adding <AppId> element in <Body>");
|
||||||
|
|
||||||
|
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT);
|
||||||
|
if (currValue != null && currValue.size() > 0) {
|
||||||
|
appProf.setImageUrl(currValue.get(0));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
logger.warn("Null or empty <ThumbnailURL> element in <Body>" + appProf.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
//currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
||||||
|
|
||||||
|
//RETRIEVE URL
|
||||||
|
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_END_POINT_URL_TEXT);
|
||||||
|
|
||||||
|
if (currValue != null && currValue.size() > 0) {
|
||||||
|
String url = currValue.get(0);
|
||||||
|
// System.out.println("URL "+url);
|
||||||
|
if(url!=null)
|
||||||
|
appProf.setUrl(url);
|
||||||
|
else
|
||||||
|
throw new ApplicationProfileNotFoundException("Your ApplicationProfile URL was not found in the profile for Scope: " + scope.toString() +", consider adding <EndPoint><URL> element in <Body>");
|
||||||
|
}
|
||||||
|
else throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" in the scope: "+discoveryScope +" does not contain "+RESOURCE_PROFILE_BODY_END_POINT_URL +" property, please add it");
|
||||||
}
|
}
|
||||||
else throw new ApplicationProfileNotFoundException("Your ApplicationProfile NAME was not found in the profile");
|
return appProf;
|
||||||
|
}
|
||||||
currValue = helper.evaluate(RESOURCE_PROFILE_DESCRIPTION_TEXT);
|
},secret);
|
||||||
if (currValue != null && currValue.size() > 0) {
|
|
||||||
appProf.setDescription(currValue.get(0));
|
} catch (Throwable e) {
|
||||||
}
|
|
||||||
else logger.warn("No Description exists for " + appProf.getName());
|
|
||||||
|
|
||||||
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_APP_ID_TEXT);
|
|
||||||
if (currValue != null && currValue.size() > 0) {
|
|
||||||
appProf.setKey(currValue.get(0));
|
|
||||||
}
|
|
||||||
else throw new ApplicationProfileNotFoundException("Your ApplicationProfile ID was not found in the profile, consider adding <AppId> element in <Body>");
|
|
||||||
|
|
||||||
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_THUMBNAIL_URL_TEXT);
|
|
||||||
if (currValue != null && currValue.size() > 0) {
|
|
||||||
appProf.setImageUrl(currValue.get(0));
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
logger.warn("Null or empty <ThumbnailURL> element in <Body>" + appProf.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
//currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
|
||||||
|
|
||||||
//RETRIEVE URL
|
|
||||||
currValue = helper.evaluate(RESOURCE_PROFILE_BODY_END_POINT_URL_TEXT);
|
|
||||||
|
|
||||||
if (currValue != null && currValue.size() > 0) {
|
|
||||||
String url = currValue.get(0);
|
|
||||||
// System.out.println("URL "+url);
|
|
||||||
if(url!=null)
|
|
||||||
appProf.setUrl(url);
|
|
||||||
else
|
|
||||||
throw new ApplicationProfileNotFoundException("Your ApplicationProfile URL was not found in the profile for Scope: " + scope.toString() +", consider adding <EndPoint><URL> element in <Body>");
|
|
||||||
}
|
|
||||||
else throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" in the scope: "+discoveryScope +" does not contain "+RESOURCE_PROFILE_BODY_END_POINT_URL +" property, please add it");
|
|
||||||
|
|
||||||
return appProf;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
|
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
|
||||||
return null;
|
return null;
|
||||||
}finally{
|
|
||||||
if(originalScope!=null && !originalScope.isEmpty()){
|
|
||||||
ScopeProvider.instance.set(originalScope);
|
|
||||||
logger.info("scope provider set to orginal scope: "+originalScope);
|
|
||||||
}else{
|
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
logger.info("scope provider reset");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -184,15 +184,15 @@ public class ApplicationProfileReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
//
|
//
|
||||||
// String portletClassName = "org.gcube.portlets.user.gisviewerapp.server.GisViewerAppServiceImpl";
|
// String portletClassName = "org.gcube.portlets.user.gisviewerapp.server.GisViewerAppServiceImpl";
|
||||||
// String scope ="/gcube/devNext/NextNext";
|
// String scope ="/gcube/devNext/NextNext";
|
||||||
// String secondaryType = "ApplicationProfile";
|
// String secondaryType = "ApplicationProfile";
|
||||||
// ApplicationProfileReader reader = new ApplicationProfileReader(scope, secondaryType, portletClassName, true);
|
// ApplicationProfileReader reader = new ApplicationProfileReader(scope, secondaryType, portletClassName, true);
|
||||||
//
|
//
|
||||||
// System.out.println(reader);
|
// System.out.println(reader);
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.common.security.ContextBean;
|
||||||
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
|
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
|
||||||
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
|
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -31,28 +32,28 @@ import com.google.common.cache.RemovalNotification;
|
||||||
public class LoadingMapOfScopeCache {
|
public class LoadingMapOfScopeCache {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(LoadingMapOfScopeCache.class);
|
private static Logger logger = LoggerFactory.getLogger(LoadingMapOfScopeCache.class);
|
||||||
private static LoadingCache<String, ScopeBean> scopeNamesToFullScopes;
|
private static LoadingCache<String, ContextBean> scopeNamesToFullScopes;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
|
|
||||||
CacheLoader<String, ScopeBean> loader = new CacheLoader<String, ScopeBean>(){
|
CacheLoader<String, ContextBean> loader = new CacheLoader<String, ContextBean>(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScopeBean load(String scopeName)
|
public ContextBean load(String scopeName)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
logger.info("Loading the cache for scope: {}",scopeName);
|
logger.info("Loading the cache for scope: {}",scopeName);
|
||||||
ScopeBean fullScope = loadFullScopeforScopeName(scopeName);
|
ContextBean fullScope = loadFullScopeforScopeName(scopeName);
|
||||||
logger.info("Returning {} for the Scope name: {}",ScopeBean.class.getSimpleName(), scopeName);
|
logger.info("Returning {} for the Scope name: {}",ScopeBean.class.getSimpleName(), scopeName);
|
||||||
return fullScope;
|
return fullScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RemovalListener<String, ScopeBean> removalListener = new RemovalListener<String, ScopeBean>() {
|
RemovalListener<String, ContextBean> removalListener = new RemovalListener<String, ContextBean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoval(RemovalNotification<String, ScopeBean> arg0) {
|
public void onRemoval(RemovalNotification<String, ContextBean> arg0) {
|
||||||
|
|
||||||
logger.debug("cache expired");
|
logger.debug("cache expired");
|
||||||
//prePopulateCache();
|
//prePopulateCache();
|
||||||
|
@ -82,7 +83,7 @@ public class LoadingMapOfScopeCache {
|
||||||
Map<String, String> map = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(UriResolverSmartGearManagerInit.getRootContextScope());
|
Map<String, String> map = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(UriResolverSmartGearManagerInit.getRootContextScope());
|
||||||
|
|
||||||
for (String scopeName : map.keySet()) {
|
for (String scopeName : map.keySet()) {
|
||||||
scopeNamesToFullScopes.asMap().put(scopeName, new ScopeBean(map.get(scopeName)));
|
scopeNamesToFullScopes.asMap().put(scopeName, new ContextBean(map.get(scopeName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Cache populated with: "+scopeNamesToFullScopes.asMap().toString());
|
logger.info("Cache populated with: "+scopeNamesToFullScopes.asMap().toString());
|
||||||
|
@ -102,7 +103,7 @@ public class LoadingMapOfScopeCache {
|
||||||
* @return the scope bean
|
* @return the scope bean
|
||||||
* @throws ExecutionException the execution exception
|
* @throws ExecutionException the execution exception
|
||||||
*/
|
*/
|
||||||
public static ScopeBean get(String scopeName) throws ExecutionException{
|
public static ContextBean get(String scopeName) throws ExecutionException{
|
||||||
|
|
||||||
return scopeNamesToFullScopes.get(scopeName);
|
return scopeNamesToFullScopes.get(scopeName);
|
||||||
}
|
}
|
||||||
|
@ -114,9 +115,9 @@ public class LoadingMapOfScopeCache {
|
||||||
* @param scopeName the scope name
|
* @param scopeName the scope name
|
||||||
* @return the scope bean
|
* @return the scope bean
|
||||||
*/
|
*/
|
||||||
protected static ScopeBean loadFullScopeforScopeName(String scopeName){
|
protected static ContextBean loadFullScopeforScopeName(String scopeName){
|
||||||
|
|
||||||
ScopeBean fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);
|
ContextBean fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);
|
||||||
|
|
||||||
//THIS CHECK SHOULD NOT BE NEEDED
|
//THIS CHECK SHOULD NOT BE NEEDED
|
||||||
if(fullScope==null){
|
if(fullScope==null){
|
||||||
|
@ -133,7 +134,7 @@ public class LoadingMapOfScopeCache {
|
||||||
*
|
*
|
||||||
* @return the cache
|
* @return the cache
|
||||||
*/
|
*/
|
||||||
public LoadingCache<String, ScopeBean> getCache(){
|
public LoadingCache<String, ContextBean> getCache(){
|
||||||
return scopeNamesToFullScopes;
|
return scopeNamesToFullScopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,11 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.glassfish.jersey.message.filtering.spi.ScopeProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ public class CatalogueServiceEndpointReader {
|
||||||
*/
|
*/
|
||||||
public static List<ServiceEndpoint> getConfigurationFromISFORCatalogueUrl() throws Exception{
|
public static List<ServiceEndpoint> getConfigurationFromISFORCatalogueUrl() throws Exception{
|
||||||
|
|
||||||
logger.info("Searching SE "+RUNTIME_CATALOGUE_RESOURCE_NAME+" configurations in the scope: "+ScopeProvider.instance.get());
|
logger.info("Searching SE "+RUNTIME_CATALOGUE_RESOURCE_NAME+" configurations in the scope: "+SecretManagerProvider.instance.get().getContext());
|
||||||
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_CATALOGUE_RESOURCE_NAME +"'");
|
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_CATALOGUE_RESOURCE_NAME +"'");
|
||||||
|
@ -90,7 +91,7 @@ public class CatalogueServiceEndpointReader {
|
||||||
* @return the catalogue url
|
* @return the catalogue url
|
||||||
*/
|
*/
|
||||||
public static String getCatalogueUrl() {
|
public static String getCatalogueUrl() {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = SecretManagerProvider.instance.get().getContext();
|
||||||
logger.debug("Getting Catalogue URL for scope: "+scope +" read from CacheCkanDataCatalogue");
|
logger.debug("Getting Catalogue URL for scope: "+scope +" read from CacheCkanDataCatalogue");
|
||||||
String catalogueURLForScope = cacheCkanDataCatalogue.get(scope);
|
String catalogueURLForScope = cacheCkanDataCatalogue.get(scope);
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ public class CatalogueServiceEndpointReader {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.debug("Instancing again the scope provider with scope value: "+scope);
|
logger.debug("Instancing again the scope provider with scope value: "+scope);
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
DataCatalogueImpl utilCKAN = new DataCatalogueImpl(scope);
|
DataCatalogueImpl utilCKAN = new DataCatalogueImpl(scope);
|
||||||
catalogueURLForScope = utilCKAN.getCatalogueUrl();
|
catalogueURLForScope = utilCKAN.getCatalogueUrl();
|
||||||
if(catalogueURLForScope==null)
|
if(catalogueURLForScope==null)
|
||||||
|
@ -124,7 +125,7 @@ public class CatalogueServiceEndpointReader {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static DataCatalogueImpl getDataCatalogueImpl() throws Exception {
|
public static DataCatalogueImpl getDataCatalogueImpl() throws Exception {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = SecretManagerProvider.instance.get().getContext();
|
||||||
return new DataCatalogueImpl(scope);
|
return new DataCatalogueImpl(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery;
|
import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery.FIELD_TYPE;
|
import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery.FIELD_TYPE;
|
||||||
|
@ -85,13 +85,13 @@ public class ApplicationProfileReaderForCatalogueResolver {
|
||||||
String queryString = GcubeQuery.getGcubeGenericResource(secondaryType, FIELD_TYPE.RESOURCE_NAME, resourceName);
|
String queryString = GcubeQuery.getGcubeGenericResource(secondaryType, FIELD_TYPE.RESOURCE_NAME, resourceName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Trying to fetch ApplicationProfile in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType + ", ResourceName: " + resourceName);
|
logger.info("Trying to fetch ApplicationProfile in the scope: "+SecretManagerProvider.instance.get().getContext()+", SecondaryType: " + secondaryType + ", ResourceName: " + resourceName);
|
||||||
Query q = new QueryBox(queryString);
|
Query q = new QueryBox(queryString);
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
List<String> appProfile = client.submit(q);
|
List<String> appProfile = client.submit(q);
|
||||||
|
|
||||||
if (appProfile == null || appProfile.size() == 0)
|
if (appProfile == null || appProfile.size() == 0)
|
||||||
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", ResourceName: " + resourceName +" is not registered in the scope: "+ScopeProvider.instance.get());
|
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", ResourceName: " + resourceName +" is not registered in the scope: "+SecretManagerProvider.instance.get().getContext());
|
||||||
else {
|
else {
|
||||||
try{
|
try{
|
||||||
String elem = appProfile.get(0);
|
String elem = appProfile.get(0);
|
||||||
|
|
|
@ -17,7 +17,7 @@ import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
||||||
|
@ -60,7 +60,7 @@ public class CkanCatalogueConfigurationsReader {
|
||||||
*/
|
*/
|
||||||
public static GatewayCKANCatalogueReference loadCatalogueEndPoints() throws Exception{
|
public static GatewayCKANCatalogueReference loadCatalogueEndPoints() throws Exception{
|
||||||
GatewayCKANCatalogueReference links = new GatewayCKANCatalogueReference();
|
GatewayCKANCatalogueReference links = new GatewayCKANCatalogueReference();
|
||||||
links.setScope(ScopeProvider.instance.get());
|
links.setScope(SecretManagerProvider.instance.get().getContext());
|
||||||
|
|
||||||
DataCatalogueImpl catalogueImpl = CatalogueServiceEndpointReader.getDataCatalogueImpl();
|
DataCatalogueImpl catalogueImpl = CatalogueServiceEndpointReader.getDataCatalogueImpl();
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class CkanCatalogueConfigurationsReader {
|
||||||
String ckanPortletURL = catalogueImpl.getCatalogueUrl();
|
String ckanPortletURL = catalogueImpl.getCatalogueUrl();
|
||||||
links.setCkanURL(ckanPortletURL);
|
links.setCkanURL(ckanPortletURL);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.warn("Erron on getting CKAN Porlet URL for scope: "+ScopeProvider.instance.get(), e);
|
logger.warn("Erron on getting CKAN Porlet URL for scope: {} ",SecretManagerProvider.instance.get().getContext(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return links;
|
return links;
|
||||||
|
@ -134,7 +134,7 @@ public class CkanCatalogueConfigurationsReader {
|
||||||
*/
|
*/
|
||||||
protected static String getPortletUrlForScopeFromIS() throws Exception {
|
protected static String getPortletUrlForScopeFromIS() throws Exception {
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = SecretManagerProvider.instance.get().getContext();
|
||||||
logger.debug("Trying to fetch applicationProfile profile from the infrastructure for " +
|
logger.debug("Trying to fetch applicationProfile profile from the infrastructure for " +
|
||||||
APPLICATION_PROFILE_NAME + " scope: " + scope);
|
APPLICATION_PROFILE_NAME + " scope: " + scope);
|
||||||
try {
|
try {
|
||||||
|
@ -178,7 +178,7 @@ public class CkanCatalogueConfigurationsReader {
|
||||||
*
|
*
|
||||||
* @param args the arguments
|
* @param args the arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
/*public static void main(String[] args) {
|
||||||
|
|
||||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
try {
|
try {
|
||||||
|
@ -189,5 +189,5 @@ public class CkanCatalogueConfigurationsReader {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,13 @@ import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||||
|
@ -45,12 +41,10 @@ public class GetAllInfrastructureScopes {
|
||||||
* @return the map of binding between (VRE_NAME, FULL_SCOPE_OF_VRE_NAME)
|
* @return the map of binding between (VRE_NAME, FULL_SCOPE_OF_VRE_NAME)
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> loadMapOfScopeNameToFullScope(String rootScope) throws Exception{
|
/*public static Map<String, String> loadMapOfScopeNameToFullScope(String rootScope) throws Exception{
|
||||||
|
|
||||||
String originalScope = ScopeProvider.instance.get();
|
|
||||||
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
ScopeBean scopeBean = null;
|
|
||||||
Map<String, String> scopeNameToFullScopeMap = new HashMap<String,String>();
|
Map<String, String> scopeNameToFullScopeMap = new HashMap<String,String>();
|
||||||
ScopeProvider.instance.set(rootScope);
|
ScopeProvider.instance.set(rootScope);
|
||||||
String secondaryType = Type.INFRASTRUCTURE.name();
|
String secondaryType = Type.INFRASTRUCTURE.name();
|
||||||
|
@ -91,7 +85,7 @@ public class GetAllInfrastructureScopes {
|
||||||
for (String vreName : vreNameFullScope.keySet()) {
|
for (String vreName : vreNameFullScope.keySet()) {
|
||||||
System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
|
System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
|
||||||
}*/
|
}*/
|
||||||
|
/*
|
||||||
logger.info("Total VRE is: "+scopeNameToFullScopeMap.size());
|
logger.info("Total VRE is: "+scopeNameToFullScopeMap.size());
|
||||||
return scopeNameToFullScopeMap;
|
return scopeNameToFullScopeMap;
|
||||||
|
|
||||||
|
@ -104,7 +98,7 @@ public class GetAllInfrastructureScopes {
|
||||||
}else
|
}else
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +115,7 @@ public class GetAllInfrastructureScopes {
|
||||||
List<String> listResourceName = new ArrayList<String>();
|
List<String> listResourceName = new ArrayList<String>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Trying to fetch GenericResource in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType);
|
logger.info("Trying to fetch GenericResource in the scope: {} , SecondaryType: {} ",SecretManagerProvider.instance.get().getContext(), secondaryType);
|
||||||
Query q = new QueryBox(queryString);
|
Query q = new QueryBox(queryString);
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
List<String> listGenericResources = client.submit(q);
|
List<String> listGenericResources = client.submit(q);
|
||||||
|
@ -129,7 +123,7 @@ public class GetAllInfrastructureScopes {
|
||||||
logger.info("# of GenericResource returned are: "+listGenericResources.size());
|
logger.info("# of GenericResource returned are: "+listGenericResources.size());
|
||||||
|
|
||||||
if (listGenericResources == null || listGenericResources.size() == 0)
|
if (listGenericResources == null || listGenericResources.size() == 0)
|
||||||
throw new Exception("GenericResource with SecondaryType: " + secondaryType + ", is not registered in the scope: "+ScopeProvider.instance.get());
|
throw new Exception("GenericResource with SecondaryType: " + secondaryType + ", is not registered in the scope: "+SecretManagerProvider.instance.get().getContext());
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,7 +140,7 @@ public class GetAllInfrastructureScopes {
|
||||||
listResourceName.add(resourceNames.get(0));
|
listResourceName.add(resourceNames.get(0));
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new Exception("Error during parsing the generic resource: "+genericResource + " in the scope: "+ScopeProvider.instance.get());
|
throw new Exception("Error during parsing the generic resource: "+genericResource + " in the scope: "+SecretManagerProvider.instance.get().getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +169,7 @@ public class GetAllInfrastructureScopes {
|
||||||
List<String> listOfVOScopes = new ArrayList<String>();
|
List<String> listOfVOScopes = new ArrayList<String>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Trying to fetch GenericResource in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType);
|
logger.info("Trying to fetch GenericResource in the scope: {}, SecondaryType: {} ",SecretManagerProvider.instance.get().getContext(), secondaryType);
|
||||||
Query q = new QueryBox(queryString);
|
Query q = new QueryBox(queryString);
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
List<String> listGenericResources = client.submit(q);
|
List<String> listGenericResources = client.submit(q);
|
||||||
|
@ -183,7 +177,7 @@ public class GetAllInfrastructureScopes {
|
||||||
logger.info("# of GenericResource returned searching for secondaryType= "+secondaryType+" is/are: "+listGenericResources.size());
|
logger.info("# of GenericResource returned searching for secondaryType= "+secondaryType+" is/are: "+listGenericResources.size());
|
||||||
|
|
||||||
if (listGenericResources == null || listGenericResources.size() == 0)
|
if (listGenericResources == null || listGenericResources.size() == 0)
|
||||||
throw new Exception("GenericResource with SecondaryType: " + secondaryType + ", is not registered in the scope: "+ScopeProvider.instance.get());
|
throw new Exception("GenericResource with SecondaryType: " + secondaryType + ", is not registered in the scope: "+SecretManagerProvider.instance.get().getContext());
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,7 +199,7 @@ public class GetAllInfrastructureScopes {
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new Exception("Error during parsing the generic resource: "+genericResource + " in the scope: "+ScopeProvider.instance.get());
|
throw new Exception("Error during parsing the generic resource: "+genericResource + " in the scope: "+SecretManagerProvider.instance.get().getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
import javax.xml.transform.Transformer;
|
import javax.xml.transform.Transformer;
|
||||||
|
@ -20,11 +21,18 @@ import org.gcube.common.resources.gcore.GenericResource;
|
||||||
import org.gcube.common.resources.gcore.Resource;
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
import org.gcube.common.resources.gcore.Resources;
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.AuthorizedTasks;
|
||||||
|
import org.gcube.common.security.Owner;
|
||||||
|
import org.gcube.common.security.secrets.CredentialSecret;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
||||||
import org.gcube.datatransfer.resolver.util.ScopeUtil;
|
import org.gcube.datatransfer.resolver.util.ScopeUtil;
|
||||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||||
|
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
import org.glassfish.jersey.message.filtering.spi.ScopeProvider;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
@ -51,7 +59,7 @@ public class UpdateApplicationProfileCatalogueResolver {
|
||||||
*/
|
*/
|
||||||
public static boolean validateEndPoint(String scopeToInstanceResolver, String VRE, String fullScope) throws ApplicationProfileNotFoundException {
|
public static boolean validateEndPoint(String scopeToInstanceResolver, String VRE, String fullScope) throws ApplicationProfileNotFoundException {
|
||||||
|
|
||||||
String originalScope = ScopeProvider.instance.get();
|
//String originalScope = ScopeProvider.instance.get();
|
||||||
logger.info("Checking if the VRE_NAME: "+VRE+" exists into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+" using scope: "+scopeToInstanceResolver);
|
logger.info("Checking if the VRE_NAME: "+VRE+" exists into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+" using scope: "+scopeToInstanceResolver);
|
||||||
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToInstanceResolver, true);
|
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToInstanceResolver, true);
|
||||||
Element root = appPrCatResolver.getRootDocument();
|
Element root = appPrCatResolver.getRootDocument();
|
||||||
|
@ -86,25 +94,25 @@ public class UpdateApplicationProfileCatalogueResolver {
|
||||||
logger.debug("Updated resource: \n"+result.getWriter().toString());
|
logger.debug("Updated resource: \n"+result.getWriter().toString());
|
||||||
|
|
||||||
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scopeToInstanceResolver):scopeToInstanceResolver;
|
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scopeToInstanceResolver):scopeToInstanceResolver;
|
||||||
ScopeProvider.instance.set(discoveryScope);
|
|
||||||
|
|
||||||
ScopedPublisher rp=RegistryPublisherFactory.scopedPublisher();
|
ApplicationContext ctx = ContextProvider.get();
|
||||||
Resource resource = toResource(result);
|
Secret secret = ctx.container().configuration().authorizationProvider().getSecretForContext(discoveryScope);
|
||||||
rp.update(resource);
|
|
||||||
|
AuthorizedTasks.executeSafely(() -> {
|
||||||
|
ScopedPublisher rp=RegistryPublisherFactory.scopedPublisher();
|
||||||
|
Resource resource = toResource(result);
|
||||||
|
try {
|
||||||
|
rp.update(resource);
|
||||||
|
}catch(RegistryNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}, secret);
|
||||||
logger.info("Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+" updated on IS successfully using scope: "+discoveryScope);
|
logger.info("Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+" updated on IS successfully using scope: "+discoveryScope);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logger.error("Error ", e);
|
logger.error("Error ", e);
|
||||||
throw new ApplicationProfileNotFoundException("Error during parsing application profile with resource name: " +ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME + " in the scope: " + scopeToInstanceResolver);
|
throw new ApplicationProfileNotFoundException("Error during parsing application profile with resource name: " +ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME + " in the scope: " + scopeToInstanceResolver);
|
||||||
}finally{
|
|
||||||
if(originalScope!=null){
|
|
||||||
ScopeProvider.instance.set(originalScope);
|
|
||||||
logger.info("scope provider set to orginal scope: "+originalScope);
|
|
||||||
}else{
|
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
logger.info("scope provider reset");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,20 +139,20 @@ public class UpdateApplicationProfileCatalogueResolver {
|
||||||
* @return the document
|
* @return the document
|
||||||
*/
|
*/
|
||||||
private static Document addNewEndPoint(Document document, String VRE, String fullScope){
|
private static Document addNewEndPoint(Document document, String VRE, String fullScope){
|
||||||
Element newEndPoint = document.createElement(ApplicationProfileReaderForCatalogueResolver.END_POINT);
|
Element newEndPoint = document.createElement(ApplicationProfileReaderForCatalogueResolver.END_POINT);
|
||||||
Element newScope = document.createElement(ApplicationProfileReaderForCatalogueResolver.SCOPE);
|
Element newScope = document.createElement(ApplicationProfileReaderForCatalogueResolver.SCOPE);
|
||||||
newScope.setTextContent(fullScope);
|
newScope.setTextContent(fullScope);
|
||||||
Element newVREName = document.createElement(ApplicationProfileReaderForCatalogueResolver.VRE_NAME);
|
Element newVREName = document.createElement(ApplicationProfileReaderForCatalogueResolver.VRE_NAME);
|
||||||
newVREName.setTextContent(VRE);
|
newVREName.setTextContent(VRE);
|
||||||
|
|
||||||
newEndPoint.appendChild(newScope);
|
newEndPoint.appendChild(newScope);
|
||||||
newEndPoint.appendChild(newVREName);
|
newEndPoint.appendChild(newVREName);
|
||||||
|
|
||||||
logger.info("Adding the "+ApplicationProfileReaderForCatalogueResolver.END_POINT+":");
|
logger.info("Adding the "+ApplicationProfileReaderForCatalogueResolver.END_POINT+":");
|
||||||
logger.info(ApplicationProfileReaderForCatalogueResolver.VRE_NAME +": "+VRE +" - "+ApplicationProfileReaderForCatalogueResolver.SCOPE +" "+fullScope);
|
logger.info(ApplicationProfileReaderForCatalogueResolver.VRE_NAME +": "+VRE +" - "+ApplicationProfileReaderForCatalogueResolver.SCOPE +" "+fullScope);
|
||||||
|
|
||||||
document.getElementsByTagName(ApplicationProfileReaderForCatalogueResolver.BODY).item(0).appendChild(newEndPoint);
|
document.getElementsByTagName(ApplicationProfileReaderForCatalogueResolver.BODY).item(0).appendChild(newEndPoint);
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,19 @@ import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.StringEncrypter;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
import org.gcube.common.resources.gcore.utils.Group;
|
import org.gcube.common.resources.gcore.utils.Group;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.AuthorizedTasks;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
|
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -53,68 +56,64 @@ public class GeoRuntimeReader {
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
private ServerParameters getParameters(String scope, GEO_SERVICE geoservice) throws Exception{
|
private ServerParameters getParameters(String scope, GEO_SERVICE geoservice) throws Exception{
|
||||||
String originalScope = ScopeProvider.instance.get();
|
|
||||||
ServerParameters parameters = new ServerParameters();
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
boolean isGeoserver = geoservice.equals(GEO_SERVICE.GEOSERVER);
|
boolean isGeoserver = geoservice.equals(GEO_SERVICE.GEOSERVER);
|
||||||
String resourceName = isGeoserver ? GEOSERVER_RESOURCE_NAME : GEONETWORK_RESOURCE_NAME;
|
String resourceName = isGeoserver ? GEOSERVER_RESOURCE_NAME : GEONETWORK_RESOURCE_NAME;
|
||||||
ScopeProvider.instance.set(scope);
|
Secret secret = ContextProvider.get().container().configuration().authorizationProvider().getSecretForContext(scope);
|
||||||
|
|
||||||
|
return AuthorizedTasks.executeSafely(new Callable<ServerParameters>() {
|
||||||
|
public ServerParameters call() throws Exception{
|
||||||
|
ServerParameters parameters = new ServerParameters();
|
||||||
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
|
||||||
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
logger.info("GeoRuntimeReader, using scope: "+scope + ", to get resource: "+resourceName);
|
||||||
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
|
|
||||||
|
|
||||||
logger.info("GeoRuntimeReader, using scope: "+scope + ", to get resource: "+resourceName);
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
List<ServiceEndpoint> r = client.submit(query);
|
||||||
|
if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource: "+resourceName);
|
||||||
|
|
||||||
List<ServiceEndpoint> r = client.submit(query);
|
ServiceEndpoint se = r.get(0);
|
||||||
if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource: "+resourceName);
|
if(se.profile()==null)
|
||||||
|
throw new Exception("IS profile is null for resource: "+resourceName);
|
||||||
|
|
||||||
ServiceEndpoint se = r.get(0);
|
Group<AccessPoint> accessPoints = se.profile().accessPoints();
|
||||||
if(se.profile()==null)
|
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
|
||||||
throw new Exception("IS profile is null for resource: "+resourceName);
|
|
||||||
|
|
||||||
Group<AccessPoint> accessPoints = se.profile().accessPoints();
|
AccessPoint ap = accessPoints.iterator().next();
|
||||||
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
|
parameters.setUrl(ap.address());
|
||||||
|
parameters.setUser(ap.username()); //username
|
||||||
|
|
||||||
AccessPoint ap = accessPoints.iterator().next();
|
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||||
parameters.setUrl(ap.address());
|
parameters.setPassword(decryptedPassword); //password
|
||||||
parameters.setUser(ap.username()); //username
|
|
||||||
|
|
||||||
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
if (isGeoserver){
|
||||||
parameters.setPassword(decryptedPassword); //password
|
Group<Property> properties = ap.properties();
|
||||||
|
if(properties.size()==0) throw new Exception("Properties in resource "+resourceName+" not found");
|
||||||
|
Iterator<Property> iter = properties.iterator();
|
||||||
|
|
||||||
if (isGeoserver){
|
while (iter.hasNext()) {
|
||||||
Group<Property> properties = ap.properties();
|
|
||||||
if(properties.size()==0) throw new Exception("Properties in resource "+resourceName+" not found");
|
|
||||||
Iterator<Property> iter = properties.iterator();
|
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
Property prop = iter.next();
|
||||||
|
|
||||||
Property prop = iter.next();
|
if(prop.name().compareTo(WORKSPACES_PROPERTY_NAME)==0){
|
||||||
|
// logger.trace("Property "+WORKSPACES_PROPERTY_NAME+" found, setting value: "+prop.value());
|
||||||
if(prop.name().compareTo(WORKSPACES_PROPERTY_NAME)==0){
|
// parameters.setWorkspaces(prop.value());
|
||||||
// logger.trace("Property "+WORKSPACES_PROPERTY_NAME+" found, setting value: "+prop.value());
|
// break;
|
||||||
// parameters.setWorkspaces(prop.value());
|
}
|
||||||
// break;
|
}
|
||||||
}
|
}
|
||||||
|
return parameters;
|
||||||
}
|
}
|
||||||
}
|
}, secret);
|
||||||
|
}catch (Throwable e) {
|
||||||
}catch (Exception e) {
|
|
||||||
logger.error("Sorry, an error occurred on reading parameters in Runtime Resources",e);
|
logger.error("Sorry, an error occurred on reading parameters in Runtime Resources",e);
|
||||||
}finally{
|
return new ServerParameters();
|
||||||
if(originalScope!=null){
|
|
||||||
ScopeProvider.instance.set(originalScope);
|
|
||||||
logger.info("scope provider set to orginal scope: "+originalScope);
|
|
||||||
}else{
|
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
logger.info("scope provider reset");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parameters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package org.gcube.datatransfer.resolver.gis;
|
package org.gcube.datatransfer.resolver.gis;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import org.gcube.common.security.AuthorizedTasks;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
|
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||||
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
||||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||||
|
@ -48,31 +52,25 @@ public class GeonetworkInstance {
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
String originalScope = ScopeProvider.instance.get();
|
Secret secret = ContextProvider.get().container().configuration().authorizationProvider().getSecretForContext(this.scope);
|
||||||
logger.debug("Instancing GeonetworkInstance with scope: "+scope + ", authenticate: "+authenticate +", login level: "+level);
|
logger.debug("Instancing GeonetworkInstance with scope: "+scope + ", authenticate: "+authenticate +", login level: "+level);
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set(scope);
|
AuthorizedTasks.executeSafely( new Callable<Void>() {
|
||||||
logger.info("setting scope "+scope);
|
public Void call() throws Exception {
|
||||||
createInstanceGeonetworkPublisher(authenticate, level);
|
createInstanceGeonetworkPublisher(authenticate, level);
|
||||||
this.config = geonetworkPublisher.getConfiguration();
|
config = geonetworkPublisher.getConfiguration();
|
||||||
this.version = this.config.getGeoNetworkVersion();
|
version = config.getGeoNetworkVersion();
|
||||||
this.endPoint = this.config.getGeoNetworkEndpoint();
|
endPoint = config.getGeoNetworkEndpoint();
|
||||||
if(this.type!=null){
|
if(type!=null)
|
||||||
this.account=config.getScopeConfiguration().getAccounts().get(this.type);
|
account=config.getScopeConfiguration().getAccounts().get(type);
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
}, secret );
|
||||||
//logger.info("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
|
//logger.info("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
String message = "Sorry, an error occurred in instancing geonetwork";
|
String message = "Sorry, an error occurred in instancing geonetwork";
|
||||||
logger.warn(message, e);
|
logger.warn(message, e);
|
||||||
throw new GeonetworkInstanceException(message);
|
throw new GeonetworkInstanceException(message);
|
||||||
}finally{
|
|
||||||
if(originalScope!=null){
|
|
||||||
ScopeProvider.instance.set(originalScope);
|
|
||||||
logger.info("scope provider set to orginal scope: "+originalScope);
|
|
||||||
}else{
|
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
logger.info("scope provider reset");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,8 +127,8 @@ public class GeonetworkInstance {
|
||||||
public GeoNetworkPublisher getGeonetworkPublisher() {
|
public GeoNetworkPublisher getGeonetworkPublisher() {
|
||||||
return geonetworkPublisher;
|
return geonetworkPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the version.
|
* Gets the version.
|
||||||
*
|
*
|
||||||
|
@ -139,8 +137,8 @@ public class GeonetworkInstance {
|
||||||
public Version getVersion() {
|
public Version getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the level.
|
* Gets the level.
|
||||||
*
|
*
|
||||||
|
@ -158,8 +156,8 @@ public class GeonetworkInstance {
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the end point.
|
* Gets the end point.
|
||||||
*
|
*
|
||||||
|
@ -168,7 +166,7 @@ public class GeonetworkInstance {
|
||||||
public String getEndPoint() {
|
public String getEndPoint() {
|
||||||
return endPoint;
|
return endPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the config.
|
* Gets the config.
|
||||||
*
|
*
|
||||||
|
@ -209,7 +207,7 @@ public class GeonetworkInstance {
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,10 @@ import javax.ws.rs.core.MultivaluedMap;
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
import javax.ws.rs.ext.Provider;
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
||||||
import org.gcube.datatransfer.resolver.UriResolverServices;
|
import org.gcube.datatransfer.resolver.UriResolverServices;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -62,11 +62,9 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
|
||||||
public void filter(ContainerRequestContext reqContext) throws IOException {
|
public void filter(ContainerRequestContext reqContext) throws IOException {
|
||||||
log.info(RequestHandler.class.getSimpleName() +" Request called");
|
log.info(RequestHandler.class.getSimpleName() +" Request called");
|
||||||
|
|
||||||
if(SecurityTokenProvider.instance.get()==null)
|
if(SecretManagerProvider.instance.get()==null)
|
||||||
SecurityTokenProvider.instance.set(context.getInitParameter(ROOT_APP_TOKEN));
|
SecretManagerProvider.instance.set(ContextProvider.get().container().configuration().authorizationProvider().getSecretForContext(context.getInitParameter(ROOT_APP_TOKEN)));
|
||||||
|
|
||||||
if(ScopeProvider.instance.get()==null)
|
|
||||||
ScopeProvider.instance.set(context.getInitParameter(ROOT_SCOPE));
|
|
||||||
|
|
||||||
log.info("Token and Scope Provider set called");
|
log.info("Token and Scope Provider set called");
|
||||||
|
|
||||||
|
@ -172,8 +170,7 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
|
||||||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
|
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
log.info(RequestHandler.class.getSimpleName() +" Response called");
|
log.info(RequestHandler.class.getSimpleName() +" Response called");
|
||||||
SecurityTokenProvider.instance.reset();
|
SecretManagerProvider.instance.reset();
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
log.info("Token and Scope Provider reset called");
|
log.info("Token and Scope Provider reset called");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.datatransfer.resolver.services;
|
package org.gcube.datatransfer.resolver.services;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
|
@ -16,6 +15,7 @@ import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
@ -29,16 +29,17 @@ import javax.ws.rs.core.Response;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
||||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.StringEncrypter;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.AuthorizedTasks;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.security.ContextBean;
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
import org.gcube.common.security.ContextBean.Type;
|
||||||
|
import org.gcube.common.security.Owner;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.GCubeSecret;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
import org.gcube.common.storagehub.model.Metadata;
|
||||||
import org.gcube.data.analysis.dminvocation.ActionType;
|
import org.gcube.data.analysis.dminvocation.ActionType;
|
||||||
import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager;
|
import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager;
|
||||||
|
@ -49,7 +50,7 @@ import org.gcube.datatransfer.resolver.util.ScopeUtil;
|
||||||
import org.gcube.datatransfer.resolver.util.Util;
|
import org.gcube.datatransfer.resolver.util.Util;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.gcube.storagehub.ApplicationMode;
|
import org.gcube.smartgears.ContextProvider;
|
||||||
import org.gcube.storagehub.StorageHubManagement;
|
import org.gcube.storagehub.StorageHubManagement;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -104,7 +105,7 @@ public class AnalyticsCreateResolver {
|
||||||
try {
|
try {
|
||||||
logger.info("body is: " + body);
|
logger.info("body is: " + body);
|
||||||
|
|
||||||
DataMinerInvocation jsonRequest = null;
|
final DataMinerInvocation jsonRequest;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body),
|
jsonRequest = DataMinerInvocationManager.getInstance().unmarshalingJSON(IOUtils.toInputStream(body),
|
||||||
|
@ -119,7 +120,7 @@ public class AnalyticsCreateResolver {
|
||||||
logger.debug("The body contains the request: " + jsonRequest.toString());
|
logger.debug("The body contains the request: " + jsonRequest.toString());
|
||||||
|
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = SecretManagerProvider.instance.get().getContext();
|
||||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||||
logger.info("ScopeProvider has scope: " + scope);
|
logger.info("ScopeProvider has scope: " + scope);
|
||||||
|
|
||||||
|
@ -138,8 +139,8 @@ public class AnalyticsCreateResolver {
|
||||||
"Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(),
|
"Mandatory body parameter 'operatorId' not found or empty in the JSON object", this.getClass(),
|
||||||
helpURI);
|
helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(scope);
|
ContextBean scopeBean = new ContextBean(scope);
|
||||||
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
|
if (scopeBean.is(Type.INFRASTRUCTURE) || scopeBean.is(Type.VO)) {
|
||||||
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE");
|
logger.error(Type.INFRASTRUCTURE + "or " + Type.VO + " scope detected, you must set a scope of VRE");
|
||||||
throw ExceptionManager.unauthorizedException(req,
|
throw ExceptionManager.unauthorizedException(req,
|
||||||
|
@ -157,81 +158,83 @@ public class AnalyticsCreateResolver {
|
||||||
if (jsonRequest.getActionType() == null)
|
if (jsonRequest.getActionType() == null)
|
||||||
jsonRequest.setActionType(ActionType.RUN);
|
jsonRequest.setActionType(ActionType.RUN);
|
||||||
|
|
||||||
File tempInvocationFile = null;
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String contextToken = SecurityTokenProvider.instance.get();
|
|
||||||
String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true);
|
String xmlRequest = DataMinerInvocationManager.getInstance().marshalingXML(jsonRequest, true, true);
|
||||||
String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId());
|
String uniqueName = createDMInvocationFileName(jsonRequest.getOperatorId());
|
||||||
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlRequest.getBytes());
|
|
||||||
logger.info("Created StorageHubClient Instance, uploading file: " + tempInvocationFile.getName());
|
|
||||||
|
|
||||||
AuthorizationEntry entry = authorizationService().get(contextToken);
|
|
||||||
// retrieve the info of the token owner
|
// retrieve the info of the token owner
|
||||||
ClientInfo clientInfo = entry.getClientInfo();
|
Owner clientInfo = SecretManagerProvider.instance.get().getOwner();
|
||||||
String owner = clientInfo.getId(); // IS THIS THE USERNAME?
|
String owner = clientInfo.getId(); // IS THIS THE USERNAME?
|
||||||
|
|
||||||
String infra = ScopeUtil.getInfrastructureNameFromScope(ScopeProvider.instance.get());
|
String infra = ScopeUtil.getInfrastructureNameFromScope(scope);
|
||||||
String theAppToken = readApplicationTokenFromSE(req, infra);
|
String theAppToken = readApplicationTokenFromSE(req, infra);
|
||||||
|
|
||||||
logger.info("By using infra scope: " + infra + " and the Application Token: "
|
logger.info("By using infra scope: " + infra + " and the Application Token: "
|
||||||
+ theAppToken.substring(0, theAppToken.length() / 2) + "... of "
|
+ theAppToken.substring(0, theAppToken.length() / 2) + "... of "
|
||||||
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " to instance the "
|
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " to instance the "
|
||||||
+ StorageHubManagement.class.getSimpleName());
|
+ StorageHubManagement.class.getSimpleName());
|
||||||
ScopeProvider.instance.set(infra);
|
|
||||||
ApplicationMode applicationMode = new ApplicationMode(theAppToken);
|
|
||||||
applicationMode.start();
|
|
||||||
|
|
||||||
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
publicLinkToDMInvFile = AuthorizedTasks.executeSafely(new Callable<String>() {
|
||||||
Metadata metadata = new Metadata();
|
public String call() throws Exception{
|
||||||
Map<String, Object> theMap = new HashMap<String, Object>();
|
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
||||||
theMap.put("owner", owner);
|
Metadata metadata = new Metadata();
|
||||||
metadata.setMap(theMap);
|
Map<String, Object> theMap = new HashMap<String, Object>();
|
||||||
URL thePublicLink = null;
|
theMap.put("owner", owner);
|
||||||
try {
|
metadata.setMap(theMap);
|
||||||
|
URL thePublicLink = null;
|
||||||
logger.info("Saving dataminer-invocation file for the user: " + owner);
|
File tempInvocationFile = createTempFile(uniqueName, ".xml", xmlRequest.getBytes());
|
||||||
thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile),
|
try {
|
||||||
tempInvocationFile.getName(), "application/xml", metadata);
|
|
||||||
logger.info("Saved dataminer-invocation file at: " + thePublicLink);
|
logger.info("Created StorageHubClient Instance, uploading file: " + tempInvocationFile.getName());
|
||||||
} catch (Exception e) {
|
logger.info("Saving dataminer-invocation file for the user: " + owner);
|
||||||
logger.error("Error when storing your 'dataminer-invocation':", e);
|
thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "application/xml", metadata);
|
||||||
throw ExceptionManager
|
logger.info("Saved dataminer-invocation file at: " + thePublicLink);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error when storing your 'dataminer-invocation':", e);
|
||||||
|
throw ExceptionManager
|
||||||
.internalErrorException(
|
.internalErrorException(
|
||||||
req, "Error when storing your 'dataminer-invocation' request with "
|
req, "Error when storing your 'dataminer-invocation' request with "
|
||||||
+ jsonRequest + ". \nPlease contact the support",
|
+ jsonRequest + ". \nPlease contact the support",
|
||||||
this.getClass(), helpURI);
|
this.getClass(), helpURI);
|
||||||
}
|
} finally {
|
||||||
|
try {
|
||||||
|
// DELETING THE TEMP FILE
|
||||||
|
if (tempInvocationFile != null && tempInvocationFile.exists())
|
||||||
|
tempInvocationFile.delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
publicLinkToDMInvFile = thePublicLink != null ? thePublicLink.toString() : null;
|
return thePublicLink != null ? thePublicLink.toString() : null;
|
||||||
} catch (Exception e) {
|
|
||||||
|
}
|
||||||
|
}, new GCubeSecret(theAppToken));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
|
||||||
if (e instanceof InternalServerException) {
|
if (e instanceof InternalServerException) {
|
||||||
// error during storing the file via StorageHubManagent
|
// error during storing the file via StorageHubManagent
|
||||||
throw e;
|
throw new WebApplicationException(e);
|
||||||
}
|
}
|
||||||
logger.error("Error on creating 'dataminer-invocation:", e);
|
logger.error("Error on creating 'dataminer-invocation:", e);
|
||||||
throw ExceptionManager.badRequestException(req,
|
throw ExceptionManager.badRequestException(req,
|
||||||
"Error on creating your 'dataminer-invocation' request with " + jsonRequest
|
"Error on creating your 'dataminer-invocation' request with " + jsonRequest
|
||||||
+ ". \nPlease contact the support",
|
+ ". \nPlease contact the support",
|
||||||
this.getClass(), helpURI);
|
this.getClass(), helpURI);
|
||||||
} finally {
|
}
|
||||||
// No needed to reset the scope, it is provided by TokenSetter
|
|
||||||
try {
|
|
||||||
// DELETING THE TEMP FILE
|
|
||||||
if (tempInvocationFile != null && tempInvocationFile.exists())
|
|
||||||
tempInvocationFile.delete();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// silent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (publicLinkToDMInvFile == null) {
|
if (publicLinkToDMInvFile == null) {
|
||||||
logger.error("Error on creating the public link to file");
|
logger.error("Error on creating the public link to file");
|
||||||
throw ExceptionManager.badRequestException(req,
|
throw ExceptionManager.badRequestException(req,
|
||||||
"Error on getting link to your 'dataminer-invocation' request. Plese contact the support "
|
"Error on getting link to your 'dataminer-invocation' request. Plese contact the support "
|
||||||
+ jsonRequest,
|
+ jsonRequest,
|
||||||
this.getClass(), helpURI);
|
this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
String dataMinerURL = String.format("%s/%s?%s=%s", analyticsGetResolverURL, vreName,
|
String dataMinerURL = String.format("%s/%s?%s=%s", analyticsGetResolverURL, vreName,
|
||||||
|
@ -272,77 +275,73 @@ public class AnalyticsCreateResolver {
|
||||||
*/
|
*/
|
||||||
private static String readApplicationTokenFromSE(HttpServletRequest req, String scope) {
|
private static String readApplicationTokenFromSE(HttpServletRequest req, String scope) {
|
||||||
|
|
||||||
String callerScope = null;
|
|
||||||
String gCubeAppToken = null;
|
|
||||||
try {
|
try {
|
||||||
callerScope = ScopeProvider.instance.get();
|
Secret secret = ContextProvider.get().container().configuration().authorizationProvider().getSecretForContext(scope);
|
||||||
ScopeProvider.instance.set(scope);
|
return AuthorizedTasks.executeSafely(new Callable<String>() {
|
||||||
logger.info("Searching SE " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " configurations in the scope: "
|
public String call() throws Exception{
|
||||||
+ ScopeProvider.instance.get());
|
|
||||||
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
String gCubeAppToken = null;
|
||||||
query.addCondition("$resource/Profile/Name/text() eq '" + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + "'");
|
|
||||||
query.addCondition("$resource/Profile/Category/text() eq 'Service'");
|
|
||||||
|
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
logger.info("Searching SE " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " configurations in the scope: "
|
||||||
List<ServiceEndpoint> toReturn = client.submit(query);
|
+ scope);
|
||||||
|
|
||||||
logger.info("The query returned " + toReturn.size() + " ServiceEndpoint/s");
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
query.addCondition("$resource/Profile/Name/text() eq '" + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + "'");
|
||||||
|
query.addCondition("$resource/Profile/Category/text() eq 'Service'");
|
||||||
|
|
||||||
if (toReturn.size() == 0) {
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
String errorMessage = "No " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " registered in the scope: "
|
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||||
+ ScopeProvider.instance.get();
|
|
||||||
logger.error(errorMessage);
|
|
||||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class,
|
|
||||||
helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceEndpoint se = toReturn.get(0);
|
logger.info("The query returned " + toReturn.size() + " ServiceEndpoint/s");
|
||||||
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
|
||||||
for (AccessPoint accessPoint : theAccessPoints) {
|
if (toReturn.size() == 0) {
|
||||||
Collection<Property> properties = accessPoint.properties().asCollection();
|
String errorMessage = "No " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " registered in the scope: "
|
||||||
for (Property property : properties) {
|
+ scope;
|
||||||
if (property.name().equalsIgnoreCase(GCUBE_TOKEN)) {
|
logger.error(errorMessage);
|
||||||
logger.info("gcube-token as property was found, returning it");
|
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class,
|
||||||
gCubeAppToken = property.value();
|
helpURI);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServiceEndpoint se = toReturn.get(0);
|
||||||
|
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
||||||
|
for (AccessPoint accessPoint : theAccessPoints) {
|
||||||
|
Collection<Property> properties = accessPoint.properties().asCollection();
|
||||||
|
for (Property property : properties) {
|
||||||
|
if (property.name().equalsIgnoreCase(GCUBE_TOKEN)) {
|
||||||
|
logger.info("gcube-token as property was found, returning it");
|
||||||
|
gCubeAppToken = property.value();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gCubeAppToken != null)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gCubeAppToken != null) {
|
||||||
|
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(gCubeAppToken);
|
||||||
|
logger.info("Returning decrypted Application Token registered into "
|
||||||
|
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE: "
|
||||||
|
+ decryptedPassword.substring(0, decryptedPassword.length() / 2) + "....");
|
||||||
|
return decryptedPassword;
|
||||||
|
} else {
|
||||||
|
String errorMessage = "No " + GCUBE_TOKEN + " as Property saved in the "
|
||||||
|
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE registered in the scope: "
|
||||||
|
+ scope;
|
||||||
|
logger.error(errorMessage);
|
||||||
|
throw new Exception(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}, secret);
|
||||||
if (gCubeAppToken != null)
|
|
||||||
break;
|
} catch (Throwable e) {
|
||||||
}
|
|
||||||
|
|
||||||
if (gCubeAppToken != null) {
|
|
||||||
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(gCubeAppToken);
|
|
||||||
logger.info("Returning decrypted Application Token registered into "
|
|
||||||
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE: "
|
|
||||||
+ decryptedPassword.substring(0, decryptedPassword.length() / 2) + "....");
|
|
||||||
return decryptedPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
String errorMessage = "No " + GCUBE_TOKEN + " as Property saved in the "
|
|
||||||
+ ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME + " SE registered in the scope: "
|
|
||||||
+ ScopeProvider.instance.get();
|
|
||||||
logger.error(errorMessage);
|
|
||||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
String errorMessage = "Error occurred on reading the " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME
|
String errorMessage = "Error occurred on reading the " + ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME
|
||||||
+ " SE registered in the scope: " + ScopeProvider.instance.get();
|
+ " SE registered in the scope: " + scope;
|
||||||
logger.error(errorMessage, e);
|
logger.error(errorMessage, e);
|
||||||
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
throw ExceptionManager.internalErrorException(req, errorMessage, AnalyticsCreateResolver.class, helpURI);
|
||||||
|
|
||||||
} finally {
|
}
|
||||||
if (callerScope != null) {
|
|
||||||
logger.info("Setting to the callerScope scope: " + callerScope);
|
|
||||||
ScopeProvider.instance.set(callerScope);
|
|
||||||
} else {
|
|
||||||
logger.info("Reset scope");
|
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,7 @@ import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.common.security.ContextBean;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
||||||
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
||||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
|
@ -70,7 +71,7 @@ public class AnalyticsGetResolver {
|
||||||
this.getClass(), helpURI);
|
this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeBean fullScopeBean = null;
|
ContextBean fullScopeBean = null;
|
||||||
|
|
||||||
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -13,9 +13,9 @@ import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -49,14 +49,15 @@ public class OatResolver {
|
||||||
LOG.info(this.getClass().getSimpleName() + " GET starts...");
|
LOG.info(this.getClass().getSimpleName() + " GET starts...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
Secret currentSecret = SecretManagerProvider.instance.get();
|
||||||
LOG.info("ScopeProvider has scope: " + scope);
|
|
||||||
String username = AuthorizationProvider.instance.get().getClient().getId();
|
LOG.info("ScopeProvider has scope: {} ", currentSecret.getContext());
|
||||||
UserInfo userInfo = new UserInfo(username, new ArrayList<>());
|
|
||||||
String userToken = authorizationService().generateUserToken(userInfo, scope);
|
UserInfo userInfo = new UserInfo(currentSecret.getOwner().getId(), new ArrayList<>());
|
||||||
|
String userToken = authorizationService().generateUserToken(userInfo, currentSecret.getContext());
|
||||||
String msgToken = userToken.substring(0, 10) + "_MASKED_TOKEN";
|
String msgToken = userToken.substring(0, 10) + "_MASKED_TOKEN";
|
||||||
LOG.info("returning legacy token {} for user {}", msgToken, username);
|
LOG.info("returning legacy token {} for user {}", msgToken, currentSecret.getOwner().getId());
|
||||||
return Response.ok(userToken).build();
|
return Response.ok(userToken).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Exception:", e);
|
LOG.error("Exception:", e);
|
||||||
|
|
Loading…
Reference in New Issue