Search in sources :

Example 16 with ImpersonationCredentials

use of org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials in project jackrabbit-oak by apache.

the class UserAuthenticationTest method testAuthenticateImpersonationCredentials2.

@Test
public void testAuthenticateImpersonationCredentials2() throws Exception {
    SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
    assertTrue(authentication.authenticate(new ImpersonationCredentials(sc, new TestAuthInfo())));
}
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 17 with ImpersonationCredentials

use of org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials 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)

Aggregations

ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)17 SimpleCredentials (javax.jcr.SimpleCredentials)15 Test (org.junit.Test)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 Credentials (javax.jcr.Credentials)7 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)7 GuestCredentials (javax.jcr.GuestCredentials)6 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)5 LoginException (javax.security.auth.login.LoginException)4 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)4 AuthInfoImpl (org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl)4 ArrayList (java.util.ArrayList)3 Principal (java.security.Principal)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Nonnull (javax.annotation.Nonnull)2 FailedLoginException (javax.security.auth.login.FailedLoginException)2 User (org.apache.jackrabbit.api.security.user.User)2 IOException (java.io.IOException)1 CheckForNull (javax.annotation.CheckForNull)1