Search in sources :

Example 56 with Credentials

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

the class TokenAuthenticationTest method testAuthenticateWithInvalidCredentials.

@Test
public void testAuthenticateWithInvalidCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new GuestCredentials());
    invalid.add(new SimpleCredentials(userId, new char[0]));
    for (Credentials creds : invalid) {
        assertFalse(authentication.authenticate(creds));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ArrayList(java.util.ArrayList) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 57 with Credentials

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

the class TokenProviderImplTest method testCreateTokenFromCredentials.

@Test
public void testCreateTokenFromCredentials() throws Exception {
    SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
    List<Credentials> valid = new ArrayList<Credentials>();
    valid.add(sc);
    valid.add(new ImpersonationCredentials(sc, null));
    for (Credentials creds : valid) {
        TokenInfo info = tokenProvider.createToken(creds);
        assertTokenInfo(info, userId);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ArrayList(java.util.ArrayList) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 58 with Credentials

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

the class LoginModuleImplTest method testCustomUserAuthentication.

@Test
public void testCustomUserAuthentication() throws Exception {
    LoginModuleImpl loginModule = new LoginModuleImpl();
    UserAuthenticationFactory factory = new UserAuthenticationFactory() {

        @CheckForNull
        @Override
        public Authentication getAuthentication(@Nonnull UserConfiguration configuration, @Nonnull Root root, @Nullable String userId) {
            return new Authentication() {

                @Override
                public boolean authenticate(@Nullable Credentials credentials) throws LoginException {
                    return true;
                }

                @CheckForNull
                @Override
                public String getUserId() {
                    return null;
                }

                @CheckForNull
                @Override
                public Principal getUserPrincipal() {
                    return null;
                }
            };
        }
    };
    CallbackHandler cbh = new TestCallbackHandler(factory);
    SimpleCredentials creds = new SimpleCredentials("loginId", new char[0]);
    Subject subject = new Subject(false, Sets.<Principal>newHashSet(), ImmutableSet.of(creds), Sets.newHashSet());
    loginModule.initialize(subject, cbh, Maps.<String, Object>newHashMap(), Maps.<String, Object>newHashMap());
    assertTrue(loginModule.login());
    assertTrue(loginModule.commit());
    AuthInfo authInfo = subject.getPublicCredentials(AuthInfo.class).iterator().next();
    assertEquals("loginId", authInfo.getUserID());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) UserAuthenticationFactory(org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) Subject(javax.security.auth.Subject) SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) Nullable(javax.annotation.Nullable) GuestCredentials(javax.jcr.GuestCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 59 with Credentials

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

the class UserAuthenticationTest method testAuthenticateInvalidCredentials.

@Test
public void testAuthenticateInvalidCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new TokenCredentials("token"));
    invalid.add(new Credentials() {
    });
    for (Credentials creds : invalid) {
        assertFalse(authentication.authenticate(creds));
    }
}
Also used : ArrayList(java.util.ArrayList) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 60 with Credentials

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

the class UserAuthenticationTest method testAuthenticateInvalidSimpleCredentials.

@Test
public void testAuthenticateInvalidSimpleCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new SimpleCredentials(userId, "wrongPw".toCharArray()));
    invalid.add(new SimpleCredentials(userId, "".toCharArray()));
    invalid.add(new SimpleCredentials("unknownUser", "pw".toCharArray()));
    for (Credentials creds : invalid) {
        try {
            authentication.authenticate(creds);
            fail("LoginException expected");
        } catch (LoginException e) {
            // success
            assertTrue(e instanceof FailedLoginException);
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) FailedLoginException(javax.security.auth.login.FailedLoginException) ArrayList(java.util.ArrayList) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) 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