Search in sources :

Example 86 with Authorizable

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

the class AdministratorTest method testAdminNodeCollidingWithAuthorizableFolder.

/**
     * Test for collisions that would prevent from recreate the admin user.
     * - an intermediate rep:AuthorizableFolder node with the same name
     */
public void testAdminNodeCollidingWithAuthorizableFolder() throws RepositoryException, NotExecutableException {
    Authorizable admin = userMgr.getAuthorizable(adminId);
    if (admin == null || !(admin instanceof AuthorizableImpl)) {
        throw new NotExecutableException();
    }
    // access the node corresponding to the admin user and remove it
    NodeImpl adminNode = ((AuthorizableImpl) admin).getNode();
    String adminPath = adminNode.getPath();
    String adminNodeName = adminNode.getName();
    Node parentNode = adminNode.getParent();
    Session s = adminNode.getSession();
    adminNode.remove();
    // use session obtained from the node as usermgr may point to a dedicated
    // system workspace different from the superusers workspace.
    s.save();
    Session s2 = null;
    String collidingPath = null;
    try {
        // now create a colliding node:
        Node n = parentNode.addNode(adminNodeName, "rep:AuthorizableFolder");
        collidingPath = n.getPath();
        s.save();
        // force recreation of admin user.
        s2 = getHelper().getSuperuserSession();
        admin = userMgr.getAuthorizable(adminId);
        assertNotNull(admin);
        assertEquals(adminNodeName, ((AuthorizableImpl) admin).getNode().getName());
        assertFalse(adminPath.equals(((AuthorizableImpl) admin).getNode().getPath()));
    } finally {
        if (s2 != null) {
            s2.logout();
        }
        // remove the extra folder and the admin user (created underneath) again.
        if (collidingPath != null) {
            s.getNode(collidingPath).remove();
            s.save();
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeImpl(org.apache.jackrabbit.core.NodeImpl) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Session(javax.jcr.Session)

Example 87 with Authorizable

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

the class DefaultPrincipalProviderTest method testPrincipalCache.

/**
     * Test if cache is properly updated.
     * 
     * @throws Exception
     */
public void testPrincipalCache() throws Exception {
    Principal testPrincipal = getTestPrincipal();
    String testName = testPrincipal.getName();
    assertNull(principalProvider.getPrincipal(testName));
    // create a user with the given principal name -> cache must be updated.
    Authorizable a = userMgr.createUser(testName, "pw");
    save(superuser);
    try {
        assertNotNull(principalProvider.getPrincipal(testName));
    } finally {
        a.remove();
        save(superuser);
    }
    // after removal -> entry must be removed from the cache.
    assertNull(principalProvider.getPrincipal(testName));
    // create a group with that name
    a = userMgr.createGroup(testPrincipal);
    save(superuser);
    try {
        Principal p = principalProvider.getPrincipal(testName);
        assertNotNull(p);
        assertTrue(p instanceof java.security.acl.Group);
    } finally {
        a.remove();
        save(superuser);
    }
    // recreate user again without filling cache with 'null' value
    a = userMgr.createUser(testName, "pw");
    save(superuser);
    try {
        Principal p = principalProvider.getPrincipal(testName);
        assertNotNull(p);
        assertFalse(p instanceof java.security.acl.Group);
    } finally {
        a.remove();
        save(superuser);
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 88 with Authorizable

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

the class GroupAdministratorTest method testRemoveMembershipForOwnAuthorizable.

public void testRemoveMembershipForOwnAuthorizable() throws RepositoryException, NotExecutableException {
    UserManager umgr = getUserManager(uSession);
    Authorizable user = umgr.getAuthorizable(uID);
    Group gr = (Group) umgr.getAuthorizable(groupAdmin.getID());
    // removing himself from group. should succeed.
    assertTrue(gr.removeMember(user));
}
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)

Example 89 with Authorizable

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

the class GroupAdministratorTest method tearDown.

protected void tearDown() throws Exception {
    try {
        if (uSession != null) {
            uSession.logout();
        }
    } finally {
        // remove group member ship
        groupAdmin.removeMember(userMgr.getAuthorizable(uID));
        // remove all users that have been created
        Authorizable a = userMgr.getAuthorizable(otherUID);
        if (a != null) {
            a.remove();
        }
        save(superuser);
    }
    super.tearDown();
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 90 with Authorizable

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

the class DefaultSyncContextTest method testSyncProperties.

@Test
public void testSyncProperties() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    Authorizable a = syncCtx.createUser(externalUser);
    // create exact mapping
    Map<String, String> mapping = new HashMap();
    Map<String, ?> extProps = externalUser.getProperties();
    for (String propName : extProps.keySet()) {
        mapping.put(propName, propName);
    }
    syncCtx.syncProperties(externalUser, a, mapping);
    for (String propName : extProps.keySet()) {
        assertTrue(a.hasProperty(propName));
        Object obj = extProps.get(propName);
        Value[] vs = a.getProperty(propName);
        if (vs.length == 1) {
            assertEquals(syncCtx.createValue(obj), a.getProperty(propName)[0]);
        } else {
            Value[] expected = (obj instanceof Collection) ? syncCtx.createValues((Collection) obj) : syncCtx.createValues(Arrays.asList((Object[]) obj));
            assertArrayEquals(expected, a.getProperty(propName));
        }
    }
}
Also used : HashMap(java.util.HashMap) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Collection(java.util.Collection) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)466 Test (org.junit.Test)254 User (org.apache.jackrabbit.api.security.user.User)104 Group (org.apache.jackrabbit.api.security.user.Group)101 UserManager (org.apache.jackrabbit.api.security.user.UserManager)93 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)64 Principal (java.security.Principal)58 Node (javax.jcr.Node)55 RepositoryException (javax.jcr.RepositoryException)55 Query (org.apache.jackrabbit.api.security.user.Query)50 Session (javax.jcr.Session)49 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)45 Value (javax.jcr.Value)29 NodeImpl (org.apache.jackrabbit.core.NodeImpl)29 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)28 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)24 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)24 SimpleCredentials (javax.jcr.SimpleCredentials)21 HashMap (java.util.HashMap)18 QueryBuilder (org.apache.jackrabbit.api.security.user.QueryBuilder)16