Fix column level security optimizations to use noauth session when needed
@@ -51,6 +51,7 @@ import com.orientechnologies.orient.core.storage.OStorageProxy;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collector;
import java.util.stream.Collectors;
/**
@@ -427,6 +428,7 @@ public class OSecurityShared implements OSecurityInternal {
if (role instanceof ORole) {
((ORole) role).reload();
}
+ updateAllFilteredProperties((ODatabaseDocumentInternal) session);
}
private void validatePolicyWithIndexes(ODatabaseSession session, String resource) throws IllegalArgumentException {
@@ -495,6 +497,7 @@ public class OSecurityShared implements OSecurityInternal {
policies.remove(resource);
roleDoc.save();
role.reload();
+ updateAllFilteredProperties((ODatabaseDocumentInternal) session);
}
private String normalizeSecurityResource(ODatabaseSession session, String resource) {
@@ -1048,11 +1051,24 @@ public class OSecurityShared implements OSecurityInternal {
protected void updateAllFilteredProperties(ODatabaseDocumentInternal session) {
try {
- Set<OSecurityResourceProperty> result = new HashSet<>();
-// session.getSharedContext().getOrientDB().executeNoAuthorization(session.getName(), (db -> {
+ Set<OSecurityResourceProperty> result;
+ if (session.getUser() == null) {
+ result = calculateAllFilteredProperties(session);
+ } else {
+ result = session.getSharedContext().getOrientDB().executeNoAuthorization(session.getName(), (db -> calculateAllFilteredProperties(db))).get();
+ }
+ synchronized (this) {
+ filteredProperties = result;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ protected Set<OSecurityResourceProperty> calculateAllFilteredProperties(ODatabaseSession session) {
+ Set<OSecurityResourceProperty> result = new HashSet<>();
if (session.getClass("ORole") == null) {
- return;
+ return Collections.emptySet();
}
OResultSet rs = session.query("select policies from ORole");
while (rs.hasNext()) {
@@ -1075,13 +1091,6 @@ public class OSecurityShared implements OSecurityInternal {
}
}
rs.close();
-// return null;
-// })).get();
- synchronized (this) {
- filteredProperties = result;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+ return result;
}
}
