Search in sources :

Example 81 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class GroupImportTest method testImportGroupMembersFromNodes.

@Test
public void testImportGroupMembersFromNodes() throws Exception {
    List<String> createdUsers = new LinkedList<String>();
    Session s = getImportSession();
    UserManager uMgr = getUserManager();
    try {
        String[] users = { "angi", "adi", "hansi", "lisi", "luzi", "susi", "pipi", "hari", "gabi", "eddi", "debbi", "cati", "admin", "anonymous" };
        for (String user : users) {
            if (uMgr.getAuthorizable(user) == null) {
                uMgr.createUser(user, user);
                createdUsers.add(user);
            }
        }
        if (!uMgr.isAutoSave()) {
            s.save();
        }
        doImport(getTargetPath(), "GroupImportTest-testImportGroupMembersFromNodes.xml");
        if (!uMgr.isAutoSave()) {
            s.save();
        }
        Authorizable aShrimps = uMgr.getAuthorizable("shrimps");
        assertNotNull("Shrimps authorizable must exist", aShrimps);
        assertTrue("Shrimps authorizable must be a group", aShrimps.isGroup());
        Group gShrimps = (Group) aShrimps;
        for (String user : users) {
            assertTrue(user + " should be member of " + gShrimps, gShrimps.isMember(uMgr.getAuthorizable(user)));
        }
    } finally {
        for (String user : createdUsers) {
            Authorizable a = uMgr.getAuthorizable(user);
            if (a != null && !a.isGroup()) {
                a.remove();
            }
        }
        for (NodeIterator it = s.getNode(getTargetPath()).getNodes(); it.hasNext(); ) {
            Node n = it.nextNode();
            if (!n.getDefinition().isProtected()) {
                n.remove();
            }
        }
        s.save();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) LinkedList(java.util.LinkedList) Session(javax.jcr.Session) Test(org.junit.Test)

Example 82 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserInitializerTest method testAnonymousConfiguration.

/**
     * @since OAK 1.0 The anonymous user is optional.
     */
@Test
public void testAnonymousConfiguration() throws Exception {
    Map<String, Object> userParams = new HashMap();
    userParams.put(UserConstants.PARAM_ANONYMOUS_ID, "");
    ConfigurationParameters params = ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams));
    SecurityProvider sp = new SecurityProviderImpl(params);
    final ContentRepository repo = new Oak().with(new InitialContent()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(sp).createContentRepository();
    ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

        @Override
        public ContentSession run() throws Exception {
            return repo.login(null, null);
        }
    });
    try {
        Root root = cs.getLatestRoot();
        UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
        UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
        Authorizable anonymous = umgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
        assertNull(anonymous);
    } finally {
        cs.close();
    }
    // login as admin should fail
    ContentSession anonymousSession = null;
    try {
        anonymousSession = repo.login(new GuestCredentials(), null);
        fail();
    } catch (LoginException e) {
    //success
    } finally {
        if (anonymousSession != null) {
            anonymousSession.close();
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) HashMap(java.util.HashMap) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) LoginException(javax.security.auth.login.LoginException) InitialContent(org.apache.jackrabbit.oak.InitialContent) PropertyIndexProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) UserManager(org.apache.jackrabbit.api.security.user.UserManager) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) LoginException(javax.security.auth.login.LoginException) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) GuestCredentials(javax.jcr.GuestCredentials) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 83 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserValidatorTest method testRemoveAdminUser.

@Test
public void testRemoveAdminUser() throws Exception {
    try {
        String adminId = getConfig().getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
        UserManager userMgr = getUserManager(root);
        Authorizable admin = userMgr.getAuthorizable(adminId);
        if (admin == null) {
            admin = userMgr.createUser(adminId, adminId);
            root.commit();
        }
        root.getTree(admin.getPath()).remove();
        root.commit();
        fail("Admin user cannot be removed");
    } catch (CommitFailedException e) {
    // success
    } finally {
        root.refresh();
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 84 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class AccessControlActionTest method testAccessControlAction.

@Test
public void testAccessControlAction() throws Exception {
    UserManager userMgr = getUserManager(root);
    Group gr = null;
    try {
        gr = userMgr.createGroup("actionTestGroup");
        root.commit();
        assertAcAction(gr, PrivilegeConstants.JCR_READ);
    } finally {
        root.refresh();
        if (gr != null) {
            gr.remove();
        }
        root.commit();
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 85 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserValidatorTest method testRemoveAdminUserFolder.

@Test
public void testRemoveAdminUserFolder() throws Exception {
    try {
        String adminId = getConfig().getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
        UserManager userMgr = getUserManager(root);
        Authorizable admin = userMgr.getAuthorizable(adminId);
        if (admin == null) {
            admin = userMgr.createUser(adminId, adminId);
            root.commit();
        }
        root.getTree(admin.getPath()).getParent().remove();
        root.commit();
        fail("Admin user cannot be removed");
    } catch (CommitFailedException e) {
    // success
    } finally {
        root.refresh();
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

UserManager (org.apache.jackrabbit.api.security.user.UserManager)234 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)93 Test (org.junit.Test)90 Group (org.apache.jackrabbit.api.security.user.Group)81 User (org.apache.jackrabbit.api.security.user.User)72 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)52 Session (javax.jcr.Session)45 RepositoryException (javax.jcr.RepositoryException)40 Principal (java.security.Principal)38 SimpleCredentials (javax.jcr.SimpleCredentials)34 AccessDeniedException (javax.jcr.AccessDeniedException)19 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)19 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Node (javax.jcr.Node)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)14 Value (javax.jcr.Value)11 Root (org.apache.jackrabbit.oak.api.Root)11 AccessControlManager (javax.jcr.security.AccessControlManager)9 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)9