Search in sources :

Example 46 with UserManager

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

the class SyncMBeanImplTest method testInitialSyncExternalUsers.

@Test
public void testInitialSyncExternalUsers() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER);
    String[] externalId = new String[] { externalUser.getExternalId().getString() };
    String[] result = syncMBean.syncExternalUsers(externalId);
    assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "add");
    UserManager userManager = getUserManager();
    User testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    assertNotNull(testUser);
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        assertNotNull(userManager.getAuthorizable(groupRef.getId()));
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 47 with UserManager

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

the class UserManagerImplTest method testCleanup.

public void testCleanup() throws RepositoryException, NotExecutableException {
    Session s = getHelper().getSuperuserSession();
    try {
        UserManager umgr = getUserManager(s);
        s.logout();
        // any more -> accessing users must fail.
        try {
            umgr.getAuthorizable("any userid");
            fail("After having logged out the original session, the user manager must not be live any more.");
        } catch (RepositoryException e) {
        // success
        }
    } finally {
        if (s.isLive()) {
            s.logout();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 48 with UserManager

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

the class UserManagerImplTest method testCleanupForAllWorkspaces.

public void testCleanupForAllWorkspaces() throws RepositoryException, NotExecutableException {
    String[] workspaceNames = superuser.getWorkspace().getAccessibleWorkspaceNames();
    for (String workspaceName1 : workspaceNames) {
        Session s = getHelper().getSuperuserSession(workspaceName1);
        try {
            UserManager umgr = getUserManager(s);
            s.logout();
            // any more -> accessing users must fail.
            try {
                umgr.getAuthorizable("any userid");
                fail("After having logged out the original session, the user manager must not be live any more.");
            } catch (RepositoryException e) {
            // success
            }
        } finally {
            if (s.isLive()) {
                s.logout();
            }
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 49 with UserManager

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

the class WriteTest method testEditor2.

public void testEditor2() throws NotExecutableException, RepositoryException {
    UserManager uMgr = getUserManager(superuser);
    User u = null;
    User u2 = null;
    try {
        u = uMgr.createUser("t", "t");
        u2 = uMgr.createUser("tt", "tt", new TestPrincipal("tt"), "t/tt");
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        Principal p = u.getPrincipal();
        Principal p2 = u2.getPrincipal();
        if (p instanceof ItemBasedPrincipal && p2 instanceof ItemBasedPrincipal && Text.isDescendant(((ItemBasedPrincipal) p).getPath(), ((ItemBasedPrincipal) p2).getPath())) {
            JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
            JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p2);
            acMgr.setPolicy(acls[0].getPath(), acls[0]);
            acls = acMgr.getApplicablePolicies(p);
            String path = acls[0].getPath();
            Node n = superuser.getNode(path);
            assertEquals("rep:PrincipalAccessControl", n.getPrimaryNodeType().getName());
        } else {
            throw new NotExecutableException();
        }
    } finally {
        superuser.refresh(false);
        if (u2 != null)
            u2.remove();
        if (u != null)
            u.remove();
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) User(org.apache.jackrabbit.api.security.user.User) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Node(javax.jcr.Node) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 50 with UserManager

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

the class WriteTest method testEditor.

public void testEditor() throws NotExecutableException, RepositoryException {
    UserManager uMgr = getUserManager(superuser);
    User u = null;
    try {
        u = uMgr.createUser("t", "t");
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        Principal p = u.getPrincipal();
        JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
        JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p);
        assertEquals(1, acls.length);
        assertTrue(acls[0] instanceof ACLTemplate);
        // access again
        acls = acMgr.getApplicablePolicies(p);
        assertEquals(1, acls.length);
        assertEquals(1, acMgr.getApplicablePolicies(acls[0].getPath()).getSize());
        assertEquals(0, acMgr.getPolicies(p).length);
        assertEquals(0, acMgr.getPolicies(acls[0].getPath()).length);
        acMgr.setPolicy(acls[0].getPath(), acls[0]);
        assertEquals(0, acMgr.getApplicablePolicies(p).length);
        assertEquals(1, acMgr.getPolicies(p).length);
        assertEquals(1, acMgr.getPolicies(acls[0].getPath()).length);
    } finally {
        superuser.refresh(false);
        if (u != null) {
            u.remove();
            if (!uMgr.isAutoSave()) {
                superuser.save();
            }
        }
    }
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

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