Search in sources :

Example 1 with EchoingPrincipalResolver

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

Example 2 with EchoingPrincipalResolver

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));
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) Test(org.junit.Test)

Example 3 with EchoingPrincipalResolver

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());
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) Test(org.junit.Test)

Example 4 with EchoingPrincipalResolver

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"));
    });
}
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

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