use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyChainingResolver.
@Test
public void verifyChainingResolver() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(CoreAuthenticationTestUtils.getAttributeRepository());
final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
final Principal p = chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), CoreAuthenticationTestUtils.getPrincipal(CoreAuthenticationTestUtils.CONST_USERNAME, Collections.singletonMap(ATTR_1, "value")), new SimpleTestUsernamePasswordAuthenticationHandler());
assertEquals(p.getAttributes().size(), CoreAuthenticationTestUtils.getAttributeRepository().getPossibleUserAttributeNames().size() + 1);
assertTrue(p.getAttributes().containsKey(ATTR_1));
}
use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyNullAttributes.
@Test
public void verifyNullAttributes() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(true, CoreAuthenticationTestUtils.CONST_USERNAME);
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
final Principal p = resolver.resolve(c, null);
assertNull(p);
}
use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverLdaptiveTests method verifyResolver.
@Test
public void verifyResolver() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(this.attributeRepository);
final Principal p = resolver.resolve(new UsernamePasswordCredential("castest1", "castest1"), CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler());
assertNotNull(p);
assertTrue(p.getAttributes().containsKey("givenName"));
}
use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverLdaptiveTests method verifyChainedResolver.
@Test
public void verifyChainedResolver() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(this.attributeRepository);
final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
final Map<String, Object> attributes = new HashMap<>(2);
attributes.put("a1", "v1");
attributes.put("a2", "v2");
final Principal p = chain.resolve(new UsernamePasswordCredential("castest1", "castest1"), CoreAuthenticationTestUtils.getPrincipal("castest1", attributes), new SimpleTestUsernamePasswordAuthenticationHandler());
assertNotNull(p);
assertTrue(p.getAttributes().containsKey("givenName"));
assertTrue(p.getAttributes().containsKey("a1"));
assertTrue(p.getAttributes().containsKey("a2"));
}
use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver 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