use of org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyChainingResolverOverwrite.
@Test
public void verifyChainingResolverOverwrite() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
resolver.setAttributeRepository(CoreAuthenticationTestUtils.getAttributeRepository());
final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
final Map<String, Object> attributes = new HashMap<>();
attributes.put("cn", "changedCN");
attributes.put(ATTR_1, "value1");
final Principal p = chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), CoreAuthenticationTestUtils.getPrincipal(CoreAuthenticationTestUtils.CONST_USERNAME, attributes), new SimpleTestUsernamePasswordAuthenticationHandler());
assertEquals(p.getAttributes().size(), CoreAuthenticationTestUtils.getAttributeRepository().getPossibleUserAttributeNames().size() + 1);
assertTrue(p.getAttributes().containsKey(ATTR_1));
assertTrue(p.getAttributes().containsKey("cn"));
assertTrue(CollectionUtils.toCollection(p.getAttributes().get("cn")).contains("changedCN"));
}
use of org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyChainingResolver.
@Test
public void verifyChainingResolver() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
resolver.setAttributeRepository(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.EchoingPrincipalResolver in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyChainingResolverDistinct.
@Test
public void verifyChainingResolverDistinct() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
resolver.setAttributeRepository(CoreAuthenticationTestUtils.getAttributeRepository());
final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
this.thrown.expect(PrincipalException.class);
chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), CoreAuthenticationTestUtils.getPrincipal("somethingelse", Collections.singletonMap(ATTR_1, "value")), new SimpleTestUsernamePasswordAuthenticationHandler());
}
use of org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver 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