Search in sources :

Example 6 with ChainingPrincipalResolver

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"));
    });
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) HashMap(java.util.HashMap) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ChainingPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver)6 Test (org.junit.Test)6 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)5 EchoingPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver)4 PersonDirectoryPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver)4 HashMap (java.util.HashMap)2 Credential (org.apereo.cas.authentication.Credential)2 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)1 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1