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);
}
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);
}
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;
}
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;
}
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());
}
Aggregations