Search in sources :

Example 81 with Authorizable

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

the class UserManagerImplTest method testFindAuthorizableByAddedProperty.

public void testFindAuthorizableByAddedProperty() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    Authorizable auth = null;
    try {
        auth = userMgr.createGroup(p);
        auth.setProperty("E-Mail", new Value[] { superuser.getValueFactory().createValue("anyVal") });
        save(superuser);
        boolean found = false;
        Iterator<Authorizable> result = userMgr.findAuthorizables("E-Mail", "anyVal");
        while (result.hasNext()) {
            Authorizable a = result.next();
            if (a.getID().equals(auth.getID())) {
                found = true;
            }
        }
        assertTrue(found);
    } finally {
        // remove the create group again.
        if (auth != null) {
            auth.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 82 with Authorizable

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

the class LdapLoginTestBase method after.

@After
public void after() throws Exception {
    if (!USE_COMMON_LDAP_FIXTURE) {
        LDAP_SERVER.tearDown();
    }
    try {
        Authorizable a = userManager.getAuthorizable(USER_ID);
        if (a != null) {
            a.remove();
        }
        if (GROUP_DN != null) {
            a = userManager.getAuthorizable(GROUP_DN);
            if (a != null) {
                a.remove();
            }
        }
        root.commit();
    } finally {
        root.refresh();
        super.after();
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) After(org.junit.After)

Example 83 with Authorizable

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

the class LdapLoginTestBase method testSyncCreateUser.

@Test
public void testSyncCreateUser() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));
        root.refresh();
        Authorizable user = userManager.getAuthorizable(USER_ID);
        assertNotNull(user);
        assertTrue(user.hasProperty(USER_PROP));
        Tree userTree = cs.getLatestRoot().getTree(user.getPath());
        assertFalse(userTree.hasProperty(UserConstants.REP_PASSWORD));
        assertNull(userManager.getAuthorizable(GROUP_DN));
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) Test(org.junit.Test)

Example 84 with Authorizable

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

the class LdapLoginTestBase method testSyncUpdate.

@Test
public void testSyncUpdate() throws Exception {
    // create user upfront in order to test update mode
    Authorizable user = userManager.createUser(USER_ID, null);
    ExternalUser externalUser = idp.getUser(USER_ID);
    user.setProperty("rep:externalId", new ValueFactoryImpl(root, NamePathMapper.DEFAULT).createValue(externalUser.getExternalId().getString()));
    root.commit();
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));
        root.refresh();
        user = userManager.getAuthorizable(USER_ID);
        assertNotNull(user);
        assertTrue(user.hasProperty(USER_PROP));
        assertNull(userManager.getAuthorizable(GROUP_DN));
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 85 with Authorizable

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

the class LdapLoginTestBase method testReLogin.

@Test
public void testReLogin() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));
        root.refresh();
        Authorizable user = userManager.getAuthorizable(USER_ID);
        assertNotNull(user);
        assertFalse(root.getTree(user.getPath()).hasProperty(UserConstants.REP_PASSWORD));
        cs.close();
        // login again
        cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));
        root.refresh();
        assertEquals(USER_ID, cs.getAuthInfo().getUserID());
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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