use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.
the class ShibbolethPersonAttributeDao method getPerson.
@Override
public IPersonAttributes getPerson(final String uid) {
final AttributeResolutionContext attributeResolutionContext = new AttributeResolutionContext();
attributeResolutionContext.setPrincipal(uid);
try {
this.attributeResolver.resolveAttributes(attributeResolutionContext);
final Map<String, List<Object>> attributes = attributeResolutionContext.getResolvedIdPAttributes().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, p -> p.getValue().getValues().stream().map(IdPAttributeValue::getValue).collect(Collectors.toList())));
return new NamedPersonImpl(uid, attributes);
} catch (final ResolutionException e) {
throw Throwables.propagate(e);
}
}
use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.
the class AbstractPrincipalAttributesRepository method retrievePersonAttributesToPrincipalAttributes.
/**
* Obtains attributes first from the repository by calling
* {@link org.apereo.services.persondir.IPersonAttributeDao#getPerson(String)}.
*
* @param id the person id to locate in the attribute repository
* @return the map of attributes
*/
protected Map<String, List<Object>> retrievePersonAttributesToPrincipalAttributes(final String id) {
final IPersonAttributes attrs = getAttributeRepository().getPerson(id);
if (attrs == null) {
LOGGER.debug("Could not find principal [{}] in the repository so no attributes are returned.", id);
return Collections.emptyMap();
}
final Map<String, List<Object>> attributes = attrs.getAttributes();
if (attributes == null) {
LOGGER.debug("Principal [{}] has no attributes and so none are returned.", id);
return Collections.emptyMap();
}
return attributes;
}
use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.
the class PersonDirectoryPrincipalResolver method retrievePersonAttributes.
/**
* Retrieve person attributes map.
*
* @param principalId the principal id
* @param credential the credential whose id we have extracted. This is passed so that implementations
* can extract useful bits of authN info such as attributes into the principal.
* @return the map
*/
protected Map<String, List<Object>> retrievePersonAttributes(final String principalId, final Credential credential) {
final IPersonAttributes personAttributes = this.attributeRepository.getPerson(principalId);
final Map<String, List<Object>> attributes;
if (personAttributes == null) {
attributes = null;
} else {
attributes = personAttributes.getAttributes();
}
return attributes;
}
use of org.apereo.services.persondir.IPersonAttributes 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());
}
use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.
the class AbstractCachingPrincipalAttributesRepositoryTests method setUp.
@Before
public void setUp() {
attributes = new HashMap<>();
attributes.put("a1", Arrays.asList("v1", "v2", "v3"));
List email = new ArrayList<>();
email.add("final@example.com");
attributes.put(MAIL, email);
attributes.put("a6", Arrays.asList("v16", "v26", "v63"));
attributes.put("a2", Arrays.asList("v4"));
attributes.put("username", Arrays.asList("uid"));
this.dao = mock(IPersonAttributeDao.class);
final IPersonAttributes person = mock(IPersonAttributes.class);
when(person.getName()).thenReturn("uid");
when(person.getAttributes()).thenReturn(attributes);
when(dao.getPerson(any(String.class))).thenReturn(person);
email = new ArrayList<>();
email.add("final@school.com");
this.principal = this.principalFactory.createPrincipal("uid", Collections.singletonMap(MAIL, email));
}
Aggregations