Search in sources :

Example 81 with SimpleCredentials

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

the class UserAuthenticationTest method testAuthenticateImpersonationCredentials.

@Test
public void testAuthenticateImpersonationCredentials() throws Exception {
    SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
    assertTrue(authentication.authenticate(new ImpersonationCredentials(sc, adminSession.getAuthInfo())));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 82 with SimpleCredentials

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

the class AbstractLoginModuleTest method testGetSharedCredentials.

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

Example 83 with SimpleCredentials

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

the class AbstractLoginModuleTest method testGetCredentialsFromSubjectWrongClass.

@Test
public void testGetCredentialsFromSubjectWrongClass() {
    Subject subject = new Subject();
    subject.getPublicCredentials().add(new SimpleCredentials("userid", new char[0]));
    AbstractLoginModule lm = new TestLoginModule(TestCredentials.class);
    lm.initialize(subject, null, ImmutableMap.<String, Object>of(), null);
    assertNull(lm.getCredentials());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 84 with SimpleCredentials

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

the class GuestLoginModuleTest method testSimpleCredentials.

@Test
public void testSimpleCredentials() throws LoginException {
    Subject subject = new Subject();
    CallbackHandler cbh = new TestCallbackHandler(new SimpleCredentials("test", new char[0]));
    Map sharedState = new HashMap();
    guestLoginModule.initialize(subject, cbh, sharedState, Collections.<String, Object>emptyMap());
    assertFalse(guestLoginModule.login());
    assertFalse(sharedState.containsKey(AbstractLoginModule.SHARED_KEY_CREDENTIALS));
    assertFalse(guestLoginModule.commit());
    assertTrue(subject.getPrincipals().isEmpty());
    assertTrue(subject.getPublicCredentials().isEmpty());
    assertFalse(guestLoginModule.logout());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 85 with SimpleCredentials

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

the class AuthInfoImplTest method testCreateFromSubjectWithSimpleCredentials.

@Test
public void testCreateFromSubjectWithSimpleCredentials() {
    Subject subject = new Subject();
    subject.getPublicCredentials().add(new SimpleCredentials(USER_ID, new char[0]));
    AuthInfo info = AuthInfoImpl.createFromSubject(subject);
    assertEquals(USER_ID, info.getUserID());
    assertTrue(info.getPrincipals().isEmpty());
    assertEquals(0, info.getAttributeNames().length);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Subject(javax.security.auth.Subject) 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