Search in sources :

Example 1 with DefaultPrincipalResolutionExecutionPlan

use of org.apereo.cas.authentication.principal.DefaultPrincipalResolutionExecutionPlan in project cas by apereo.

the class SurrogatePrincipalResolverTests method verifyPrincipalResolutionPlan.

@Test
public void verifyPrincipalResolutionPlan() {
    val surrogatePrincipalBuilder = new SurrogatePrincipalBuilder(PrincipalFactoryUtils.newPrincipalFactory(), CoreAuthenticationTestUtils.getAttributeRepository(), new SimpleSurrogateAuthenticationService(Map.of("test", List.of("surrogate")), mock(ServicesManager.class)));
    val upc = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    val surrogateCreds = new SurrogateUsernamePasswordCredential();
    surrogateCreds.setSurrogateUsername("surrogate");
    surrogateCreds.setUsername(upc.getUsername());
    val plan = new DefaultPrincipalResolutionExecutionPlan();
    val context = getPrincipalResolutionContext(StringUtils.EMPTY, CoreAuthenticationTestUtils.getAttributeRepository());
    plan.registerPrincipalResolver(new PersonDirectoryPrincipalResolver(context));
    plan.registerPrincipalResolver(new SurrogatePrincipalResolver(context).setSurrogatePrincipalBuilder(surrogatePrincipalBuilder));
    val resolver = new ChainingPrincipalResolver(new DefaultPrincipalElectionStrategy(), casProperties);
    resolver.setChain(plan.getRegisteredPrincipalResolvers());
    val upcPrincipal = resolver.resolve(upc, Optional.of(CoreAuthenticationTestUtils.getPrincipal("test")), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
    assertNotNull(upcPrincipal);
    assertEquals(1, upcPrincipal.getAttributes().get("givenName").size());
    assertEquals(upc.getId(), upcPrincipal.getId());
    val surrogatePrincipal = resolver.resolve(surrogateCreds, Optional.of(CoreAuthenticationTestUtils.getPrincipal("casuser")), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
    assertNotNull(surrogatePrincipal);
    assertEquals(1, surrogatePrincipal.getAttributes().get("givenName").size());
    assertEquals(surrogateCreds.getId(), surrogatePrincipal.getId());
}
Also used : lombok.val(lombok.val) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) DefaultPrincipalResolutionExecutionPlan(org.apereo.cas.authentication.principal.DefaultPrincipalResolutionExecutionPlan) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleSurrogateAuthenticationService(org.apereo.cas.authentication.surrogate.SimpleSurrogateAuthenticationService) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)1 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)1 DefaultPrincipalElectionStrategy (org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy)1 DefaultPrincipalResolutionExecutionPlan (org.apereo.cas.authentication.principal.DefaultPrincipalResolutionExecutionPlan)1 ChainingPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver)1 PersonDirectoryPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver)1 SimpleSurrogateAuthenticationService (org.apereo.cas.authentication.surrogate.SimpleSurrogateAuthenticationService)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1