use of org.apereo.services.persondir.support.StubPersonAttributeDao in project cas by apereo.
the class RegisteredServiceSimpleFormControllerTests method setUp.
@Before
public void setUp() throws Exception {
final Map<String, List<Object>> attributes = new HashMap<>();
attributes.put(TEST_ID, Arrays.asList(new Object[] { TEST_ID }));
this.repository = new StubPersonAttributeDao();
this.repository.setBackingMap(attributes);
this.registeredServiceFactory = new DefaultRegisteredServiceFactory(new DefaultAccessStrategyMapper(), policyMapper, new DefaultProxyPolicyMapper(), new DefaultRegisteredServiceMapper(), new DefaultUsernameAttributeProviderMapper(), Collections.singletonList(new AttributeFormDataPopulator(this.repository)));
this.manager = new DefaultServicesManager(new InMemoryServiceRegistry());
this.controller = new RegisteredServiceSimpleFormController(this.manager, this.registeredServiceFactory);
}
use of org.apereo.services.persondir.support.StubPersonAttributeDao in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyChainingResolverOverwritePrincipal.
@Test
public void verifyChainingResolverOverwritePrincipal() {
val context1 = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger())).attributeRepository(CoreAuthenticationTestUtils.getAttributeRepository()).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalNameTransformer(formUserId -> formUserId).useCurrentPrincipalId(false).resolveAttributes(true).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
val resolver = new PersonDirectoryPrincipalResolver(context1);
val context2 = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger())).attributeRepository(new StubPersonAttributeDao(Collections.singletonMap("principal", CollectionUtils.wrap("changedPrincipal")))).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalAttributeNames("principal").principalNameTransformer(formUserId -> formUserId).useCurrentPrincipalId(false).resolveAttributes(true).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
val resolver2 = new PersonDirectoryPrincipalResolver(context2);
val chain = new ChainingPrincipalResolver(new DefaultPrincipalElectionStrategy(), casProperties);
chain.setChain(Arrays.asList(new EchoingPrincipalResolver(), resolver, resolver2));
val p = chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), Optional.of(CoreAuthenticationTestUtils.getPrincipal("somethingelse", Collections.singletonMap(ATTR_1, List.of("value")))), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
assertNotNull(p);
assertEquals("changedPrincipal", p.getId());
assertEquals(7, p.getAttributes().size());
assertTrue(p.getAttributes().containsKey(ATTR_1));
assertTrue(p.getAttributes().containsKey("principal"));
}
use of org.apereo.services.persondir.support.StubPersonAttributeDao in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyNullAttributes.
@Test
public void verifyNullAttributes() {
val context = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger())).attributeRepository(new StubPersonAttributeDao(new HashMap<>(0))).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(true).principalNameTransformer(String::trim).principalAttributeNames(CoreAuthenticationTestUtils.CONST_USERNAME).useCurrentPrincipalId(false).resolveAttributes(true).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
val resolver = new PersonDirectoryPrincipalResolver(context);
val c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
val p = resolver.resolve(c, Optional.empty());
assertNull(p);
}
use of org.apereo.services.persondir.support.StubPersonAttributeDao in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyMultiplePrincipalAttributeNamesNotFound.
@Test
public void verifyMultiplePrincipalAttributeNamesNotFound() {
val context1 = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger())).attributeRepository(CoreAuthenticationTestUtils.getAttributeRepository()).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalNameTransformer(formUserId -> formUserId).useCurrentPrincipalId(false).resolveAttributes(true).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
val resolver = new PersonDirectoryPrincipalResolver(context1);
val context2 = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger())).attributeRepository(new StubPersonAttributeDao(Collections.singletonMap("something", CollectionUtils.wrap("principal-id")))).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalNameTransformer(formUserId -> formUserId).useCurrentPrincipalId(false).principalAttributeNames(" invalid, ").resolveAttributes(true).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
val resolver2 = new PersonDirectoryPrincipalResolver(context2);
val chain = new ChainingPrincipalResolver(new DefaultPrincipalElectionStrategy(), casProperties);
chain.setChain(Arrays.asList(new EchoingPrincipalResolver(), resolver, resolver2));
val p = chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), Optional.of(CoreAuthenticationTestUtils.getPrincipal("somethingelse", Collections.singletonMap(ATTR_1, List.of("value")))), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
assertNotNull(p);
assertEquals("test", p.getId());
}
use of org.apereo.services.persondir.support.StubPersonAttributeDao in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyNullAttributeValues.
@Test
public void verifyNullAttributeValues() {
val attributes = new ArrayList<>();
attributes.add(null);
val context = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger())).attributeRepository(new StubPersonAttributeDao(Map.of("a", attributes))).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalNameTransformer(formUserId -> formUserId).useCurrentPrincipalId(false).resolveAttributes(true).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
val resolver = new PersonDirectoryPrincipalResolver(context);
val principal = resolver.resolve((Credential) () -> "a");
assertTrue(principal.getAttributes().containsKey("a"));
}
Aggregations