style - code formatting

This commit is contained in:
Alfredo Oliviero 2024-02-23 17:35:59 +01:00
parent bacba3984c
commit cc2d0b74cd
14 changed files with 129 additions and 84 deletions

View File

@ -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> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>

View File

@ -6,11 +6,14 @@ import java.util.Set;
import javax.ws.rs.ApplicationPath; import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application; import javax.ws.rs.core.Application;
import org.gcube.service.helloworld.services.AuthorizedMethods; import org.gcube.service.helloworld.services.AuthenticatedService;
import org.gcube.service.helloworld.services.ExcludeAuthorization; import org.gcube.service.helloworld.services.ExcludeAuthorizationService;
import org.gcube.service.helloworld.services.HelloService; import org.gcube.service.helloworld.services.HelloService;
import org.gcube.service.helloworld.services.TestAuthorizationService;
/**
*
* @author Lucio Lelii (ISTI-CNR)
*/
@ApplicationPath("") @ApplicationPath("")
public class HelloWorld extends Application { public class HelloWorld extends Application {
@ -19,9 +22,8 @@ public class HelloWorld extends Application {
final Set<Class<?>> classes = new HashSet<Class<?>>(); final Set<Class<?>> classes = new HashSet<Class<?>>();
// register resources classes implementing Servlets // register resources classes implementing Servlets
classes.add(HelloService.class); classes.add(HelloService.class);
classes.add(ExcludeAuthorization.class); classes.add(ExcludeAuthorizationService.class);
classes.add(TestAuthorizationService.class); classes.add(AuthenticatedService.class);
return classes; return classes;
} }
} }

View File

@ -16,9 +16,7 @@ import org.slf4j.LoggerFactory;
* to the app declaring it via the @ManagedBy annotation. (@see HelloWorld * to the app declaring it via the @ManagedBy annotation. (@see HelloWorld
* class) * class)
* *
* * @author Lucio Lelii (ISTI-CNR)
* @author lucio
*
*/ */
public class HelloWorldManager implements ApplicationManager { public class HelloWorldManager implements ApplicationManager {

View File

@ -8,6 +8,13 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* Jackson serializer for ContainerConfiguration
*
* @author Alfredo Oliviero (ISTI-CNR)
*
*/
public class ContainerConfigurationSerializer extends StdSerializer<ContainerConfiguration> { public class ContainerConfigurationSerializer extends StdSerializer<ContainerConfiguration> {
protected ContainerConfigurationSerializer(Class<ContainerConfiguration> t) { protected ContainerConfigurationSerializer(Class<ContainerConfiguration> t) {
super(t); super(t);
@ -17,9 +24,9 @@ public class ContainerConfigurationSerializer extends StdSerializer<ContainerCon
super(ContainerConfiguration.class, true); super(ContainerConfiguration.class, true);
} }
@Override @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.writeStartObject();
jgen.writeObjectField("mode", configuration.mode()); jgen.writeObjectField("mode", configuration.mode());
jgen.writeObjectField("app", configuration.apps()); jgen.writeObjectField("app", configuration.apps());
@ -33,8 +40,6 @@ public class ContainerConfigurationSerializer extends StdSerializer<ContainerCon
jgen.writeObjectField("desc", configuration.toString()); jgen.writeObjectField("desc", configuration.toString());
jgen.writeEndObject(); jgen.writeEndObject();
} }
} }

View File

