Search in sources :

Example 6 with PersonDirectoryPrincipalResolver

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

the class PrincipalAttributeRepositoryFetcherJdbcTests method verifyOperationWithoutUsernamePasswordCredentialType.

@Test
public void verifyOperationWithoutUsernamePasswordCredentialType() {
    val context = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.MULTIVALUED)).attributeRepository(attributeRepository).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).resolveAttributes(true).returnNullIfNoAttributes(true).build();
    val resolver = new PersonDirectoryPrincipalResolver(context);
    val credential = CoreAuthenticationTestUtils.getHttpBasedServiceCredentials();
    val p = resolver.resolve(credential, Optional.of(CoreAuthenticationTestUtils.getPrincipal()), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
    assertNull(p);
}
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)

Example 7 with PersonDirectoryPrincipalResolver

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

the class PersonDirectoryPrincipalResolverTests method verifyNullPrincipal.

@Test
public void verifyNullPrincipal() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
    final Principal p = resolver.resolve(() -> null, CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler());
    assertNull(p);
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) Test(org.junit.Test)

Example 8 with PersonDirectoryPrincipalResolver

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

the class CasCoreAuthenticationPrincipalConfiguration method personDirectoryPrincipalResolver.

@Autowired
@RefreshScope
@Bean
@ConditionalOnMissingBean(name = "personDirectoryPrincipalResolver")
public PrincipalResolver personDirectoryPrincipalResolver(@Qualifier("attributeRepository") final IPersonAttributeDao attributeRepository, @Qualifier("principalFactory") final PrincipalFactory principalFactory) {
    final PersonDirectoryPrincipalResolver bean = new PersonDirectoryPrincipalResolver();
    bean.setAttributeRepository(attributeRepository);
    bean.setPrincipalAttributeName(casProperties.getPersonDirectory().getPrincipalAttribute());
    bean.setReturnNullIfNoAttributes(casProperties.getPersonDirectory().isReturnNull());
    bean.setPrincipalFactory(principalFactory);
    return bean;
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Autowired(org.springframework.beans.factory.annotation.Autowired) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with PersonDirectoryPrincipalResolver

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

the class CasCoreAuthenticationPrincipalConfiguration method personDirectoryPrincipalResolver.

@Autowired
@RefreshScope
@Bean
@ConditionalOnMissingBean(name = "personDirectoryPrincipalResolver")
public PrincipalResolver personDirectoryPrincipalResolver(@Qualifier("principalFactory") final PrincipalFactory principalFactory) {
    final PersonDirectoryPrincipalResolver bean = new PersonDirectoryPrincipalResolver(attributeRepository, principalFactory, casProperties.getPersonDirectory().isReturnNull(), casProperties.getPersonDirectory().getPrincipalAttribute());
    final ChainingPrincipalResolver resolver = new ChainingPrincipalResolver();
    if (!attributeRepositories.isEmpty()) {
        LOGGER.debug("Attribute repository sources are defined and available for the principal resolution chain. " + "The principal resolver will use a combination of attributes collected from attribute repository sources " + "and whatever may be collected during the authentication phase where results are eventually merged.");
        resolver.setChain(CollectionUtils.wrapList(bean, new EchoingPrincipalResolver()));
    } else {
        LOGGER.debug("Attribute repository sources are not available for principal resolution so principal resolver will echo " + "back the principal resolved during authentication directly.");
        resolver.setChain(CollectionUtils.wrapList(new EchoingPrincipalResolver()));
    }
    return resolver;
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Autowired(org.springframework.beans.factory.annotation.Autowired) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with PersonDirectoryPrincipalResolver

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

the class PersonDirectoryPrincipalResolverTests method verifyChainingResolverDistinct.

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

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