Search in sources :

Example 6 with IPersonAttributeDao

use of org.apereo.services.persondir.IPersonAttributeDao in project cas by apereo.

the class RegisteredServiceAttributeReleasePolicyTests method checkServiceAttributeFilterAllAttributesWithCachingTurnedOn.

@Test
public void checkServiceAttributeFilterAllAttributesWithCachingTurnedOn() {
    final ReturnAllAttributeReleasePolicy policy = new ReturnAllAttributeReleasePolicy();
    final Map<String, List<Object>> attributes = new HashMap<>();
    attributes.put("values", Arrays.asList(new Object[] { "v1", "v2", "v3" }));
    attributes.put("cn", Arrays.asList(new Object[] { "commonName" }));
    attributes.put("username", Arrays.asList(new Object[] { "uid" }));
    final IPersonAttributeDao dao = new StubPersonAttributeDao(attributes);
    final IPersonAttributes person = mock(IPersonAttributes.class);
    when(person.getName()).thenReturn("uid");
    when(person.getAttributes()).thenReturn(attributes);
    final CachingPrincipalAttributesRepository repository = new CachingPrincipalAttributesRepository(TimeUnit.MILLISECONDS.name(), 100);
    repository.setAttributeRepository(dao);
    final Principal p = new DefaultPrincipalFactory().createPrincipal("uid", Collections.singletonMap("mail", "final@example.com"));
    policy.setPrincipalAttributesRepository(repository);
    final Map<String, Object> attr = policy.getAttributes(p, CoreAuthenticationTestUtils.getRegisteredService());
    assertEquals(attr.size(), attributes.size());
}
Also used : HashMap(java.util.HashMap) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) List(java.util.List) CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository) Principal(org.apereo.cas.authentication.principal.Principal) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ArrayList (java.util.ArrayList)6 IPersonAttributeDao (org.apereo.services.persondir.IPersonAttributeDao)6 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)5 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)5 Bean (org.springframework.context.annotation.Bean)5 PrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties)3 HashMap (java.util.HashMap)1 List (java.util.List)1 SearchControls (javax.naming.directory.SearchControls)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 Principal (org.apereo.cas.authentication.principal.Principal)1 CachingPrincipalAttributesRepository (org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)1 InternalGroovyScriptDao (org.apereo.cas.authentication.principal.resolvers.InternalGroovyScriptDao)1 IPersonAttributes (org.apereo.services.persondir.IPersonAttributes)1 GroovyPersonAttributeDao (org.apereo.services.persondir.support.GroovyPersonAttributeDao)1 GrouperPersonAttributeDao (org.apereo.services.persondir.support.GrouperPersonAttributeDao)1 JsonBackedComplexStubPersonAttributeDao (org.apereo.services.persondir.support.JsonBackedComplexStubPersonAttributeDao)1 StubPersonAttributeDao (org.apereo.services.persondir.support.StubPersonAttributeDao)1 AbstractJdbcPersonAttributeDao (org.apereo.services.persondir.support.jdbc.AbstractJdbcPersonAttributeDao)1 MultiRowJdbcPersonAttributeDao (org.apereo.services.persondir.support.jdbc.MultiRowJdbcPersonAttributeDao)1