Search in sources :

Example 6 with StubPersonAttributeDao

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);
}
Also used : HashMap(java.util.HashMap) DefaultAccessStrategyMapper(org.apereo.cas.mgmt.services.web.factory.DefaultAccessStrategyMapper) DefaultProxyPolicyMapper(org.apereo.cas.mgmt.services.web.factory.DefaultProxyPolicyMapper) DefaultRegisteredServiceMapper(org.apereo.cas.mgmt.services.web.factory.DefaultRegisteredServiceMapper) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) RegisteredServiceSimpleFormController(org.apereo.cas.mgmt.services.web.RegisteredServiceSimpleFormController) List(java.util.List) DefaultRegisteredServiceFactory(org.apereo.cas.mgmt.services.web.factory.DefaultRegisteredServiceFactory) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) DefaultUsernameAttributeProviderMapper(org.apereo.cas.mgmt.services.web.factory.DefaultUsernameAttributeProviderMapper) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) AttributeFormDataPopulator(org.apereo.cas.mgmt.services.web.factory.AttributeFormDataPopulator) Before(org.junit.Before)

Example 7 with StubPersonAttributeDao

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"));
}
Also used : lombok.val(lombok.val) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with StubPersonAttributeDao

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);
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with StubPersonAttributeDao

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());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) RefreshAutoConfiguration(org.springframework.cloud.autoconfigure.RefreshAutoConfiguration) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Tag(org.junit.jupiter.api.Tag) Credential(org.apereo.cas.authentication.Credential) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) PrincipalFactoryUtils(org.apereo.cas.authentication.principal.PrincipalFactoryUtils) lombok.val(lombok.val) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) IPersonAttributeDaoFilter(org.apereo.services.persondir.IPersonAttributeDaoFilter) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions(org.junit.jupiter.api.Assertions) PrincipalAttributesCoreProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesCoreProperties) Optional(java.util.Optional) CoreAuthenticationUtils(org.apereo.cas.authentication.CoreAuthenticationUtils) Collections(java.util.Collections) CoreAuthenticationTestUtils(org.apereo.cas.authentication.CoreAuthenticationTestUtils) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with StubPersonAttributeDao

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"));
}
Also used : lombok.val(lombok.val) ArrayList(java.util.ArrayList) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

StubPersonAttributeDao (org.apereo.services.persondir.support.StubPersonAttributeDao)13 lombok.val (lombok.val)12 Test (org.junit.jupiter.api.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 HashMap (java.util.HashMap)8 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DefaultPrincipalElectionStrategy (org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy)3 IPersonAttributeDaoFilter (org.apereo.services.persondir.IPersonAttributeDaoFilter)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Stream (java.util.stream.Stream)2 CoreAuthenticationTestUtils (org.apereo.cas.authentication.CoreAuthenticationTestUtils)2 CoreAuthenticationUtils (org.apereo.cas.authentication.CoreAuthenticationUtils)2 Credential (org.apereo.cas.authentication.Credential)2 PrincipalFactoryUtils (org.apereo.cas.authentication.principal.PrincipalFactoryUtils)2 CachingPrincipalAttributesRepository (org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)2