Search in sources :

Example 16 with PrincipalImpl

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

the class GetGroupPrincipalsTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    super.beforeSuite();
    session = loginAdministrative();
    UserManager userManager = ((JackrabbitSession) session).getUserManager();
    Authorizable user = userManager.getAuthorizable(USER);
    if (user == null) {
        user = userManager.createUser(USER, USER);
        principalName = user.getPrincipal().getName();
    }
    // make sure we have a least a single group the user is member of.
    Group gr = userManager.createGroup(new PrincipalImpl(GROUP), "test");
    gr.addMember(user);
    for (int i = 1; i < numberOfGroups; i++) {
        Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), "test");
        if (!nestedGroups) {
            g.addMember(user);
        } else {
            g.addMember(gr);
        }
        gr = g;
    }
    session.save();
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)

Example 17 with PrincipalImpl

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

the class AddMemberTest method createUsers.

@Override
protected void createUsers(@Nonnull UserManager userManager) throws Exception {
    for (int i = 0; i <= numberOfMembers; i++) {
        String id = USER + i;
        User u = userManager.createUser(id, null, new PrincipalImpl(id), REL_TEST_PATH);
        userPaths.add(u.getPath());
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)

Example 18 with PrincipalImpl

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

the class AddMembersTest method createUsers.

protected void createUsers(@Nonnull UserManager userManager) throws Exception {
    if (!ImportBehavior.NAME_BESTEFFORT.equals(importBehavior)) {
        for (int i = 0; i <= numberOfMembers; i++) {
            String id = USER + i;
            userManager.createUser(id, null, new PrincipalImpl(id), REL_TEST_PATH);
        }
    }
}
Also used : PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)

Example 19 with PrincipalImpl

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

the class UserManagerImplTest method testEnforceAuthorizableFolderHierarchy.

@Test
public void testEnforceAuthorizableFolderHierarchy() throws RepositoryException, CommitFailedException {
    User user = userMgr.createUser(testUserId, null);
    root.commit();
    NodeUtil userNode = new NodeUtil(root.getTree(user.getPath()));
    NodeUtil folder = userNode.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
    String path = folder.getTree().getPath();
    // authNode - authFolder -> create User
    try {
        Principal p = new PrincipalImpl("test2");
        userMgr.createUser(p.getName(), p.getName(), p, path);
        root.commit();
        fail("Users may not be nested.");
    } catch (CommitFailedException e) {
    // success
    } finally {
        Authorizable a = userMgr.getAuthorizable("test2");
        if (a != null) {
            a.remove();
            root.commit();
        }
    }
    NodeUtil someContent = userNode.addChild("mystuff", JcrConstants.NT_UNSTRUCTURED);
    path = someContent.getTree().getPath();
    try {
        // authNode - anyNode -> create User
        try {
            Principal p = new PrincipalImpl("test3");
            userMgr.createUser(p.getName(), p.getName(), p, path);
            root.commit();
            fail("Users may not be nested.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            Authorizable a = userMgr.getAuthorizable("test3");
            if (a != null) {
                a.remove();
                root.commit();
            }
        }
        // authNode - anyNode - authFolder -> create User
        folder = someContent.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
        // this time save node structure
        root.commit();
        try {
            Principal p = new PrincipalImpl("test4");
            userMgr.createUser(p.getName(), p.getName(), p, folder.getTree().getPath());
            root.commit();
            fail("Users may not be nested.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            root.refresh();
            Authorizable a = userMgr.getAuthorizable("test4");
            if (a != null) {
                a.remove();
                root.commit();
            }
        }
    } finally {
        root.refresh();
        Tree t = root.getTree(path);
        if (t.exists()) {
            t.remove();
            root.commit();
        }
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 20 with PrincipalImpl

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

the class L3_UserVsPrincipalTest method testAccessControlEntryWithId.

@Test
public void testAccessControlEntryWithId() throws RepositoryException {
    AccessControlManager acMgr = getAccessControlManager(root);
    // EXERCISE fix the test case
    String[] ids = new String[] { testId, testGroupId };
    for (String id : ids) {
        AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/");
        acl.addAccessControlEntry(new PrincipalImpl(id), AccessControlUtils.privilegesFromNames(acMgr, PrivilegeConstants.JCR_READ));
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test) L2_AuthInfoTest(org.apache.jackrabbit.oak.exercise.security.authentication.L2_AuthInfoTest)

Aggregations

PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)96 Test (org.junit.Test)66 Principal (java.security.Principal)40 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)24 Group (org.apache.jackrabbit.api.security.user.Group)22 User (org.apache.jackrabbit.api.security.user.User)20 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)20 UserManager (org.apache.jackrabbit.api.security.user.UserManager)16 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)15 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)12 GroupPrincipal (org.apache.jackrabbit.api.security.principal.GroupPrincipal)11 Session (javax.jcr.Session)9 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 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)5 AuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration)5 EmptyPermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.EmptyPermissionProvider)5