Search in sources :

Example 66 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class AccessControlManagerImpl method getPrincipal.

@Nonnull
private Principal getPrincipal(@Nonnull Tree aceTree) {
    String principalName = checkNotNull(TreeUtil.getString(aceTree, REP_PRINCIPAL_NAME));
    Principal principal = principalManager.getPrincipal(principalName);
    if (principal == null) {
        log.debug("Unknown principal " + principalName);
        principal = new PrincipalImpl(principalName);
    }
    return principal;
}
Also used : ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Nonnull(javax.annotation.Nonnull)

Example 67 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class AdminPrincipalsBaseTest method before.

@Override
public void before() throws Exception {
    super.before();
    NodeUtil rootNode = new NodeUtil(root.getTree("/"), NamePathMapper.DEFAULT);
    rootNode.addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
    administrativePrincipal = getUserManager(root).createGroup(new PrincipalImpl(ADMINISTRATORS_PRINCIPAL_NAME)).getPrincipal();
    root.commit();
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlPolicyIterator itr = acMgr.getApplicablePolicies("/testNode");
    while (itr.hasNext() && acl == null) {
        AccessControlPolicy policy = itr.nextAccessControlPolicy();
        if (policy instanceof AccessControlList) {
            acl = (AccessControlList) policy;
        }
    }
    if (acl == null) {
        throw new RepositoryException("No applicable policy found.");
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) RepositoryException(javax.jcr.RepositoryException) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil)

Example 68 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ACLTest method testInternalPrincipal.

@Test
public void testInternalPrincipal() throws RepositoryException {
    Principal internal = new PrincipalImpl("unknown");
    acl.addAccessControlEntry(internal, privilegesFromNames(JCR_READ));
}
Also used : Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 69 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ACLTest method testAddEntriesWithCustomPrincipal.

@Test
public void testAddEntriesWithCustomPrincipal() throws Exception {
    Principal oakPrincipal = new PrincipalImpl("anonymous");
    Principal principal = new Principal() {

        @Override
        public String getName() {
            return "anonymous";
        }
    };
    assertTrue(acl.addAccessControlEntry(oakPrincipal, privilegesFromNames(JCR_READ)));
    assertTrue(acl.addAccessControlEntry(principal, privilegesFromNames(JCR_READ_ACCESS_CONTROL)));
    assertEquals(1, acl.getAccessControlEntries().length);
    assertTrue(acl.addEntry(principal, privilegesFromNames(JCR_READ), false));
    assertEquals(2, acl.getAccessControlEntries().length);
    assertArrayEquals(privilegesFromNames(JCR_READ_ACCESS_CONTROL), acl.getAccessControlEntries()[0].getPrivileges());
}
Also used : Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 70 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ACLTest method testEmptyPrincipal.

@Test
public void testEmptyPrincipal() throws Exception {
    try {
        acl.addAccessControlEntry(new PrincipalImpl(""), privilegesFromNames(JCR_READ));
        fail("Adding an ACE with empty-named principal should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Aggregations

PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)87 Test (org.junit.Test)59 Principal (java.security.Principal)39 Group (org.apache.jackrabbit.api.security.user.Group)23 User (org.apache.jackrabbit.api.security.user.User)20 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)20 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)19 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)15 UserManager (org.apache.jackrabbit.api.security.user.UserManager)14 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)11 Session (javax.jcr.Session)8 SimpleCredentials (javax.jcr.SimpleCredentials)7 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)6 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)6 CugPolicy (org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy)6 HashSet (java.util.HashSet)5 Nonnull (javax.annotation.Nonnull)4 SystemPrincipal (org.apache.jackrabbit.oak.spi.security.principal.SystemPrincipal)4 ArrayList (java.util.ArrayList)3 AccessControlList (javax.jcr.security.AccessControlList)3