use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit by apache.
the class ACLEditor method editAccessControlPolicies.
/**
* @see AccessControlEditor#editAccessControlPolicies(String)
*/
public AccessControlPolicy[] editAccessControlPolicies(String nodePath) throws AccessControlException, PathNotFoundException, RepositoryException {
checkProtectsNode(nodePath);
String mixin;
Name aclName;
NodeImpl controlledNode;
if (nodePath == null) {
controlledNode = (NodeImpl) session.getRootNode();
mixin = session.getJCRName(NT_REP_REPO_ACCESS_CONTROLLABLE);
aclName = N_REPO_POLICY;
} else {
controlledNode = getNode(nodePath);
mixin = session.getJCRName(NT_REP_ACCESS_CONTROLLABLE);
aclName = N_POLICY;
}
AccessControlPolicy acl = null;
NodeImpl aclNode = getAclNode(controlledNode, nodePath);
if (aclNode == null) {
// has colliding rep:policy or rep:repoPolicy child node set.
if (controlledNode.hasNode(aclName)) {
// policy child node without node being access controlled
log.warn("Colliding policy child without node being access controllable ({}).", nodePath);
} else {
PrivilegeManager privMgr = ((JackrabbitWorkspace) session.getWorkspace()).getPrivilegeManager();
if (controlledNode.isNodeType(mixin) || controlledNode.canAddMixin(mixin)) {
acl = new ACLTemplate(nodePath, session.getPrincipalManager(), privMgr, session.getValueFactory(), session, allowUnknownPrincipals);
} else {
log.warn("Node {} cannot be made access controllable.", nodePath);
}
}
}
return (acl != null) ? new AccessControlPolicy[] { acl } : new AccessControlPolicy[0];
}
use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.
the class AccessControlValidatorProvider method getRootValidator.
//--------------------------------------------------< ValidatorProvider >---
@Nonnull
@Override
public Validator getRootValidator(NodeState before, NodeState after, CommitInfo info) {
RestrictionProvider restrictionProvider = getConfig(AuthorizationConfiguration.class).getRestrictionProvider();
Root root = RootFactory.createReadOnlyRoot(before);
PrivilegeManager privilegeManager = getConfig(PrivilegeConfiguration.class).getPrivilegeManager(root, NamePathMapper.DEFAULT);
PrivilegeBitsProvider privilegeBitsProvider = new PrivilegeBitsProvider(root);
return new AccessControlValidator(after, privilegeManager, privilegeBitsProvider, restrictionProvider);
}
use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.
the class AbstractSecurityTest method privilegesFromNames.
protected Privilege[] privilegesFromNames(Iterable<String> privilegeNames) throws RepositoryException {
PrivilegeManager manager = getPrivilegeManager(root);
List<Privilege> privs = newArrayList();
for (String name : privilegeNames) {
privs.add(manager.getPrivilege(name));
}
return privs.toArray(new Privilege[privs.size()]);
}
use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.
the class JcrAllTest method testAllAggregation.
@Test
public void testAllAggregation() throws Exception {
PrivilegeBits all = bitsProvider.getBits(JCR_ALL);
PrivilegeManager pMgr = getSecurityProvider().getConfiguration(PrivilegeConfiguration.class).getPrivilegeManager(root, NamePathMapper.DEFAULT);
Iterable<Privilege> declaredAggr = Arrays.asList(pMgr.getPrivilege(JCR_ALL).getDeclaredAggregatePrivileges());
String[] allAggregates = Iterables.toArray(Iterables.transform(declaredAggr, new Function<Privilege, String>() {
@Override
public String apply(@Nullable Privilege privilege) {
return checkNotNull(privilege).getName();
}
}), String.class);
PrivilegeBits all2 = bitsProvider.getBits(allAggregates);
assertEquals(all, all2);
assertEquals(Collections.singleton(JCR_ALL), bitsProvider.getPrivilegeNames(all2));
PrivilegeBits bits = PrivilegeBits.getInstance();
for (String name : allAggregates) {
bits.add(bitsProvider.getBits(name));
}
assertEquals(all, bits.unmodifiable());
}
use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.
the class PrivilegeConfigurationImplTest method testGetPrivilegeManager.
@Test
public void testGetPrivilegeManager() {
PrivilegeManager pMgr = configuration.getPrivilegeManager(Mockito.mock(Root.class), NamePathMapper.DEFAULT);
assertTrue(pMgr instanceof PrivilegeManagerImpl);
}
Aggregations