Search in sources :

Example 66 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)

Example 67 with Credentials

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

the class UserAuthenticationTest method testAuthenticateInvalidImpersonationCredentials.

@Test
public void testAuthenticateInvalidImpersonationCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new ImpersonationCredentials(new GuestCredentials(), adminSession.getAuthInfo()));
    invalid.add(new ImpersonationCredentials(new SimpleCredentials(adminSession.getAuthInfo().getUserID(), new char[0]), new TestAuthInfo()));
    invalid.add(new ImpersonationCredentials(new SimpleCredentials("unknown", new char[0]), adminSession.getAuthInfo()));
    invalid.add(new ImpersonationCredentials(new SimpleCredentials("unknown", new char[0]), new TestAuthInfo()));
    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) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) 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) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 68 with Credentials

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

the class UserImplTest method testGetCredentialsUserWithoutPassword.

@Test
public void testGetCredentialsUserWithoutPassword() throws Exception {
    user = userMgr.createUser(uid, null);
    root.commit();
    Credentials creds = user.getCredentials();
    assertTrue(creds instanceof UserIdCredentials);
    assertEquals(uid, ((UserIdCredentials) creds).getUserId());
}
Also used : UserIdCredentials(org.apache.jackrabbit.oak.spi.security.user.UserIdCredentials) UserIdCredentials(org.apache.jackrabbit.oak.spi.security.user.UserIdCredentials) Credentials(javax.jcr.Credentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 69 with Credentials

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

the class AbstractLoginModuleTest method testGetCredentialsFromSharedState.

@Test
public void testGetCredentialsFromSharedState() {
    Map<String, Credentials> sharedState = new HashMap();
    sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, new TestCredentials());
    AbstractLoginModule lm = initLoginModule(TestCredentials.class, sharedState);
    assertTrue(lm.getCredentials() instanceof TestCredentials);
    SimpleCredentials sc = new SimpleCredentials("test", "test".toCharArray());
    sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, sc);
    lm = initLoginModule(TestCredentials.class, sharedState);
    assertNull(lm.getCredentials());
    sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, sc);
    lm = initLoginModule(SimpleCredentials.class, sharedState);
    assertTrue(lm.getCredentials() instanceof SimpleCredentials);
    sharedState.clear();
    lm = initLoginModule(TestCredentials.class, sharedState);
    assertNull(lm.getCredentials());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HashMap(java.util.HashMap) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 70 with Credentials

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

the class ImpersonationCredentialsTest method testGetBaseCredentials.

@Test
public void testGetBaseCredentials() {
    Credentials creds = new GuestCredentials();
    assertSame(creds, new ImpersonationCredentials(creds, info).getBaseCredentials());
    Credentials simpleCreds = new SimpleCredentials("userId", new char[0]);
    assertSame(simpleCreds, new ImpersonationCredentials(simpleCreds, info).getBaseCredentials());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) GuestCredentials(javax.jcr.GuestCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials) 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