Search in sources :

Example 1 with TestPrincipalProvider

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

the class AbstractLoginModuleTest method testGetPrincipals.

@Test
public void testGetPrincipals() {
    PrincipalProvider principalProvider = new TestPrincipalProvider();
    AbstractLoginModule loginModule = initLoginModule(TestCredentials.class, new TestCallbackHandler(principalProvider));
    Principal principal = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP).next();
    String userId = TestPrincipalProvider.getIDFromPrincipal(principal);
    Set<? extends Principal> principals = loginModule.getPrincipals(userId);
    assertFalse(principals.isEmpty());
    assertEquals(principalProvider.getPrincipals(userId), 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) Test(org.junit.Test)

Example 2 with TestPrincipalProvider

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

use of org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider 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)

Aggregations

PrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider)3 TestPrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.TestPrincipalProvider)3 Test (org.junit.Test)3 Principal (java.security.Principal)2 HashSet (java.util.HashSet)1