Search in sources :

Example 51 with Credentials

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

the class GuestLoginModule method login.

@Override
public boolean login() {
    if (callbackHandler != null) {
        CredentialsCallback ccb = new CredentialsCallback();
        try {
            callbackHandler.handle(new Callback[] { ccb });
            Credentials credentials = ccb.getCredentials();
            if (credentials == null) {
                guestCredentials = new GuestCredentials();
                sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, guestCredentials);
                return true;
            }
        } catch (IOException e) {
            log.debug("Login: Failed to retrieve Credentials from CallbackHandler", e);
        } catch (UnsupportedCallbackException e) {
            log.debug("Login: Failed to retrieve Credentials from CallbackHandler", e);
        }
    }
    // ignore this login module
    return false;
}
Also used : IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) GuestCredentials(javax.jcr.GuestCredentials) Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials) CredentialsCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.CredentialsCallback)

Example 52 with Credentials

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

the class PreAuthDefaultExternalLoginModuleTest method testSimpleExternal.

@Test
public void testSimpleExternal() throws Exception {
    // verify that authentication against the IDP succeeds with the given creds.
    Credentials creds = new SimpleCredentials(TestIdentityProvider.ID_TEST_USER, new char[0]);
    ExternalUser externalUser = idp.authenticate(creds);
    assertNotNull(externalUser);
    assertEquals(TestIdentityProvider.ID_TEST_USER, externalUser.getId());
    // => repo login must also succeed and the user must be synced.
    ContentSession cs = null;
    try {
        cs = login(creds);
        assertEquals(TestIdentityProvider.ID_TEST_USER, cs.getAuthInfo().getUserID());
        root.refresh();
        User u = getUserManager(root).getAuthorizable(TestIdentityProvider.ID_TEST_USER, User.class);
        assertNotNull(u);
    } 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) GuestCredentials(javax.jcr.GuestCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 53 with Credentials

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

the class TokenExternalLoginModuleTest method testTokenLogin.

@Test
public void testTokenLogin() throws Exception {
    Credentials creds = createTestCredentials();
    assertTrue(credentialsSupport.setAttributes(creds, ImmutableMap.<String, Object>of(".token", "")));
    String expectedUserId = credentialsSupport.getUserId(creds);
    ContentSession cs = login(creds);
    try {
        String token = credentialsSupport.getAttributes(creds).get(".token").toString();
        cs.close();
        cs = login(new TokenCredentials(token));
        assertEquals(expectedUserId, cs.getAuthInfo().getUserID());
    } finally {
        cs.close();
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Credentials(javax.jcr.Credentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Test(org.junit.Test)

Example 54 with Credentials

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

the class CugOakTest method beforeSuite.

@Override
protected void beforeSuite() throws Exception {
    super.beforeSuite();
    Credentials creds = (runAsAdmin) ? getCredentials() : new GuestCredentials();
    cs = contentRepository.login(creds, null);
    subject = new Subject(true, cs.getAuthInfo().getPrincipals(), Collections.emptySet(), Collections.emptySet());
}
Also used : GuestCredentials(javax.jcr.GuestCredentials) Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials) Subject(javax.security.auth.Subject)

Example 55 with Credentials

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

the class CallbackHandlerImplTest method handleNameCallback2.

@Test
public void handleNameCallback2() throws Exception {
    NameCallback cb = new NameCallback("prompt");
    create(new Credentials() {
    }).handle(new Callback[] { cb });
    assertNull(cb.getName());
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

Credentials (javax.jcr.Credentials)86 SimpleCredentials (javax.jcr.SimpleCredentials)53 Test (org.junit.Test)33 GuestCredentials (javax.jcr.GuestCredentials)26 Session (javax.jcr.Session)17 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)14 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)13 RepositoryException (javax.jcr.RepositoryException)12 User (org.apache.jackrabbit.api.security.user.User)12 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)12 LoginException (javax.security.auth.login.LoginException)8 ArrayList (java.util.ArrayList)7 LoginException (javax.jcr.LoginException)6 Subject (javax.security.auth.Subject)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Repository (javax.jcr.Repository)5 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)5 Principal (java.security.Principal)4 Map (java.util.Map)4