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