Skip to content

Commit 1c4b417

Browse files
committed
Do not pre-validate restrictions
Oak takes care of that in https://github.com/apache/jackrabbit-oak/blob/17281282fe82d0f0c4e86d0a42ecfb20bfe404e3/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACL.java#L213 as soon as you try to apply those. Otherwise you face exceptions when using restrictions only available at run-time in cloud (but not at build time). This closes #854
1 parent 8fdc6ba commit 1c4b417

File tree

5 files changed

+5
-132
lines changed

5 files changed

+5
-132
lines changed

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceinstaller/BaseAceBeanInstaller.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818

1919
import java.security.Principal;
2020
import java.util.Arrays;
21-
import java.util.Collection;
2221
import java.util.Collections;
2322
import java.util.HashSet;
24-
import java.util.List;
2523
import java.util.Map;
2624
import java.util.Set;
2725
import java.util.TreeSet;
@@ -41,7 +39,6 @@
4139
import biz.netcentric.cq.tools.actool.comparators.AcePermissionComparator;
4240
import biz.netcentric.cq.tools.actool.configmodel.AcConfiguration;
4341
import biz.netcentric.cq.tools.actool.configmodel.AceBean;
44-
import biz.netcentric.cq.tools.actool.configmodel.Restriction;
4542
import biz.netcentric.cq.tools.actool.helper.AccessControlUtils;
4643
import biz.netcentric.cq.tools.actool.helper.ContentHelper;
4744
import biz.netcentric.cq.tools.actool.helper.RestrictionsHolder;
@@ -168,25 +165,15 @@ protected boolean installPrivileges(AceBean aceBean, Principal principal, Jackra
168165
* @throws UnsupportedRepositoryOperationException
169166
* @throws RepositoryException */
170167
protected RestrictionsHolder getRestrictions(AceBean aceBean, Session session, JackrabbitAccessControlList acl)
171-
throws ValueFormatException, UnsupportedRepositoryOperationException, RepositoryException {
172-
173-
final Collection<String> supportedRestrictionNames = Arrays.asList(acl.getRestrictionNames());
168+
throws RepositoryException {
174169

175170
if (aceBean.getRestrictions().isEmpty()) {
176171
return RestrictionsHolder.empty();
177172
}
178-
179-
List<Restriction> restrictions = aceBean.getRestrictions();
180-
for (Restriction restriction : restrictions) {
181-
if (!supportedRestrictionNames.contains(restriction.getName())) {
182-
throw new IllegalStateException(
183-
"The AccessControlList at " + acl.getPath() + " does not support setting " + restriction.getName()
184-
+ " restrictions!");
185-
}
186-
}
187-
188-
RestrictionsHolder restrictionsHolder = new RestrictionsHolder(restrictions, session.getValueFactory(), acl);
189-
return restrictionsHolder;
173+
// no need to check if restrictions are supported, Oak is lenient nowadays and does the proper checks internally
174+
// see https://github.com/apache/jackrabbit-oak/blob/17281282fe82d0f0c4e86d0a42ecfb20bfe404e3/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACL.java#L213
175+
// also it supports non-mandatory restrictions like the ones from com.adobe.cq.dam.assetmetadatarestrictionprovider.impl.AssetMetadataRestrictionProvider
176+
return new RestrictionsHolder(aceBean.getRestrictions(), session.getValueFactory(), acl);
190177
}
191178

192179
/** Converts the given privilege names into a set of privilege objects.

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/validators/exceptions/InvalidRepGlobException.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/validators/exceptions/InvalidRestrictionsException.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/validators/impl/AceBeanValidatorImpl.java

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@
1414
* #L%
1515
*/
1616

17-
import java.util.Arrays;
1817
import java.util.HashSet;
19-
import java.util.List;
2018
import java.util.Set;
2119

22-
import javax.jcr.AccessDeniedException;
23-
import javax.jcr.RepositoryException;
2420
import javax.jcr.security.AccessControlManager;
2521

2622
import org.apache.commons.lang3.StringUtils;
27-
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
2823
import org.slf4j.Logger;
2924
import org.slf4j.LoggerFactory;
3025

3126
import biz.netcentric.cq.tools.actool.aem.AcToolCqActions;
3227
import biz.netcentric.cq.tools.actool.configmodel.AceBean;
33-
import biz.netcentric.cq.tools.actool.configmodel.Restriction;
34-
import biz.netcentric.cq.tools.actool.helper.AccessControlUtils;
3528
import biz.netcentric.cq.tools.actool.validators.AceBeanValidator;
3629
import biz.netcentric.cq.tools.actool.validators.Validators;
3730
import biz.netcentric.cq.tools.actool.validators.exceptions.AcConfigBeanValidationException;
@@ -42,8 +35,6 @@
4235
import biz.netcentric.cq.tools.actool.validators.exceptions.InvalidJcrPrivilegeException;
4336
import biz.netcentric.cq.tools.actool.validators.exceptions.InvalidPathException;
4437
import biz.netcentric.cq.tools.actool.validators.exceptions.InvalidPermissionException;
45-
import biz.netcentric.cq.tools.actool.validators.exceptions.InvalidRepGlobException;
46-
import biz.netcentric.cq.tools.actool.validators.exceptions.InvalidRestrictionsException;
4738
import biz.netcentric.cq.tools.actool.validators.exceptions.NoActionOrPrivilegeDefinedException;
4839
import biz.netcentric.cq.tools.actool.validators.exceptions.NoGroupDefinedException;
4940
import biz.netcentric.cq.tools.actool.validators.exceptions.TooManyActionsException;
@@ -103,8 +94,6 @@ private boolean validate(AccessControlManager aclManager) throws AcConfigBeanVal
10394
throw new NoActionOrPrivilegeDefinedException(errorMessage);
10495
}
10596

106-
validateRestrictions(this.aceBean, aclManager);
107-
10897
return true;
10998
}
11099

