Fixed code
This commit is contained in:
parent
804e2b2343
commit
f9e474d4cd
|
@ -42,6 +42,11 @@ public class AdminSecurityContext extends SecurityContext {
|
|||
super(ADMIN_SECURITY_CONTEXT_UUID, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHierarchicalMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
throw new RuntimeException("Cannot use this method for Admin Context");
|
||||
|
|
|
@ -40,6 +40,11 @@ public class ContextSecurityContext extends SecurityContext {
|
|||
super(CONTEXT_SECURITY_CONTEXT_UUID, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHierarchicalMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ORole addExtraRules(ORole role, PermissionMode permissionMode) {
|
||||
logger.trace("Adding extra rules for {}", role.getName());
|
||||
|
|
|
@ -40,6 +40,11 @@ public class QueryTemplatesSecurityContext extends SecurityContext {
|
|||
super(QUERY_TEMPLATES_SECURITY_CONTEXT_UUID, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHierarchicalMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ORole addExtraRules(ORole role, PermissionMode permissionMode) {
|
||||
logger.trace("Adding extra rules for {}", role.getName());
|
||||
|
|
|
@ -10,16 +10,13 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.requests.RequestUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.requests.ServerRequestInfo;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
|
||||
import org.gcube.informationsystem.utils.UUIDManager;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -413,46 +410,34 @@ public class SecurityContext {
|
|||
}
|
||||
|
||||
protected boolean allowed(final ORole role, final ODocument oDocument) {
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
Callable<Boolean> callable = new Callable<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
RequestUtility.getRequestInfo().get().setHierarchicalMode(false);
|
||||
ServerRequestInfo sri = RequestUtility.getRequestInfo().get();
|
||||
Boolean hm = sri.isHierarchicalMode();
|
||||
sri.setHierarchicalMode(false);
|
||||
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
oDatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
||||
oDatabaseDocument.activateOnCurrentThread();
|
||||
ORecord element = oDatabaseDocument.getRecord(oDocument.getIdentity());
|
||||
if(element == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
} finally {
|
||||
if(oDatabaseDocument!=null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Future<Boolean> result = executor.submit(callable);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
return result.get();
|
||||
oDatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
||||
oDatabaseDocument.activateOnCurrentThread();
|
||||
ORecord element = oDatabaseDocument.getRecord(oDocument.getIdentity());
|
||||
if(element == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
} finally {
|
||||
sri.setHierarchicalMode(hm);
|
||||
|
||||
if(oDatabaseDocument!=null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void create() throws ResourceRegistryException {
|
||||
|
|
|
@ -40,6 +40,11 @@ public class TypeSecurityContext extends SecurityContext {
|
|||
super(SCHEMA_SECURITY_CONTEXT_UUID, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHierarchicalMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ORole addExtraRules(ORole role, PermissionMode permissionMode) {
|
||||
logger.trace("Adding extra rules for {}", role.getName());
|
||||
|
|
|
@ -912,10 +912,10 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getContextsSet() throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.trace("Going to get contexts for {} instance with UUID {}", typeName, uuid);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument instanceDB = this.oDatabaseDocument;
|
||||
try {
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
|
@ -939,6 +939,10 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
|
||||
if(instanceDB!=null) {
|
||||
this.oDatabaseDocument = instanceDB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue