Search in sources :

Example 31 with AuthInfo

use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.

the class LoginModuleImplTest method testUserLoginIsCaseInsensitive2.

@Test
public void testUserLoginIsCaseInsensitive2() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        cs = login(new SimpleCredentials(USER_ID_CASED, USER_PW.toCharArray()));
        AuthInfo authInfo = cs.getAuthInfo();
        assertEquals(user.getID(), authInfo.getUserID());
        assertTrue(USER_ID_CASED.equalsIgnoreCase(authInfo.getUserID()));
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 32 with AuthInfo

use of org.apache.jackrabbit.oak.api.AuthInfo 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 33 with AuthInfo

use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.

the class LoginModuleImplTest method testUserLogin.

@Test
public void testUserLogin() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        cs = login(new SimpleCredentials(USER_ID, USER_PW.toCharArray()));
        AuthInfo authInfo = cs.getAuthInfo();
        assertEquals(USER_ID, authInfo.getUserID());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 34 with AuthInfo

use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.

the class LoginModuleImplTest method testInvalidImpersonation.

@Test
public void testInvalidImpersonation() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray());
        cs = login(sc);
        AuthInfo authInfo = cs.getAuthInfo();
        assertEquals(USER_ID, authInfo.getUserID());
        cs.close();
        cs = null;
        ConfigurationParameters config = securityProvider.getConfiguration(UserConfiguration.class).getParameters();
        String adminId = UserUtil.getAdminId(config);
        sc = new SimpleCredentials(adminId, new char[0]);
        ImpersonationCredentials ic = new ImpersonationCredentials(sc, authInfo);
        try {
            cs = login(ic);
            fail("User 'test' should not be allowed to impersonate " + adminId);
        } catch (LoginException e) {
        // success
        }
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 35 with AuthInfo

use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.

the class AbstractLoginModuleTest method testSetAuthInfo.

@Test
public void testSetAuthInfo() {
    Subject subject = new Subject();
    AuthInfo authInfo = new AuthInfoImpl("userid", null, null);
    AbstractLoginModule.setAuthInfo(authInfo, subject);
    Set<AuthInfo> fromSubject = subject.getPublicCredentials(AuthInfo.class);
    assertEquals(1, fromSubject.size());
    assertSame(authInfo, fromSubject.iterator().next());
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Aggregations

AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)42 Test (org.junit.Test)38 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)26 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)24 SimpleCredentials (javax.jcr.SimpleCredentials)19 Subject (javax.security.auth.Subject)15 LoginException (javax.security.auth.login.LoginException)7 Principal (java.security.Principal)6 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)6 GuestCredentials (javax.jcr.GuestCredentials)5 AuthInfoImpl (org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl)5 Credentials (javax.jcr.Credentials)4 Root (org.apache.jackrabbit.oak.api.Root)4 SystemSubject (org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject)4 RepositoryException (javax.jcr.RepositoryException)3 PrivilegedActionException (java.security.PrivilegedActionException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 Session (javax.jcr.Session)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2