Optimise security checks
canUpdate()
@@ -1329,11 +1329,17 @@ public class OSecurityShared implements OSecurityInternal {
return true;
}
- OClass clazz = ((OElement) document).getSchemaType().orElse(null);
- if (clazz == null) {
+ String className;
+ OClass clazz = null;
+ if (document instanceof ODocument) {
+ className = document.getClassName();
+ } else {
+ clazz = ((OElement) document).getSchemaType().orElse(null);
+ className = clazz == null ? null : clazz.getName();
+ }
+ if (className == null) {
return true;
}
- String className = clazz.getName();
if (roleHasPredicateSecurityForClass != null) {
for (OSecurityRole role : session.getUser().getRoles()) {
@@ -1348,6 +1354,10 @@ public class OSecurityShared implements OSecurityInternal {
}
}
+ if (clazz == null) {
+ clazz = ((OElement) document).getSchemaType().orElse(null);
+ }
+
if (document.getIdentity().isNew()) {
OBooleanExpression predicate =
OSecurityEngine.getPredicateForSecurityResource(
@@ -1485,7 +1495,12 @@ public class OSecurityShared implements OSecurityInternal {
}
if (record instanceof OElement) {
- String className = ((OElement) record).getSchemaType().map(x -> x.getName()).orElse(null);
+ String className;
+ if (record instanceof ODocument) {
+ className = ((ODocument) record).getClassName();
+ } else {
+ className = ((OElement) record).getSchemaType().map(x -> x.getName()).orElse(null);
+ }
if (className != null && roleHasPredicateSecurityForClass != null) {
for (OSecurityRole role : session.getUser().getRoles()) {
