use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlManagerImplTest method testGetPolicesAfterSetPoliciesCall.
/**
* Tests the binding state of a policy.
* @throws Exception
*/
public void testGetPolicesAfterSetPoliciesCall() throws Exception {
try {
AccessControlPolicyIterator policies = acMgr.getApplicablePolicies(testRoot);
AccessControlPolicy policy = null;
while (policies.hasNext()) {
policy = policies.nextAccessControlPolicy();
acMgr.setPolicy(testRoot, policy);
AccessControlPolicy[] acl = acMgr.getPolicies(testRoot);
assertNotNull(acl);
}
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlImporterTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
if (!(superuser instanceof SessionImpl)) {
throw new NotExecutableException("SessionImpl expected");
}
sImpl = (SessionImpl) superuser;
// make sure the repository provides resource based policies.
AccessControlPolicyIterator it = sImpl.getAccessControlManager().getApplicablePolicies("/");
if (!it.hasNext()) {
AccessControlPolicy[] pcs = sImpl.getAccessControlManager().getPolicies("/");
if (pcs == null || pcs.length == 0) {
throw new NotExecutableException();
}
}
// ok resource based acl
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlAction method setAC.
// ------------------------------------------------------------< private >---
private void setAC(Authorizable authorizable, Session session) throws RepositoryException {
Node aNode;
String path = authorizable.getPath();
JackrabbitAccessControlList acl = null;
AccessControlManager acMgr = session.getAccessControlManager();
for (AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path); it.hasNext(); ) {
AccessControlPolicy plc = it.nextAccessControlPolicy();
if (plc instanceof JackrabbitAccessControlList) {
acl = (JackrabbitAccessControlList) plc;
break;
}
}
if (acl == null) {
log.warn("Cannot process AccessControlAction: no applicable ACL at " + path);
} else {
// setup acl according to configuration.
Principal principal = new UnknownPrincipal(authorizable.getPrincipal().getName());
boolean modified = false;
if (authorizable.isGroup()) {
// new authorizable is a Group
if (groupPrivilegeNames.length > 0) {
modified = acl.addAccessControlEntry(principal, getPrivileges(groupPrivilegeNames, acMgr));
}
} else {
// new authorizable is a User
if (userPrivilegeNames.length > 0) {
modified = acl.addAccessControlEntry(principal, getPrivileges(userPrivilegeNames, acMgr));
}
}
if (modified) {
acMgr.setPolicy(path, acl);
}
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project pentaho-platform by pentaho.
the class JcrRepositoryFileAclDao method getAccessControlList.
private AccessControlList getAccessControlList(final AccessControlManager acMgr, final String path) throws RepositoryException {
AccessControlPolicyIterator applicablePolicies = acMgr.getApplicablePolicies(path);
while (applicablePolicies.hasNext()) {
AccessControlPolicy policy = applicablePolicies.nextAccessControlPolicy();
if (policy instanceof AccessControlList) {
return (AccessControlList) policy;
}
}
AccessControlPolicy[] policies = acMgr.getPolicies(path);
for (int i = 0; i < policies.length; i++) {
if (policies[i] instanceof AccessControlList) {
return (AccessControlList) policies[i];
}
}
throw new IllegalStateException("no access control list applies or is bound to node");
}
Aggregations