modificato con lucio

This commit is contained in:
Alfredo Oliviero 2024-02-16 18:05:14 +01:00
parent 8f97369935
commit 322dd3c8f4
5 changed files with 61 additions and 92 deletions

View File

@ -9,18 +9,11 @@
<description>
A gcube service - smartgears 4
</description>
<context-param>
<param-name>resolver-basepath</param-name>
<param-value>https://data-d.d4science.org/shub</param-value>
</context-param>
<servlet>
<servlet-name>IDM</servlet-name>
<servlet-class>org.gcube.idm.IdentityManagerResourceInitializer</servlet-class>
<servlet-name>org.gcube.idm.IdentityManagerResourceInitializer</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>IDM</servlet-name>
<url-pattern>/identity-manager/*</url-pattern>
<servlet-name>org.gcube.idm.IdentityManagerResourceInitializer</servlet-name>
<url-pattern>/idm/*</url-pattern>
</servlet-mapping>
</web-app>

52
pom.xml
View File

@ -43,47 +43,39 @@
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-security</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId>
</dependency>
<!-- smartgears -->
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId>
<artifactId>common-smartgears-app</artifactId>
</dependency>
<!-- jersey -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<!-- add jackson as json provider -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- Required for Enunciate plugin -->

View File

@ -1,38 +0,0 @@
package org.gcube.idm;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
/**
* @author Alfredo Oliviero (ISTI - CNR)
*/
@Provider
public class IdentityManagerExceptionMapper implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception exception) {
Status status = Status.INTERNAL_SERVER_ERROR;
String exceptionMessage = exception.getMessage();
try {
if(exception.getCause() != null) {
exceptionMessage = exception.getCause().getMessage();
}
} catch(Exception e) {
exceptionMessage = exception.getMessage();
}
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
if(WebApplicationException.class.isAssignableFrom(exception.getClass())) {
Response gotResponse = ((WebApplicationException) exception).getResponse();
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
}
return Response.status(status).entity(exceptionMessage).type(mediaType).build();
}
}

View File

@ -1,7 +1,13 @@
package org.gcube.idm;
import javax.ws.rs.ApplicationPath;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextWriter;
import org.gcube.idm.rest.TestRest;
import org.gcube.smartgears.annotations.ManagedBy;
import org.glassfish.jersey.server.ResourceConfig;
@ -10,17 +16,17 @@ import org.glassfish.jersey.server.ResourceConfig;
* @author Alfredo Oliviero (ISTI - CNR)
*/
// SMARTGEARS
// SMARTGEARS
// legge i parametri del service da application.yaml
@ApplicationPath("/")
@ManagedBy(IdentityManagerdInitializator.class)
public class IdentityManagerResourceInitializer extends ResourceConfig {
@Path("idm")
public class IdentityManagerResourceInitializer extends Application {
public IdentityManagerResourceInitializer() {
packages(TestRest.class.getPackage().toString());
//packages(UsersRest.class.getPackage().toString());
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register resources and features
classes.add(TestRest.class);
return classes;
}
}

View File

@ -4,6 +4,11 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret;
import org.gcube.idm.IdentityManagerdInitializator;
import org.gcube.smartgears.annotations.ManagedBy;
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
@ -15,6 +20,7 @@ import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
@RequestHeaders({
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
})
@ManagedBy(IdentityManagerdInitializator.class)
public class TestRest {
@GET
@ -24,4 +30,14 @@ public class TestRest {
return "{'aaa':bbb'}";
}
@GET
@Path("show_context")
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
public String show_context(){
Secret smp = SecretManagerProvider.instance.get();
String ctx = smp.getContext();
return ctx;
}
}