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