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());
}
Aggregations