@ -8,6 +8,13 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* Jackson serializer for ContainerContext
*
* @author Alfredo Oliviero (ISTI-CNR)
*
*/
public class ContainerContextSerializer extends StdSerializer<ContainerContext> { public class ContainerContextSerializer extends StdSerializer<ContainerContext> {
protected ContainerContextSerializer(Class<ContainerContext> t) { protected ContainerContextSerializer(Class<ContainerContext> t) {
super(t); super(t);
@ -17,9 +24,9 @@ public class ContainerContextSerializer extends StdSerializer<ContainerContext>
super(ContainerContext.class, true); super(ContainerContext.class, true);
} }
@Override @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.writeStartObject();
jgen.writeStringField("id", ccontext.id()); jgen.writeStringField("id", ccontext.id());
// jgen.writeObjectField("configuration.site", ccontext.configuration().site()); // jgen.writeObjectField("configuration.site", ccontext.configuration().site());

View File

@ -7,7 +7,14 @@ import org.gcube.smartgears.security.SimpleCredentials;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleModule;
public class SmartGearSerializator { /**
* Jackson Serialization utils for Smartgear Context classes
*
* @author Alfredo Oliviero (ISTI-CNR)
*
*/
public class ContextSerializator {
private static ObjectMapper serializer = null; private static ObjectMapper serializer = null;
public static ObjectMapper getSerializer() { public static ObjectMapper getSerializer() {
@ -20,7 +27,6 @@ public class SmartGearSerializator {
module.addSerializer(ContainerContext.class, new ContainerContextSerializer()); module.addSerializer(ContainerContext.class, new ContainerContextSerializer());
module.addSerializer(SimpleCredentials.class, new SimpleCredentialsSerializer()); module.addSerializer(SimpleCredentials.class, new SimpleCredentialsSerializer());
om.registerModule(module); om.registerModule(module);
serializer = om; serializer = om;
} }

View File

@ -8,6 +8,13 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* Jackson serializer for Owner
*
* @author Alfredo Oliviero (ISTI-CNR)
*
*/
public class OwnerSerializer extends StdSerializer<Owner> { public class OwnerSerializer extends StdSerializer<Owner> {
protected OwnerSerializer(Class<Owner> t) { protected OwnerSerializer(Class<Owner> t) {
@ -18,7 +25,6 @@ public class OwnerSerializer extends StdSerializer<Owner> {
super(Owner.class, true); super(Owner.class, true);
} }
@Override @Override
public void serialize(Owner owner, JsonGenerator jgen, SerializerProvider provider) throws IOException { public void serialize(Owner owner, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject(); jgen.writeStartObject();

View File

@ -8,6 +8,13 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* Jackson serializer for SimpleCredentials
*
* @author Alfredo Oliviero (ISTI-CNR)
*
*/
public class SimpleCredentialsSerializer extends StdSerializer<SimpleCredentials> { public class SimpleCredentialsSerializer extends StdSerializer<SimpleCredentials> {
protected SimpleCredentialsSerializer(Class<SimpleCredentials> t) { protected SimpleCredentialsSerializer(Class<SimpleCredentials> t) {
@ -18,9 +25,9 @@ public class SimpleCredentialsSerializer extends StdSerializer<SimpleCredentials
super(SimpleCredentials.class, true); super(SimpleCredentials.class, true);
} }
@Override @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.writeStartObject();
jgen.writeStringField("clientId", credentials.getClientID()); jgen.writeStringField("clientId", credentials.getClientID());
jgen.writeStringField("secret", "[*****]"); jgen.writeStringField("secret", "[*****]");

View File

@ -10,8 +10,13 @@ import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret; import org.gcube.common.security.secrets.Secret;
import org.gcube.smartgears.utils.InnerMethodName; import org.gcube.smartgears.utils.InnerMethodName;
/**
* @author Lucio Le (ISTI - CNR)
* @author Alfredo Oliviero (ISTI - CNR)
*/
@Path("auth") @Path("auth")
public class TestAuthorizationService { public class AuthenticatedService {
private static final String ALLOWED_ROLE = "myRole"; private static final String ALLOWED_ROLE = "myRole";
private static final String ALLOWED_ROLE_ORG = "OrganizationMember"; private static final String ALLOWED_ROLE_ORG = "OrganizationMember";
@ -25,7 +30,9 @@ public class TestAuthorizationService {
Secret secret = SecretManagerProvider.get(); Secret secret = SecretManagerProvider.get();
String userId = secret.getOwner().getId(); String userId = secret.getOwner().getId();
String context = secret.getContext(); 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 })
@ -37,7 +44,9 @@ public class TestAuthorizationService {
Secret secret = SecretManagerProvider.get(); Secret secret = SecretManagerProvider.get();
String userId = secret.getOwner().getId(); String userId = secret.getOwner().getId();
String context = secret.getContext(); 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);
} }
} }

View File

@ -13,7 +13,7 @@ import org.gcube.common.security.Owner;
import org.gcube.common.security.providers.SecretManagerProvider; import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret; import org.gcube.common.security.secrets.Secret;
import org.gcube.service.helloworld.manager.HelloWorldManager; 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.ContextProvider;
import org.gcube.smartgears.annotations.ManagedBy; import org.gcube.smartgears.annotations.ManagedBy;
import org.gcube.smartgears.context.container.ContainerContext; 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.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
/**
*
* @author Lucio Lelii (ISTI-CNR)
* @author Alfredo Oliviero (ISTI-CNR)
*/
@ManagedBy(HelloWorldManager.class) @ManagedBy(HelloWorldManager.class)
@Path("") @Path("")
public class HelloService { public class HelloService {
@ -41,7 +47,8 @@ public class HelloService {
String infrastructureName = ContextProvider.get().container().configuration().infrastructure(); String infrastructureName = ContextProvider.get().container().configuration().infrastructure();
logger.info("caller id is {}", userId); 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()); return String.format("Hello %s in context %s in infastructure %s -roles %s", userId, context,
infrastructureName, secret.getOwner().getRoles());
} }
@GET @GET
@ -54,7 +61,6 @@ public class HelloService {
Secret secret = SecretManagerProvider.get(); Secret secret = SecretManagerProvider.get();
String context = secret.getContext(); String context = secret.getContext();
data.put("context", context); data.put("context", context);
@ -64,7 +70,7 @@ public class HelloService {
ContainerContext container = ContextProvider.get().container(); ContainerContext container = ContextProvider.get().container();
data.put("container", container); data.put("container", container);
ObjectMapper objectMapper = SmartGearSerializator.getSerializer(); ObjectMapper objectMapper = ContextSerializator.getSerializer();
try { try {
String jsonData = objectMapper.writeValueAsString(data); String jsonData = objectMapper.writeValueAsString(data);

View File

@ -5,15 +5,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.common.security.Owner; 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.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 { public class RestUtils {