Search in sources :

Example 16 with AuthInfo

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

Example 17 with AuthInfo

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

the class L2_AuthInfoTest method testUserAuthInfo.

@Test
public void testUserAuthInfo() throws LoginException, RepositoryException, CommitFailedException {
    testUser = createTestUser(userManager);
    root.commit();
    contentSession = login(ExerciseUtility.getTestCredentials(testUser.getID()));
    AuthInfo authInfo = contentSession.getAuthInfo();
    // EXERCISE : fill in the expected id
    String expectedId = null;
    assertEquals(expectedId, authInfo.getUserID());
    // EXERCISE: create the set of expected principals.
    // EXERCISE: what are the variants you have at hand when using the Jackrabbit API
    // EXERCISE: what are the variants you have at hand when using public Oak SPI interfaces?
    Set<Principal> expectedPrincipals = null;
    assertEquals(expectedPrincipals, authInfo.getPrincipals());
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 18 with AuthInfo

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

the class L2_AuthInfoTest method testUserAuthInfoWithGroupMembership.

@Test
public void testUserAuthInfoWithGroupMembership() throws LoginException, RepositoryException, CommitFailedException {
    testUser = createTestUser(userManager);
    testGroup = createTestGroup(userManager);
    testGroup.addMember(testUser);
    root.commit();
    contentSession = login(getTestCredentials(testUser.getID()));
    AuthInfo authInfo = contentSession.getAuthInfo();
    // EXERCISE: create the set of expected principals.
    // EXERCISE: what are the variants you have at hand when using the Jackrabbit API
    // EXERCISE: what are the variants you have at hand when using public Oak SPI interfaces?
    Set<Principal> expectedPrincipals = null;
    assertEquals(expectedPrincipals, authInfo.getPrincipals());
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 19 with AuthInfo

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

the class L2_AuthInfoTest method testGuestAuthInfo.

@Test
public void testGuestAuthInfo() throws LoginException, NoSuchWorkspaceException {
    contentSession = login(new GuestCredentials());
    AuthInfo authInfo = contentSession.getAuthInfo();
    // EXERCISE : fill in the expected id
    String expectedId = null;
    assertEquals(expectedId, authInfo.getUserID());
    // EXERCISE: create the set of expected principals.
    // EXERCISE: what are the variants you have at hand when using the Jackrabbit API
    // EXERCISE: what are the variants you have at hand when using public Oak SPI interfaces?
    Set<Principal> expectedPrincipals = null;
    assertEquals(expectedPrincipals, authInfo.getPrincipals());
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) GuestCredentials(javax.jcr.GuestCredentials) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 20 with AuthInfo

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

the class OakSlingRepository method createAdministrativeSession.

@Override
protected Session createAdministrativeSession(String workspace) throws RepositoryException {
    // TODO: use principal provider to retrieve admin principal
    Set<? extends Principal> principals = singleton(new AdminPrincipal() {

        @Override
        public String getName() {
            return OakSlingRepository.this.adminId;
        }
    });
    AuthInfo authInfo = new AuthInfoImpl(this.adminId, Collections.<String, Object>emptyMap(), principals);
    Subject subject = new Subject(true, principals, singleton(authInfo), Collections.<Object>emptySet());
    Session adminSession;
    try {
        adminSession = Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>() {

            @Override
            public Session run() throws Exception {
                Map<String, Object> attrs = new HashMap<String, Object>();
                attrs.put("oak.refresh-interval", 0);
                // TODO OAK-803: Backwards compatibility of long-lived sessions
                JackrabbitRepository repo = (JackrabbitRepository) getRepository();
                return repo.login(null, null, attrs);
            }
        }, null);
    } catch (PrivilegedActionException e) {
        throw new RepositoryException("failed to retrieve admin session.", e);
    }
    return adminSession;
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) HashMap(java.util.HashMap) PrivilegedActionException(java.security.PrivilegedActionException) RepositoryException(javax.jcr.RepositoryException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Subject(javax.security.auth.Subject) AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) Session(javax.jcr.Session)

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