Search in sources :

Example 1 with PersonDirectoryPrincipalResolver

use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.

the class PersonDirectoryPrincipalResolverTests method verifyChainingResolverOverwrite.

@Test
public void verifyChainingResolverOverwrite() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(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 PersonDirectoryPrincipalResolver

use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.

the class PersonDirectoryPrincipalResolverTests method verifyAttributesWithPrincipal.

@Test
public void verifyAttributesWithPrincipal() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(CoreAuthenticationTestUtils.getAttributeRepository(), "cn");
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final Principal p = resolver.resolve(c, null);
    assertNotNull(p);
    assertNotEquals(p.getId(), CoreAuthenticationTestUtils.CONST_USERNAME);
    assertTrue(p.getAttributes().containsKey("memberOf"));
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) Credential(org.apereo.cas.authentication.Credential) Test(org.junit.Test)

Example 3 with PersonDirectoryPrincipalResolver

use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.

the class PersonDirectoryPrincipalResolverTests method verifyNoAttributesWithPrincipal.

@Test
public void verifyNoAttributesWithPrincipal() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(CoreAuthenticationTestUtils.getAttributeRepository(), CoreAuthenticationTestUtils.CONST_USERNAME);
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final Principal p = resolver.resolve(c, null);
    assertNotNull(p);
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) Credential(org.apereo.cas.authentication.Credential) Test(org.junit.Test)

Example 4 with PersonDirectoryPrincipalResolver

use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.

the class DefaultAuthenticationEventExecutionPlanTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = PrincipalResolutionContext.builder().attributeRepository(CoreAuthenticationTestUtils.getAttributeRepository()).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalNameTransformer(formUserId -> formUserId).useCurrentPrincipalId(false).resolveAttributes(true).attributeMerger(CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.REPLACE)).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
    val plan = new DefaultAuthenticationEventExecutionPlan();
    plan.registerAuthenticationPreProcessor(transaction -> false);
    plan.registerAuthenticationMetadataPopulators(Set.of(new RememberMeAuthenticationMetaDataPopulator(new RememberMeAuthenticationProperties())));
    plan.registerAuthenticationHandlerWithPrincipalResolvers(Set.of(new SimpleTestUsernamePasswordAuthenticationHandler()), new PersonDirectoryPrincipalResolver(context));
    plan.registerAuthenticationPolicy(new AllCredentialsValidatedAuthenticationPolicy());
    plan.registerAuthenticationPolicyResolver(transaction -> Set.of(new AllCredentialsValidatedAuthenticationPolicy()));
    assertFalse(plan.getAuthenticationPolicies(new DefaultAuthenticationTransactionFactory().newTransaction(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword())).isEmpty());
}
Also used : lombok.val(lombok.val) RememberMeAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) PrincipalFactoryUtils(org.apereo.cas.authentication.principal.PrincipalFactoryUtils) lombok.val(lombok.val) Set(java.util.Set) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) AllCredentialsValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AllCredentialsValidatedAuthenticationPolicy) List(java.util.List) CollectionUtils(org.apereo.cas.util.CollectionUtils) Assertions(org.junit.jupiter.api.Assertions) PrincipalAttributesCoreProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesCoreProperties) PrincipalResolutionContext(org.apereo.cas.authentication.principal.resolvers.PrincipalResolutionContext) Tag(org.junit.jupiter.api.Tag) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) RememberMeAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AllCredentialsValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AllCredentialsValidatedAuthenticationPolicy) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 5 with PersonDirectoryPrincipalResolver

use of org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver in project cas by apereo.

the class PrincipalAttributeRepositoryFetcherJdbcTests method verifyOperationWithUsernamePasswordCredentialType.

@Test
public void verifyOperationWithUsernamePasswordCredentialType() {
    val context = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.MULTIVALUED)).attributeRepository(attributeRepository).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).resolveAttributes(true).build();
    val resolver = new PersonDirectoryPrincipalResolver(context);
    val credential = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("casuser");
    val p = resolver.resolve(credential, Optional.of(CoreAuthenticationTestUtils.getPrincipal()), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
    assertNotNull(p);
    assertTrue(p.getAttributes().containsKey("PersonName"));
}
Also used : lombok.val(lombok.val) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) Test(org.junit.jupiter.api.Test)

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