Search in sources :

Example 36 with SimpleCredentials

use of javax.jcr.SimpleCredentials 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 37 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.

the class LdapLoginTestBase method concurrentLogin.

private void concurrentLogin(String[] users) throws Exception {
    final List<Exception> exceptions = new ArrayList<Exception>();
    List<Thread> workers = new ArrayList<Thread>();
    for (String userId : users) {
        final String uid = userId;
        workers.add(new Thread(new Runnable() {

            public void run() {
                try {
                    login(new SimpleCredentials(uid, USER_PWD.toCharArray())).close();
                } catch (Exception e) {
                    exceptions.add(e);
                }
            }
        }));
    }
    for (Thread t : workers) {
        t.start();
    }
    for (Thread t : workers) {
        t.join();
    }
    for (Exception e : exceptions) {
        e.printStackTrace();
    }
    if (!exceptions.isEmpty()) {
        throw exceptions.get(0);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ArrayList(java.util.ArrayList) LoginException(javax.security.auth.login.LoginException)

Example 38 with SimpleCredentials

use of javax.jcr.SimpleCredentials 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)

Example 39 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.

the class LdapLoginTestBase method testLoginSetsAuthInfo.

@Test
public void testLoginSetsAuthInfo() throws Exception {
    ContentSession cs = null;
    try {
        SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PWD.toCharArray());
        sc.setAttribute("attr", "val");
        cs = login(sc);
        AuthInfo ai = cs.getAuthInfo();
        assertEquals(USER_ID, ai.getUserID());
        assertEquals("val", ai.getAttribute("attr"));
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 40 with SimpleCredentials

use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.

the class LoginModuleImplTest method testUserLoginIsCaseInsensitive.

@Test
public void testUserLoginIsCaseInsensitive() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        cs = login(new SimpleCredentials(USER_ID_CASED, USER_PW.toCharArray()));
        AuthInfo authInfo = cs.getAuthInfo();
        UserManager userMgr = getUserManager(root);
        Authorizable auth = userMgr.getAuthorizable(authInfo.getUserID());
        assertNotNull(auth);
        assertTrue(auth.getID().equalsIgnoreCase(USER_ID_CASED));
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

SimpleCredentials (javax.jcr.SimpleCredentials)289 Test (org.junit.Test)142 Session (javax.jcr.Session)83 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)60 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)53 User (org.apache.jackrabbit.api.security.user.User)41 Credentials (javax.jcr.Credentials)39 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)35 UserManager (org.apache.jackrabbit.api.security.user.UserManager)34 LoginException (javax.security.auth.login.LoginException)30 Node (javax.jcr.Node)28 RepositoryException (javax.jcr.RepositoryException)25 Principal (java.security.Principal)22 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)21 GuestCredentials (javax.jcr.GuestCredentials)20 LoginException (javax.jcr.LoginException)19 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)19 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)18 Before (org.junit.Before)18 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)17