Search in sources :

Example 46 with PrincipalImpl

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

the class UserManagementTest method testCreateWithIntermediateReadDeny2.

@Test
public void testCreateWithIntermediateReadDeny2() throws Exception {
    String path = UserConstants.DEFAULT_GROUP_PATH + "/a";
    JcrUtils.getOrCreateByPath(path, UserConstants.NT_REP_AUTHORIZABLE_FOLDER, superuser);
    superuser.save();
    try {
        deny(UserConstants.DEFAULT_GROUP_PATH, privilegesFromName(Privilege.JCR_READ));
        Privilege[] privs = privilegesFromNames(new String[] { Privilege.JCR_READ, PrivilegeConstants.REP_USER_MANAGEMENT, PrivilegeConstants.REP_WRITE });
        allow(path, privs);
        Group gr = getUserManager(testSession).createGroup(groupId, new PrincipalImpl(groupId), "a/b/c");
        testSession.save();
    } finally {
        superuser.refresh(false);
        superuser.getNode(UserConstants.DEFAULT_GROUP_PATH + "/a").remove();
        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, UserConstants.DEFAULT_GROUP_PATH);
        if (acl != null) {
            acMgr.removePolicy(UserConstants.DEFAULT_GROUP_PATH, acl);
        }
        superuser.save();
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 47 with PrincipalImpl

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

the class MemberBaseTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    super.beforeSuite();
    Session s = loginAdministrative();
    try {
        List<String> memberIds = new ArrayList<String>(numberOfMembers);
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        for (int i = 0; i <= numberOfMembers; i++) {
            User u = userManager.createUser(USER + i, null, new PrincipalImpl(USER + i), REL_TEST_PATH);
            memberPaths.add(u.getPath());
            memberIds.add(USER + i);
        }
        String[] idArray = memberIds.toArray(new String[memberIds.size()]);
        for (int i = 0, j = 1; i <= numberOfGroups; i++, j++) {
            Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), REL_TEST_PATH);
            groupPaths.add(g.getPath());
            if (nested) {
                g.addMembers(ObjectArrays.concat(idArray, GROUP + j));
            } else {
                g.addMembers(idArray);
            }
        }
    } finally {
        s.save();
        s.logout();
    }
    System.out.println("setup done");
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ArrayList(java.util.ArrayList) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 48 with PrincipalImpl

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

the class RemoveMemberTest method createUsers.

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 49 with PrincipalImpl

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

the class UserManagerImpl method createSystemUser.

@Override
public User createSystemUser(String userID, String intermediatePath) throws RepositoryException {
    checkValidId(userID);
    Principal principal = new PrincipalImpl(userID);
    checkValidPrincipal(principal, false);
    Tree userTree = userProvider.createSystemUser(userID, intermediatePath);
    setPrincipal(userTree, principal);
    User user = new SystemUserImpl(userID, userTree, this);
    log.debug("System user created: " + userID);
    return user;
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Tree(org.apache.jackrabbit.oak.api.Tree) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)

Example 50 with PrincipalImpl

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

the class UserPrincipalProvider method getPrincipal.

//--------------------------------------------------< PrincipalProvider >---
@Override
public Principal getPrincipal(@Nonnull String principalName) {
    Tree authorizableTree = userProvider.getAuthorizableByPrincipal(new PrincipalImpl(principalName));
    Principal principal = createPrincipal(authorizableTree);
    if (principal == null) {
        // no such principal or error while accessing principal from user/group
        return (EveryonePrincipal.NAME.equals(principalName)) ? EveryonePrincipal.getInstance() : null;
    } else {
        return principal;
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) SystemPrincipal(org.apache.jackrabbit.oak.spi.security.principal.SystemPrincipal) Principal(java.security.Principal)

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