Fix race condition in security optimizations
@@ -882,9 +882,6 @@ public class OSecurityShared implements OSecurityInternal {
}
protected void initPredicateSecurityOptimizations(ODatabaseSession session) {
- if (true) {
- return;
- }
try {
if (session.getUser() == null) {
initPredicateSecurityOptimizationsInternal(session);
@@ -901,15 +898,10 @@ public class OSecurityShared implements OSecurityInternal {
}
private void initPredicateSecurityOptimizationsInternal(ODatabaseSession session) {
- if (this.roleHasPredicateSecurityForClass == null) {
- this.roleHasPredicateSecurityForClass = new HashMap<>();
- }
- synchronized (this.roleHasPredicateSecurityForClass) {
- this.roleHasPredicateSecurityForClass.clear();
-
+ Map<String, Map<String, Boolean>> result = new HashMap<>();
Collection<OClass> allClasses = session.getMetadata().getSchema().getClasses();
- Set<OSecurityResourceProperty> result = new HashSet<>();
+
if (session.getClass("ORole") == null) {
return;
}
@@ -927,10 +919,10 @@ public class OSecurityShared implements OSecurityInternal {
for (OClass clazz : allClasses) {
if (isClassInvolved(clazz, res) && !isAllAllowed(session, new OSecurityPolicy(policyEntry.getValue().getRecord()))) {
- Map<String, Boolean> roleMap = this.roleHasPredicateSecurityForClass.get(roleName);
+ Map<String, Boolean> roleMap = result.get(roleName);
if (roleMap == null) {
roleMap = new HashMap<>();
- roleHasPredicateSecurityForClass.put(roleName, roleMap);
+ result.put(roleName, roleMap);
}
roleMap.put(clazz.getName(), false);
}
@@ -942,9 +934,7 @@ public class OSecurityShared implements OSecurityInternal {
rs.close();
}
}
- return;
- }
-
+ this.roleHasPredicateSecurityForClass = result;
}
private boolean isAllAllowed(ODatabaseSession db, OSecurityPolicy policy) {
@@ -1323,6 +1313,9 @@ public class OSecurityShared implements OSecurityInternal {
}
public boolean couldHaveActivePredicateSecurityRoles(ODatabaseSession session, String className) {
+ if (session.getUser() == null) {
+ return false;
+ }
if (roleHasPredicateSecurityForClass != null) {
for (OSecurityRole role : session.getUser().getRoles()) {
Map<String, Boolean> roleMap = roleHasPredicateSecurityForClass.get(role.getName());
