use of org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverLdaptiveTests method verifyChainedResolver.
@Test
public void verifyChainedResolver() {
this.getEntries().forEach(entry -> {
final String username = entry.getAttribute("sAMAccountName").getStringValue();
final String psw = entry.getAttribute(ATTR_NAME_PASSWORD).getStringValue();
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
resolver.setAttributeRepository(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(username, psw), CoreAuthenticationTestUtils.getPrincipal(username, attributes), new SimpleTestUsernamePasswordAuthenticationHandler());
assertNotNull(p);
assertTrue(p.getAttributes().containsKey("displayName"));
assertTrue(p.getAttributes().containsKey("a1"));
assertTrue(p.getAttributes().containsKey("a2"));
});
}
Aggregations