Search in sources :

Example 66 with SimpleCredentials

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

the class ExternalLoginModuleDynamicMembershipTest method testSyncUpdateAfterXmlImport.

@Test
public void testSyncUpdateAfterXmlImport() throws Exception {
    try {
        // force initial sync
        login(new SimpleCredentials(USER_ID, new char[0])).close();
        // remove properties according to the behavior in the XML-import
        Root systemRoot = getSystemRoot();
        UserManager userManager = getUserManager(systemRoot);
        Authorizable a = userManager.getAuthorizable(USER_ID);
        a.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES);
        a.removeProperty(ExternalIdentityConstants.REP_LAST_SYNCED);
        systemRoot.commit();
        // login again to force sync of the user (and it's group membership)
        login(new SimpleCredentials(USER_ID, new char[0])).close();
        systemRoot.refresh();
        a = userManager.getAuthorizable(USER_ID);
        assertTrue(a.hasProperty(ExternalIdentityConstants.REP_LAST_SYNCED));
        assertExternalPrincipalNames(userManager, USER_ID);
    } finally {
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Root(org.apache.jackrabbit.oak.api.Root) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Test(org.junit.Test)

Example 67 with SimpleCredentials

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

the class ExternalLoginModuleTest method testSyncUpdate.

@Test
public void testSyncUpdate() throws Exception {
    // create user upfront in order to test update mode
    UserManager userManager = getUserManager(root);
    ExternalUser externalUser = idp.getUser(USER_ID);
    Authorizable user = userManager.createUser(externalUser.getId(), null);
    user.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, getValueFactory().createValue(externalUser.getExternalId().getString()));
    root.commit();
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, new char[0]));
        root.refresh();
        Authorizable a = userManager.getAuthorizable(USER_ID);
        assertNotNull(a);
        for (String prop : externalUser.getProperties().keySet()) {
            assertTrue(a.hasProperty(prop));
        }
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 68 with SimpleCredentials

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

the class PreAuthDefaultExternalLoginModuleTest method testSimpleLocal.

@Test
public void testSimpleLocal() throws Exception {
    User testUser = getTestUser();
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(testUser.getID(), testUser.getID().toCharArray()));
        assertEquals(testUser.getID(), cs.getAuthInfo().getUserID());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 69 with SimpleCredentials

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

the class PreAuthLoginModule method login.

@Override
public boolean login() {
    Credentials credentials = getCredentials();
    if (credentials instanceof PreAuthCredentials) {
        PreAuthCredentials pac = (PreAuthCredentials) credentials;
        String userId = pac.getUserId();
        if (userId == null) {
            pac.setMessage(PreAuthCredentials.PRE_AUTH_FAIL);
        } else {
            sharedState.put(SHARED_KEY_PRE_AUTH_LOGIN, new PreAuthenticatedLogin(userId));
            sharedState.put(SHARED_KEY_CREDENTIALS, new SimpleCredentials(userId, new char[0]));
            sharedState.put(SHARED_KEY_LOGIN_NAME, userId);
            pac.setMessage(PreAuthCredentials.PRE_AUTH_DONE);
        }
    }
    return false;
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) PreAuthenticatedLogin(org.apache.jackrabbit.oak.spi.security.authentication.PreAuthenticatedLogin)

Example 70 with SimpleCredentials

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

the class ExternalLoginModuleTest method testSyncCreateUser.

@Test
public void testSyncCreateUser() throws Exception {
    UserManager userManager = getUserManager(root);
    ContentSession cs = null;
    try {
        assertNull(userManager.getAuthorizable(USER_ID));
        cs = login(new SimpleCredentials(USER_ID, new char[0]));
        root.refresh();
        Authorizable a = userManager.getAuthorizable(USER_ID);
        assertNotNull(a);
        ExternalUser user = idp.getUser(USER_ID);
        for (String prop : user.getProperties().keySet()) {
            assertTrue(a.hasProperty(prop));
        }
        assertEquals(TEST_CONSTANT_PROPERTY_VALUE, a.getProperty(TEST_CONSTANT_PROPERTY_NAME)[0].getString());
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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