Search in sources :

Example 36 with AuthInfo

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

the class AuthInfoImplNullTest method testCreateAuthInfoFromEmptySubject.

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

Example 37 with AuthInfo

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

the class AuthInfoImplTest method testCreateFromSubjectWithPrivateSimpleCredentials.

@Test
public void testCreateFromSubjectWithPrivateSimpleCredentials() {
    Subject subject = new Subject();
    subject.getPrivateCredentials().add(new SimpleCredentials(USER_ID, new char[0]));
    AuthInfo info = AuthInfoImpl.createFromSubject(subject);
    assertNull(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 38 with AuthInfo

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

the class AuthInfoImplTest method testCreateFromSubjectWithPrincipals.

@Test
public void testCreateFromSubjectWithPrincipals() {
    Subject subject = new Subject();
    subject.getPrincipals().addAll(PRINCIPALS);
    AuthInfo info = AuthInfoImpl.createFromSubject(subject);
    assertNull(info.getUserID());
    assertEquals(PRINCIPALS, info.getPrincipals());
    assertEquals(0, info.getAttributeNames().length);
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 39 with AuthInfo

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

the class IndexInitializer method createAdministrativeSession.

private Session createAdministrativeSession() throws RepositoryException {
    //Admin ID here can be any string and need not match the actual admin userId
    final String adminId = "admin";
    Principal admin = new AdminPrincipal() {

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

            @Override
            public Session run() throws Exception {
                return repository.login();
            }
        }, null);
    } catch (PrivilegedActionException e) {
        throw new RepositoryException("failed to retrieve admin session.", e);
    }
    return adminSession;
}
Also used : AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) PrivilegedActionException(java.security.PrivilegedActionException) RepositoryException(javax.jcr.RepositoryException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject) Session(javax.jcr.Session)

Example 40 with AuthInfo

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

the class UserIDTestLoginModule method commit.

@Override
public boolean commit() {
    if (!subject.isReadOnly()) {
        // be defensive: remove all potentially added "AuthInfo' objects.
        Set<AuthInfo> ais = subject.getPublicCredentials(AuthInfo.class);
        if (!ais.isEmpty()) {
            subject.getPublicCredentials().removeAll(ais);
        }
        // and finally add the one that produces the desired result:
        String userID = null;
        subject.getPublicCredentials().add(new AuthInfoImpl(userID, Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
        return true;
    } else {
        return false;
    }
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) Principal(java.security.Principal)

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