style - code formatting
This commit is contained in:
parent
bacba3984c
commit
cc2d0b74cd
|
@ -10,7 +10,7 @@
|
|||
"projectName": "identity-manager",
|
||||
"request": "attach",
|
||||
"hostName": "localhost",
|
||||
"port": 5005
|
||||
"port": 5005
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
mvn clean package
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 smartgears-helloworld
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 smartgears-helloworld
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mvn package
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 -p 5005:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" smartgears-helloworld
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 -p 5005:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" smartgears-helloworld
|
||||
|
|
40
pom.xml
40
pom.xml
|
@ -1,4 +1,6 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
|
@ -90,24 +92,24 @@
|
|||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>${aspectj-plugin.version}</version>
|
||||
<configuration>
|
||||
<complianceLevel>11</complianceLevel>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-control-library</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<complianceLevel>11</complianceLevel>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-control-library</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -6,11 +6,14 @@ import java.util.Set;
|
|||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
import org.gcube.service.helloworld.services.AuthorizedMethods;
|
||||
import org.gcube.service.helloworld.services.ExcludeAuthorization;
|
||||
import org.gcube.service.helloworld.services.AuthenticatedService;
|
||||
import org.gcube.service.helloworld.services.ExcludeAuthorizationService;
|
||||
import org.gcube.service.helloworld.services.HelloService;
|
||||
import org.gcube.service.helloworld.services.TestAuthorizationService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
*/
|
||||
|
||||
@ApplicationPath("")
|
||||
public class HelloWorld extends Application {
|
||||
|
@ -19,9 +22,8 @@ public class HelloWorld extends Application {
|
|||
final Set<Class<?>> classes = new HashSet<Class<?>>();
|
||||
// register resources classes implementing Servlets
|
||||
classes.add(HelloService.class);
|
||||
classes.add(ExcludeAuthorization.class);
|
||||
classes.add(TestAuthorizationService.class);
|
||||
|
||||
classes.add(ExcludeAuthorizationService.class);
|
||||
classes.add(AuthenticatedService.class);
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,7 @@ import org.slf4j.LoggerFactory;
|
|||
* to the app declaring it via the @ManagedBy annotation. (@see HelloWorld
|
||||
* class)
|
||||
*
|
||||
*
|
||||
* @author lucio
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
*/
|
||||
|
||||
public class HelloWorldManager implements ApplicationManager {
|
||||
|
@ -26,7 +24,7 @@ public class HelloWorldManager implements ApplicationManager {
|
|||
Logger logger = LoggerFactory.getLogger(HelloWorldManager.class);
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
public void onInit() {
|
||||
if (ContextProvider.get().container().configuration().mode() == Mode.offline) {
|
||||
logger.debug("init called in offline mode");
|
||||
} else {
|
||||
|
@ -35,7 +33,7 @@ public class HelloWorldManager implements ApplicationManager {
|
|||
logger.debug("init called in context {}", secret.getContext());
|
||||
} else {
|
||||
logger.debug("init called in null context");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +47,7 @@ public class HelloWorldManager implements ApplicationManager {
|
|||
logger.debug("shutDown called in context {}", secret.getContext());
|
||||
} else {
|
||||
logger.debug("shutDown called in null context");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,18 +8,25 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
public class ContainerConfigurationSerializer extends StdSerializer<ContainerConfiguration> {
|
||||
/**
|
||||
* Jackson serializer for ContainerConfiguration
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContainerConfigurationSerializer extends StdSerializer<ContainerConfiguration> {
|
||||
protected ContainerConfigurationSerializer(Class<ContainerConfiguration> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public ContainerConfigurationSerializer(){
|
||||
public ContainerConfigurationSerializer() {
|
||||
super(ContainerConfiguration.class, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ContainerConfiguration configuration, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
public void serialize(ContainerConfiguration configuration, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeObjectField("mode", configuration.mode());
|
||||
jgen.writeObjectField("app", configuration.apps());
|
||||
|
@ -33,8 +40,6 @@ public class ContainerConfigurationSerializer extends StdSerializer<ContainerCon
|
|||
|
||||
jgen.writeObjectField("desc", configuration.toString());
|
||||
|
||||
|
||||
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,22 +8,29 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
public class ContainerContextSerializer extends StdSerializer<ContainerContext> {
|
||||
/**
|
||||
* Jackson serializer for ContainerContext
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContainerContextSerializer extends StdSerializer<ContainerContext> {
|
||||
protected ContainerContextSerializer(Class<ContainerContext> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public ContainerContextSerializer(){
|
||||
public ContainerContextSerializer() {
|
||||
super(ContainerContext.class, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ContainerContext ccontext, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
public void serialize(ContainerContext ccontext, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField("id", ccontext.id());
|
||||
// jgen.writeObjectField("configuration.site", ccontext.configuration().site());
|
||||
//jgen.writeObjectField("configuration", ccontext.configuration());
|
||||
// jgen.writeObjectField("configuration", ccontext.configuration());
|
||||
jgen.writeObjectField("properties", ccontext.properties());
|
||||
jgen.writeObjectField("authorizationProvider", ccontext.authorizationProvider());
|
||||
|
||||
|
|
|
@ -7,20 +7,26 @@ import org.gcube.smartgears.security.SimpleCredentials;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
||||
public class SmartGearSerializator {
|
||||
private static ObjectMapper serializer = null;
|
||||
/**
|
||||
* Jackson Serialization utils for Smartgear Context classes
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContextSerializator {
|
||||
private static ObjectMapper serializer = null;
|
||||
|
||||
public static ObjectMapper getSerializer() {
|
||||
if (serializer == null) {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
SimpleModule module = new SimpleModule();
|
||||
// module.addSerializer(Owner.class, new OwnerSerializer());
|
||||
|
||||
|
||||
module.addSerializer(ContainerConfiguration.class, new ContainerConfigurationSerializer());
|
||||
module.addSerializer(ContainerContext.class, new ContainerContextSerializer());
|
||||
module.addSerializer(SimpleCredentials.class, new SimpleCredentialsSerializer());
|
||||
|
||||
|
||||
|
||||
om.registerModule(module);
|
||||
serializer = om;
|
||||
}
|
|
@ -8,17 +8,23 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
/**
|
||||
* Jackson serializer for Owner
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class OwnerSerializer extends StdSerializer<Owner> {
|
||||
|
||||
protected OwnerSerializer(Class<Owner> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public OwnerSerializer(){
|
||||
public OwnerSerializer() {
|
||||
super(Owner.class, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(Owner owner, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
jgen.writeStartObject();
|
||||
|
|
|
@ -8,19 +8,26 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
/**
|
||||
* Jackson serializer for SimpleCredentials
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class SimpleCredentialsSerializer extends StdSerializer<SimpleCredentials> {
|
||||
|
||||
protected SimpleCredentialsSerializer(Class<SimpleCredentials> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public SimpleCredentialsSerializer(){
|
||||
public SimpleCredentialsSerializer() {
|
||||
super(SimpleCredentials.class, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(SimpleCredentials credentials, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
public void serialize(SimpleCredentials credentials, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField("clientId", credentials.getClientID());
|
||||
jgen.writeStringField("secret", "[*****]");
|
||||
|
|
|
@ -10,13 +10,18 @@ import org.gcube.common.security.providers.SecretManagerProvider;
|
|||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
||||
/**
|
||||
* @author Lucio Le (ISTI - CNR)
|
||||
* @author Alfredo Oliviero (ISTI - CNR)
|
||||
*/
|
||||
|
||||
@Path("auth")
|
||||
public class TestAuthorizationService {
|
||||
public class AuthenticatedService {
|
||||
|
||||
private static final String ALLOWED_ROLE = "myRole";
|
||||
private static final String ALLOWED_ROLE_ORG = "OrganizationMember";
|
||||
|
||||
@AuthorizationControl(allowedRoles={ALLOWED_ROLE_ORG})
|
||||
|
||||
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE_ORG })
|
||||
@GET
|
||||
@Path("org_member")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
|
@ -25,10 +30,12 @@ public class TestAuthorizationService {
|
|||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format("User %s in context %s is authorized to execute this method because he has the correct role", userId,context);
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the correct role", userId,
|
||||
context);
|
||||
}
|
||||
|
||||
@AuthorizationControl(allowedRoles={ALLOWED_ROLE})
|
||||
|
||||
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE })
|
||||
@GET
|
||||
@Path("")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
|
@ -37,7 +44,9 @@ public class TestAuthorizationService {
|
|||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format("User %s in context %s is authorized to execute this method because he has the correct role", userId,context);
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the correct role", userId,
|
||||
context);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -13,7 +13,7 @@ import org.gcube.common.security.Owner;
|
|||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.service.helloworld.manager.HelloWorldManager;
|
||||
import org.gcube.service.helloworld.serializers.SmartGearSerializator;
|
||||
import org.gcube.service.helloworld.serializers.ContextSerializator;
|
||||
import org.gcube.smartgears.ContextProvider;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
|
@ -24,6 +24,12 @@ import org.slf4j.LoggerFactory;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*/
|
||||
|
||||
@ManagedBy(HelloWorldManager.class)
|
||||
@Path("")
|
||||
public class HelloService {
|
||||
|
@ -38,23 +44,23 @@ public class HelloService {
|
|||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
|
||||
|
||||
String infrastructureName = ContextProvider.get().container().configuration().infrastructure();
|
||||
logger.info("caller id is {}",userId);
|
||||
return String.format("Hello %s in context %s in infastructure %s -roles %s", userId,context, infrastructureName, secret.getOwner().getRoles());
|
||||
logger.info("caller id is {}", userId);
|
||||
return String.format("Hello %s in context %s in infastructure %s -roles %s", userId, context,
|
||||
infrastructureName, secret.getOwner().getRoles());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("details")
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response details() {
|
||||
InnerMethodName.set("details");
|
||||
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
|
||||
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
|
||||
|
||||
String context = secret.getContext();
|
||||
data.put("context", context);
|
||||
|
||||
|
@ -64,7 +70,7 @@ public class HelloService {
|
|||
ContainerContext container = ContextProvider.get().container();
|
||||
data.put("container", container);
|
||||
|
||||
ObjectMapper objectMapper = SmartGearSerializator.getSerializer();
|
||||
ObjectMapper objectMapper = ContextSerializator.getSerializer();
|
||||
|
||||
try {
|
||||
String jsonData = objectMapper.writeValueAsString(data);
|
||||
|
@ -75,5 +81,5 @@ public class HelloService {
|
|||
return Response.serverError().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -5,15 +5,12 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.security.Owner;
|
||||
import org.gcube.service.helloworld.serializers.ContainerConfigurationSerializer;
|
||||
import org.gcube.service.helloworld.serializers.ContainerContextSerializer;
|
||||
import org.gcube.service.helloworld.serializers.SimpleCredentialsSerializer;
|
||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
import org.gcube.smartgears.security.SimpleCredentials;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
/**
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
*/
|
||||
|
||||
public class RestUtils {
|
||||
|
||||
|
@ -45,11 +42,11 @@ public class RestUtils {
|
|||
return data;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getContainerDict(ContainerContext container){
|
||||
public static Map<String, Object> getContainerDict(ContainerContext container) {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", container.id());
|
||||
data.put("configuration", container.configuration());
|
||||
//data.put("lifecycle", container.lifecycle());
|
||||
// data.put("lifecycle", container.lifecycle());
|
||||
data.put("properties", container.properties());
|
||||
data.put("authorizationProvider", container.authorizationProvider());
|
||||
return data;
|
||||
|
|
Loading…
Reference in New Issue