Search in sources :

Example 21 with AuthInfo

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

the class LdapLoginTestBase method testPrincipalsFromAuthInfo.

@Test
public void testPrincipalsFromAuthInfo() throws Exception {
    ContentSession cs = null;
    try {
        SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PWD.toCharArray());
        sc.setAttribute("attr", "val");
        cs = login(sc);
        AuthInfo ai = cs.getAuthInfo();
        root.refresh();
        PrincipalProvider pp = getSecurityProvider().getConfiguration(PrincipalConfiguration.class).getPrincipalProvider(root, NamePathMapper.DEFAULT);
        Set<? extends Principal> expected = pp.getPrincipals(USER_ID);
        assertEquals(3, expected.size());
        assertEquals(expected, ai.getPrincipals());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 22 with AuthInfo

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

the class PreAuthTest method testValidSubjectWithAuthInfo.

@Test
public void testValidSubjectWithAuthInfo() throws Exception {
    AuthInfo info = new AuthInfoImpl("testUserId", Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet());
    Set<AuthInfo> publicCreds = Collections.singleton(info);
    final Subject subject = new Subject(false, Collections.singleton(new TestPrincipal()), 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 {
        assertSame(info, cs.getAuthInfo());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) 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 23 with AuthInfo

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

the class GuestDefaultLoginModuleTest method testNullLogin.

@Test
public void testNullLogin() throws Exception {
    ContentSession cs = login(null);
    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) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 24 with AuthInfo

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

the class Jackrabbit2ConfigurationTest method testNullLogin.

@Test
public void testNullLogin() throws Exception {
    ContentSession cs = login(null);
    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) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 25 with AuthInfo

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

the class Jackrabbit2ConfigurationTest method testTokenCreationWithImpersonationAttributes.

@Test
public void testTokenCreationWithImpersonationAttributes() throws Exception {
    ContentSession cs = null;
    try {
        SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
        sc.setAttribute(".token", "");
        sc.setAttribute(".token.mandatory", "something");
        sc.setAttribute("attr", "val");
        ImpersonationCredentials ic = new ImpersonationCredentials(sc, new AuthInfoImpl(((SimpleCredentials) getAdminCredentials()).getUserID(), Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
        cs = login(ic);
        AuthInfo ai = cs.getAuthInfo();
        Set<String> attrNames = ImmutableSet.copyOf(ai.getAttributeNames());
        assertTrue(attrNames.contains("attr"));
        assertFalse(attrNames.contains(".token"));
        assertFalse(attrNames.contains(".token.mandatory"));
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) 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