Search in sources :

Example 31 with GuestCredentials

use of javax.jcr.GuestCredentials 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 32 with GuestCredentials

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

the class GuestLoginModuleTest method testNullLogin.

@Test
public void testNullLogin() throws LoginException {
    Subject subject = new Subject();
    CallbackHandler cbh = new TestCallbackHandler(null);
    Map sharedState = new HashMap();
    guestLoginModule.initialize(subject, cbh, sharedState, Collections.<String, Object>emptyMap());
    assertTrue(guestLoginModule.login());
    Object sharedCreds = sharedState.get(AbstractLoginModule.SHARED_KEY_CREDENTIALS);
    assertNotNull(sharedCreds);
    assertTrue(sharedCreds instanceof GuestCredentials);
    assertTrue(guestLoginModule.commit());
    assertFalse(subject.getPrincipals(EveryonePrincipal.class).isEmpty());
    assertFalse(subject.getPublicCredentials(GuestCredentials.class).isEmpty());
    assertTrue(guestLoginModule.logout());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Subject(javax.security.auth.Subject) GuestCredentials(javax.jcr.GuestCredentials) Test(org.junit.Test)

Example 33 with GuestCredentials

use of javax.jcr.GuestCredentials 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)

Example 34 with GuestCredentials

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

the class L9_NullLoginTest method testJr2CompatibleLoginConfiguration.

public void testJr2CompatibleLoginConfiguration() throws RepositoryException {
    // EXERCISE: define the JAAS configuration that allows you to have null-login treated as anonymous login.
    Configuration configuration = null;
    Configuration.setConfiguration(configuration);
    try {
        testSession = repository.login();
        Session guest = repository.login(new GuestCredentials());
        String expectedId = guest.getUserID();
        guest.logout();
        assertEquals(expectedId, testSession.getUserID());
    } finally {
        Configuration.setConfiguration(null);
    }
}
Also used : Configuration(javax.security.auth.login.Configuration) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session)

Example 35 with GuestCredentials

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

the class L15_RepositoryWithoutAnonymousTest method testAnonymousLogin.

@Test
public void testAnonymousLogin() throws Exception {
    ContentSession oakSession = null;
    try {
        oakSession = login(new GuestCredentials());
        fail("Anonymous login must fail.");
    } catch (javax.security.auth.login.LoginException e) {
    // success
    } finally {
        if (oakSession != null) {
            oakSession.close();
        }
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

GuestCredentials (javax.jcr.GuestCredentials)39 Test (org.junit.Test)25 SimpleCredentials (javax.jcr.SimpleCredentials)13 Credentials (javax.jcr.Credentials)12 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 Session (javax.jcr.Session)8 LoginException (javax.security.auth.login.LoginException)7 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Subject (javax.security.auth.Subject)4 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)4 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)4 ArrayList (java.util.ArrayList)3 Repository (javax.jcr.Repository)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 Map (java.util.Map)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlManager (javax.jcr.security.AccessControlManager)2