Search in sources :

Example 11 with AuthInfo

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

the class PreAuthTest method testValidReadSubjectWithCredentials.

@Test
public void testValidReadSubjectWithCredentials() throws Exception {
    Set<SimpleCredentials> publicCreds = Collections.singleton(new SimpleCredentials("testUserId", new char[0]));
    final Subject subject = new Subject(true, principals, publicCreds, Collections.<Object>emptySet());
    ContentSession cs = Subject.doAsPrivileged(subject, new PrivilegedAction<ContentSession>() {

        @Override
        public ContentSession run() {
            try {
                return login(null);
            } catch (Exception e) {
                return null;
            }
        }
    }, null);
    try {
        AuthInfo authInfo = cs.getAuthInfo();
        assertNotSame(AuthInfo.EMPTY, authInfo);
        assertEquals(principals, authInfo.getPrincipals());
        assertEquals("testUserId", 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) Subject(javax.security.auth.Subject) SystemSubject(org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 12 with AuthInfo

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

the class GuestDefaultLoginModuleTest method testGuestLogin.

@Test
public void testGuestLogin() throws Exception {
    ContentSession cs = login(new GuestCredentials());
    try {
        AuthInfo authInfo = cs.getAuthInfo();
        String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());
        assertEquals(anonymousID, authInfo.getUserID());
    } finally {
        cs.close();
    }
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 13 with AuthInfo

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

the class AbstractLoginModuleTest method testSetAuthInfoPreExisting.

@Test
public void testSetAuthInfoPreExisting() {
    Subject subject = new Subject();
    subject.getPublicCredentials().add(new AuthInfoImpl(null, null, null));
    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)

Example 14 with AuthInfo

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

the class AuthInfoImplTest method testCreateFromSubjectWithAnyCredentials.

@Test
public void testCreateFromSubjectWithAnyCredentials() {
    Subject subject = new Subject();
    subject.getPublicCredentials().add(new Credentials() {
    });
    AuthInfo info = AuthInfoImpl.createFromSubject(subject);
    assertNull(info.getUserID());
    assertTrue(info.getPrincipals().isEmpty());
    assertEquals(0, info.getAttributeNames().length);
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Subject(javax.security.auth.Subject) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 15 with AuthInfo

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

the class AuthInfoImplTest method testCreateFromSubjectWithAuthInfo.

@Test
public void testCreateFromSubjectWithAuthInfo() {
    Subject subject = new Subject();
    subject.getPublicCredentials().add(authInfo);
    AuthInfo info = AuthInfoImpl.createFromSubject(subject);
    assertEquals(USER_ID, info.getUserID());
    assertEquals(PRINCIPALS, info.getPrincipals());
    assertArrayEquals(authInfo.getAttributeNames(), info.getAttributeNames());
}
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