Search in sources :

Example 11 with PersonDirectoryPrincipalResolver

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));
}
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 12 with PersonDirectoryPrincipalResolver

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

Example 13 with PersonDirectoryPrincipalResolver

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

Example 14 with PersonDirectoryPrincipalResolver

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

Example 15 with PersonDirectoryPrincipalResolver

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());
}
Also used : lombok.val(lombok.val) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) DefaultPrincipalResolutionExecutionPlan(org.apereo.cas.authentication.principal.DefaultPrincipalResolutionExecutionPlan) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleSurrogateAuthenticationService(org.apereo.cas.authentication.surrogate.SimpleSurrogateAuthenticationService) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PersonDirectoryPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver)15 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)10 Test (org.junit.Test)9 ChainingPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver)6 EchoingPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver)5 lombok.val (lombok.val)4 Test (org.junit.jupiter.api.Test)4 Credential (org.apereo.cas.authentication.Credential)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 HashMap (java.util.HashMap)2 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 List (java.util.List)1 Set (java.util.Set)1 RememberMeAuthenticationMetaDataPopulator (org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator)1 AllCredentialsValidatedAuthenticationPolicy (org.apereo.cas.authentication.policy.AllCredentialsValidatedAuthenticationPolicy)1 DefaultPrincipalElectionStrategy (org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy)1