This commit is contained in:
Lucio Lelii 2018-10-18 16:24:49 +00:00
parent 582673819a
commit f0ac1a5670
10 changed files with 112 additions and 170 deletions

View File

@ -30,7 +30,6 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

32
pom.xml
View File

@ -109,6 +109,31 @@
<version>2.13</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
</dependency>
<!-- weld -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.2.10.Final</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>1.2.2.Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@ -124,13 +149,6 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- GIS RESOLVER DEPENDENCIES -->
<dependency>

View File

@ -3,5 +3,4 @@ package org.gcube.datatransfer.resolver;
public class Constants {
public static final String SERVLET_GEONETWORK = "geonetwork";
public static final String SERVLET_CATALOGUE = "catalogue";
}

View File

@ -1,23 +1,16 @@
package org.gcube.datatransfer.resolver;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import org.gcube.datatransfer.resolver.services.Catalogue;
import org.gcube.datatransfer.resolver.services.StorageManager;
import org.glassfish.jersey.server.ResourceConfig;
@Path("uri-resolver")
public class UriResolver extends Application {
public class UriResolver extends ResourceConfig {
public UriResolver() {
// Register all resources present under the package.
packages("org.gcube.datatransfer.resolver.services","org.gcube.datatransfer.resolver.requesthandler");
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register resources and features
classes.add(StorageManager.class);
classes.add(Catalogue.class);
return classes;
}
}

View File

@ -83,20 +83,16 @@ public class ApplicationProfileReaderForCatalogueResolver {
*/
private void readProfileFromInfrastrucure() {
String originalScope = ScopeProvider.instance.get();
String queryString = GcubeQuery.getGcubeGenericResource(secondaryType, FIELD_TYPE.RESOURCE_NAME, resourceName);
try {
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scope):scope;
ScopeProvider.instance.set(discoveryScope);
logger.info("Trying to fetch ApplicationProfile in the scope: "+discoveryScope+", SecondaryType: " + secondaryType + ", ResourceName: " + resourceName);
logger.info("Trying to fetch ApplicationProfile in the scope: "+ScopeProvider.instance.get()+", SecondaryType: " + secondaryType + ", ResourceName: " + resourceName);
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", ResourceName: " + resourceName +" is not registered in the scope: "+discoveryScope);
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", ResourceName: " + resourceName +" is not registered in the scope: "+ScopeProvider.instance.get());
else {
try{
String elem = appProfile.get(0);
@ -117,14 +113,6 @@ public class ApplicationProfileReaderForCatalogueResolver {
} catch (Exception e) {
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
}finally{
if(originalScope!=null && !originalScope.isEmpty()){
ScopeProvider.instance.set(originalScope);
logger.info("scope provider setted to orginal scope: "+originalScope);
}else{
ScopeProvider.instance.reset();
logger.info("scope provider reset");
}
}
}

View File

@ -0,0 +1,41 @@
package org.gcube.datatransfer.resolver.requesthandler;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Provider
public class TokenSetter implements ContainerRequestFilter, ContainerResponseFilter {
private static final Logger log = LoggerFactory.getLogger(TokenSetter.class);
@Context ServletContext context;
@Override
public void filter(ContainerRequestContext ctx) throws IOException {
log.info("TokenSetter Request called");
SecurityTokenProvider.instance.set(context.getInitParameter("root-app-token"));
ScopeProvider.instance.set(context.getInitParameter("root-scope"));
}
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
log.info("TokenSetter Response called");
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}
}

View File

@ -2,7 +2,6 @@ package org.gcube.datatransfer.resolver.services;
import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -17,65 +16,32 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.Constants;
import org.gcube.datatransfer.resolver.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
import org.gcube.datatransfer.resolver.catalogue.CatalogueResolver;
import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
import org.gcube.datatransfer.resolver.catalogue.resource.UpdateApplicationProfileCatalogueResolver;
import org.gcube.datatransfer.resolver.scope.ScopeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.model.CkanDataset;
@Path(Constants.SERVLET_CATALOGUE)
@Path("/")
public class Catalogue {
private static Logger logger = LoggerFactory.getLogger(Catalogue.class);
private ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
public static final String ENV_SCOPE = "SCOPE"; //Environment Variable
/** The scope to enc decr. */
private String scopeToEncDecr = null;
public void init() throws ServletException {
initScopeFromEnv();
}
/**
* Inits the scope from env.
*
* @return the string
* @throws ServletException the servlet exception
*/
private String initScopeFromEnv() throws ServletException{
if(scopeToEncDecr!=null)
return scopeToEncDecr;
try{
scopeToEncDecr = ScopeUtil.getScopeFromEnvironment();
}catch(ServletException e){
logger.error("I cannot encrypt/descrypt: ", e);
throw new ServletException(CatalogueResolver.class.getName() +" cannot work without set the Environment Variable: "+ENV_SCOPE);
}
appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToEncDecr, true);
logger.info("Resource read for CatalogueResolver: "+appPrCatResolver);
return scopeToEncDecr;
}
ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
@GET
@Path("{ctlg(-(o|g|p|g))?}/{vreName}/{entityName}")
@Path("{entityContext:ctlg(-(o|g|p|d)?}/{vreName}/{entityName}")
public Response resolveCatalogue(@PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) {
try {
@ -118,7 +84,7 @@ public class Catalogue {
}
@POST
@Path("")
@Path("catalogue")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) {

View File

@ -2,9 +2,9 @@ package org.gcube.datatransfer.resolver.services;
import java.io.InputStream;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@ -19,14 +19,15 @@ import org.gcube.datatransfer.resolver.SingleFileStreamingOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Path("")
@Path("/")
public class StorageManager {
private static Logger logger = LoggerFactory.getLogger(StorageManager.class);
@GET
@Path("{smpId}")
@Produces()
public Response getFile(@PathParam("smpId") String smpId) {
logger.info("resolve Storage Id called");
StorageClient client = new StorageClient("DataTransfer", "UriResolver", "storageid-resolver", AccessType.PUBLIC);
IClient iClient = client.getClient();
String toSEID = iClient.getId(smpId); //to Storage Encrypted ID
@ -51,6 +52,7 @@ public class StorageManager {
logger.warn("Error when getting file metadata from storage, printing this warning and trying to continue..", e);
}
logger.info("filename retrieved is {}",fileName);
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream

View File

@ -3,5 +3,5 @@
<group>DataTransfer</group>
<version>1.0.0-SNAPSHOT</version>
<description>Storage Hub webapp</description>
<local-persistence location='target' />
<exclude handlers='request-validation context-retriever'>/*</exclude>
</application>

View File

@ -1,87 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<!--
<display-name>http resolver</display-name>
<context-param>
<param-name>root-app-token</param-name>
<param-value>e22a46ac-418c-49f2-ad3f-99a5b9689825-98187548</param-value>
</context-param>
<context-param>
<param-name>root-scope</param-name>
<param-value>/gcube</param-value>
</context-param>
root-scope
<filter>
<filter-name>uriResolverRewriteFilter</filter-name>
<filter-class>org.gcube.datatransfer.resolver.UriResolverRewriteFilter</filter-class>
</filter>
<servlet>
<servlet-name>org.gcube.datatransfer.resolver.UriResolver</servlet-name>
<filter-mapping>
<filter-name>uriResolverRewriteFilter</filter-name>
</servlet>
<servlet-mapping>
<servlet-name>org.gcube.datatransfer.resolver.UriResolver</servlet-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>smp</servlet-name>
<display-name>smp</display-name>
<servlet-class>org.gcube.datatransfer.resolver.http.HttpResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>catalogue</servlet-name>
<display-name>catalogue</display-name>
<servlet-class>org.gcube.datatransfer.resolver.catalogue.CatalogueResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>id</servlet-name>
<display-name>id</display-name>
<servlet-class>org.gcube.datatransfer.resolver.http.StorageIDResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>gisResolver</servlet-name>
<display-name>gisResolver</display-name>
<servlet-class>org.gcube.datatransfer.resolver.gis.GisResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>geonetwork</servlet-name>
<display-name>geonetwork</display-name>
<servlet-class>org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>smp</servlet-name>
<url-pattern>/smp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>gisResolver</servlet-name>
<url-pattern>/gis</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalogue</servlet-name>
<url-pattern>/catalogue</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>id</servlet-name>
<url-pattern>/id</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>geonetwork</servlet-name>
<url-pattern>/geonetwork</url-pattern>
</servlet-mapping> -->
<servlet>
<servlet-name>org.gcube.data.access.storagehub.StorageHub</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>org.gcube.data.access.storagehub.StorageHub</servlet-name>
<url-pattern>/workspace/*</url-pattern>
</servlet-mapping>
</web-app>