Skip to content

Commit bca7e04

Browse files
authored
Merge pull request #664 from rubnig/bugfix/663-prefetch-query-traversal-limit
[663] Fix prefetch query traversal limit
2 parents 620d540 + eece0cf commit bca7e04

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

Diff for: accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableinstaller/impl/AuthInstallerUserManagerPrefetchingImpl.java

+32-16
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ public AuthInstallerUserManagerPrefetchingImpl(UserManager delegate, final Value
6868
Iterator<Authorizable> authorizablesToPrefetchIt = delegate.findAuthorizables(new Query() {
6969
public <T> void build(QueryBuilder<T> builder) {
7070
builder.setCondition(
71-
builder.or( //
72-
builder.neq("@" + JcrConstants.JCR_PRIMARYTYPE, valueFactory.createValue(UserConstants.NT_REP_USER)),
73-
builder.eq("@" + UserConstants.REP_AUTHORIZABLE_ID, valueFactory.createValue(Constants.USER_ANONYMOUS))) //
71+
builder.or(
72+
builder.eq("@" + JcrConstants.JCR_PRIMARYTYPE, valueFactory.createValue(UserConstants.NT_REP_SYSTEM_USER)),
73+
builder.eq("@" + JcrConstants.JCR_PRIMARYTYPE, valueFactory.createValue(UserConstants.NT_REP_GROUP))
74+
)
7475
);
7576
}
7677
});
@@ -81,22 +82,16 @@ public <T> void build(QueryBuilder<T> builder) {
8182
long startPrefetchMemberships = System.currentTimeMillis();
8283
while (authorizablesToPrefetchIt.hasNext()) {
8384
Authorizable auth = authorizablesToPrefetchIt.next();
84-
String authId = auth.getID();
85-
86-
// also cache those groups which are not member of any other group!
87-
Set<String> memberOfByAuthorizableIds = new HashSet<>();
88-
this.isMemberOfByAuthorizableId.put(authId, memberOfByAuthorizableIds);
89-
Iterator<Group> declaredMemberOf = auth.declaredMemberOf();
90-
while (declaredMemberOf.hasNext()) {
91-
Group memberOfGroup = declaredMemberOf.next();
92-
String memberOfGroupId = memberOfGroup.getID();
93-
memberOfByAuthorizableIds.add(memberOfGroupId);
94-
nonRegularUserMembersByAuthorizableId.computeIfAbsent(memberOfGroupId, id -> new HashSet<>()).add(authId);
95-
membershipCount++;
96-
}
85+
membershipCount += prefetchAuthorizable(auth);
9786
authorizableIdsAndPaths.put(auth.getID(), auth.getPath());
9887
}
9988

89+
Authorizable anonymous = delegate.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
90+
if (anonymous != null) {
91+
membershipCount += prefetchAuthorizable(anonymous);
92+
authorizableIdsAndPaths.put(anonymous.getID(), anonymous.getPath());
93+
}
94+
10095
installLog.addMessage(LOG, "Prefetched " + membershipCount + " memberships in "
10196
+ msHumanReadable(System.currentTimeMillis() - startPrefetchMemberships));
10297
}
@@ -147,6 +142,27 @@ public void removeAuthorizable(final Authorizable authorizable) throws Repositor
147142
authorizableIdsAndPaths.remove(authorizable.getID());
148143
}
149144

145+
private int prefetchAuthorizable(final Authorizable authorizable) throws RepositoryException {
146+
Objects.requireNonNull(authorizable);
147+
148+
int membershipCount = 0;
149+
String authId = authorizable.getID();
150+
151+
// also cache those groups which are not member of any other group!
152+
Set<String> memberOfByAuthorizableIds = new HashSet<>();
153+
this.isMemberOfByAuthorizableId.put(authId, memberOfByAuthorizableIds);
154+
Iterator<Group> declaredMemberOf = authorizable.declaredMemberOf();
155+
while (declaredMemberOf.hasNext()) {
156+
Group memberOfGroup = declaredMemberOf.next();
157+
String memberOfGroupId = memberOfGroup.getID();
158+
memberOfByAuthorizableIds.add(memberOfGroupId);
159+
nonRegularUserMembersByAuthorizableId.computeIfAbsent(memberOfGroupId, id -> new HashSet<>()).add(authId);
160+
membershipCount++;
161+
}
162+
authorizableIdsAndPaths.put(authorizable.getID(), authorizable.getPath());
163+
return membershipCount;
164+
}
165+
150166
private void removeGroupFromCache(final Group group) throws RepositoryException {
151167
final String groupID = group.getID();
152168
final Iterator<Authorizable> membersIt = group.getDeclaredMembers();

Diff for: accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/helper/QueryHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class QueryHelper {
4646
private static final String ROOT_REP_POLICY_NODE = "/rep:policy";
4747
private static final String ROOT_REPO_POLICY_NODE = "/" + Constants.REPO_POLICY_NODE;
4848
private static final String HOME_REP_POLICY = "/home/rep:policy";
49-
private static final String OAK_INDEX_PATH_REP_ACL = "/oak:index/repACL";
49+
private static final String OAK_INDEX_PATH_REP_ACL = "/oak:index/repACL-custom-1";
5050

5151
/** Method that returns a set containing all rep:policy nodes from repository excluding those contained in paths which are excluded from
5252
* search

0 commit comments

Comments
 (0)