resource-registry/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/QueryTemplatesSecurityConte...

63 lines
2.1 KiB
Java
Raw Normal View History

2021-10-21 16:32:05 +02:00
package org.gcube.informationsystem.resourceregistry.contexts.security;
import java.util.UUID;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
2021-10-21 16:32:05 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class QueryTemplatesSecurityContext extends SecurityContext {
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
private static final String QUERY_TEMPLATES_SECURITY_CONTEXT;
private static final UUID QUERY_TEMPLATES_SECURITY_CONTEXT_UUID;
2021-10-21 16:32:05 +02:00
static {
2021-10-21 19:14:45 +02:00
QUERY_TEMPLATES_SECURITY_CONTEXT = "dddddddd-dddd-dddd-dddd-dddddddddddd";
QUERY_TEMPLATES_SECURITY_CONTEXT_UUID = UUID.fromString(QUERY_TEMPLATES_SECURITY_CONTEXT);
2021-10-21 16:32:05 +02:00
}
private static QueryTemplatesSecurityContext instance;
public static QueryTemplatesSecurityContext getInstance() throws ResourceRegistryException {
if(instance==null) {
instance = new QueryTemplatesSecurityContext();
ContextUtility contextUtility = ContextUtility.getInstance();
contextUtility.addSecurityContext(QUERY_TEMPLATES_SECURITY_CONTEXT, instance);
}
return instance;
}
private QueryTemplatesSecurityContext() throws ResourceRegistryException {
2021-10-21 19:14:45 +02:00
super(QUERY_TEMPLATES_SECURITY_CONTEXT_UUID, false);
2021-10-21 16:32:05 +02:00
}
@Override
2023-05-11 18:35:56 +02:00
protected Role addExtraRules(Role role, PermissionMode permissionMode) {
2021-10-21 16:32:05 +02:00
logger.trace("Adding extra rules for {}", role.getName());
switch(permissionMode) {
case WRITER:
2023-05-11 18:35:56 +02:00
role.addRule(Rule.ResourceGeneric.CLUSTER, null, Role.PERMISSION_ALL);
role.addRule(Rule.ResourceGeneric.SYSTEM_CLUSTERS, null, Role.PERMISSION_ALL);
role.addRule(Rule.ResourceGeneric.CLASS, null, Role.PERMISSION_ALL);
2021-10-21 16:32:05 +02:00
break;
case READER:
2023-05-11 18:35:56 +02:00
role.addRule(Rule.ResourceGeneric.CLUSTER, null, Role.PERMISSION_READ);
role.addRule(Rule.ResourceGeneric.SYSTEM_CLUSTERS, null, Role.PERMISSION_READ);
role.addRule(Rule.ResourceGeneric.CLASS, null, Role.PERMISSION_READ);
2021-10-21 16:32:05 +02:00
break;
default:
break;
}
return role;
}
}