@@ -117,60 +106,6 @@ private void maintainBeanCounter() {
117106
previousAuthorizableId = aceBean.getAuthorizableId();
118107
}
119108

120-
private boolean validateRestrictions(final AceBean tmpAceBean, final AccessControlManager aclManager)
121-
throws InvalidRepGlobException, InvalidRestrictionsException {
122-
boolean valid = true;
123-
124-
final List<Restriction> restrictions = tmpAceBean.getRestrictions();
125-
if (restrictions.isEmpty()) {
126-
return true;
127-
}
128-
129-
final Set<String> restrictionNamesFromAceBean = new HashSet<String>();
130-
for (Restriction restriction : restrictions) {
131-
restrictionNamesFromAceBean.add(restriction.getName());
132-
}
133-
134-
final Set<String> allowedRestrictionNames = getSupportedRestrictions(aclManager);
135-
136-
if (!allowedRestrictionNames.containsAll(restrictionNamesFromAceBean)) {
137-
restrictionNamesFromAceBean.removeAll(allowedRestrictionNames);
138-
valid = false;
139-
final String errorMessage = getBeanDescription(this.currentBeanCounter,
140-
tmpAceBean.getAuthorizableId())
141-
+ ", this repository doesn't support following restriction(s): "
142-
+ restrictionNamesFromAceBean;
143-
throw new InvalidRestrictionsException(errorMessage);
144-
}
145-
146-
return valid;
147-
}
148-
149-
private Set<String> getSupportedRestrictions(final AccessControlManager aclManager)
150-
throws InvalidRepGlobException {
151-
Set<String> allowedRestrictions = new HashSet<>();
152-
try {
153-
final JackrabbitAccessControlList jacl = getJackrabbitAccessControlList(aclManager);
154-
allowedRestrictions = new HashSet<>(Arrays.asList(jacl.getRestrictionNames()));
155-
} catch (final RepositoryException e) {
156-
throw new InvalidRepGlobException("Could not get restriction names from ACL of path: " + this.aceBean.getJcrPath());
157-
}
158-
return allowedRestrictions;
159-
}
160-
161-
private JackrabbitAccessControlList getJackrabbitAccessControlList(final AccessControlManager aclManager) throws RepositoryException, AccessDeniedException {
162-
JackrabbitAccessControlList jacl = null;
163-
// don't check paths containing wildcards
164-
if(!this.aceBean.getJcrPath().contains("*")){
165-
jacl = AccessControlUtils.getModifiableAcl(aclManager, this.aceBean.getJcrPath());
166-
}
167-
if(jacl == null){
168-
// root as fallback
169-
jacl = AccessControlUtils.getModifiableAcl(aclManager, "/");
170-
}
171-
return jacl;
172-
}
173-
174109
private boolean validatePermission(final AceBean tmpAclBean) throws InvalidPermissionException {
175110

176111
final String permission = tmpAclBean.getPermission();

accesscontroltool-bundle/src/test/resources/testconfig.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,12 @@
285285
rep:glob: test
286286
rep:ntNames: test
287287
rep:prefixes: test
288-
assertedException: InvalidRestrictionsException
289288

290289
#11 wrong restriction name. correct one would be rep:glob
291290
- path: /content
292291
permission: allow
293292
actions: read
294293
restrictions:
295294
rep:Glob: /cq:*
296-
assertedException: InvalidRestrictionsException
297-
298295

299296

0 commit comments

Comments
 (0)