Search in sources :

Example 26 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class AbstractLoginModuleTest method testGetPrincipalProviderFromCallback.

@Test
public void testGetPrincipalProviderFromCallback() {
    AbstractLoginModule loginModule = initLoginModule(TestCredentials.class, new TestCallbackHandler(new TestPrincipalProvider()));
    assertNotNull(loginModule.getPrincipalProvider());
    PrincipalProvider principalProvider = loginModule.getPrincipalProvider();
    assertNotNull(principalProvider);
    // principalProvider is stored as field -> second access returns the same object
    assertSame(principalProvider, loginModule.getPrincipalProvider());
}
Also used : TestPrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider) PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) TestPrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider) Test(org.junit.Test)

Example 27 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class AbstractLoginModuleTest method testGetPrincipalsFromPrincipal.

@Test
public void testGetPrincipalsFromPrincipal() {
    PrincipalProvider principalProvider = new TestPrincipalProvider();
    AbstractLoginModule loginModule = initLoginModule(TestCredentials.class, new TestCallbackHandler(principalProvider));
    Principal principal = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP).next();
    Set<Principal> expected = new HashSet<>();
    expected.add(principal);
    expected.addAll(principalProvider.getGroupMembership(principal));
    Set<? extends Principal> principals = loginModule.getPrincipals(principal);
    assertFalse(principals.isEmpty());
    assertEquals(expected, principals);
}
Also used : TestPrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider) PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) TestPrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider) Principal(java.security.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider 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 29 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class ExternalPrincipalConfigurationTest method testGetPrincipalProviderEnabled.

@Test
public void testGetPrincipalProviderEnabled() {
    enable();
    PrincipalProvider pp = principalConfiguration.getPrincipalProvider(root, NamePathMapper.DEFAULT);
    assertNotNull(pp);
    assertTrue(pp instanceof ExternalGroupPrincipalProvider);
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 30 with PrincipalProvider

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider in project jackrabbit-oak by apache.

the class ExternalPrincipalConfigurationTest method assertIsEnabled.

private void assertIsEnabled(ExternalPrincipalConfiguration externalPrincipalConfiguration, boolean expected) throws Exception {
    PrincipalProvider pp = externalPrincipalConfiguration.getPrincipalProvider(root, getNamePathMapper());
    assertEquals(expected, pp instanceof ExternalGroupPrincipalProvider);
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider)

Aggregations

PrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider)30 Test (org.junit.Test)26 AbstractPrincipalProviderTest (org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest)16 Tree (org.apache.jackrabbit.oak.api.Tree)10 Principal (java.security.Principal)6 Group (org.apache.jackrabbit.api.security.user.Group)5 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 Nonnull (javax.annotation.Nonnull)3 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)3 Root (org.apache.jackrabbit.oak.api.Root)3 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)3 TestPrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider)3 HashSet (java.util.HashSet)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)2 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)2 PrincipalConfiguration (org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CheckForNull (javax.annotation.CheckForNull)1