use of org.apereo.services.persondir.IPersonAttributeDaoFilter in project cas by apereo.
the class CouchbasePersonAttributeDao method getPerson.
@Override
@SneakyThrows
public IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter) {
val query = String.format("%s = '%s'", couchbaseProperties.getUsernameAttribute(), uid);
val result = couchbase.select(query);
if (result.rowsAsObject().isEmpty()) {
LOGGER.debug("Couchbase query did not return any results/rows.");
return null;
}
val rows = result.rowsAsObject();
val attributes = new LinkedHashMap<String, Object>(rows.stream().filter(row -> row.containsKey(couchbase.getBucket())).map(row -> {
val document = row.getObject(couchbase.getBucket());
val results = CouchbaseClientFactory.collectAttributesFromEntity(document, s -> true);
return results.entrySet();
}).flatMap(Collection::stream).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
return new CaseInsensitiveNamedPersonImpl(uid, stuffAttributesIntoList(attributes));
}
use of org.apereo.services.persondir.IPersonAttributeDaoFilter in project cas by apereo.
the class CoreAuthenticationUtilsTests method verifyAttributeRepositoriesByFilter.
@Test
public void verifyAttributeRepositoriesByFilter() {
val repository = new StubPersonAttributeDao(CoreAuthenticationTestUtils.getAttributes()) {
@Override
public IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter) {
if (filter.choosePersonAttributeDao(this)) {
return super.getPerson(uid, filter);
}
return null;
}
};
var attrs = CoreAuthenticationUtils.retrieveAttributesFromAttributeRepository(repository, "casuser", Set.of("*"), Optional.of(CoreAuthenticationTestUtils.getPrincipal("casuser")));
assertTrue(attrs.containsKey("uid"));
assertTrue(attrs.containsKey("mail"));
assertTrue(attrs.containsKey("memberOf"));
attrs = CoreAuthenticationUtils.retrieveAttributesFromAttributeRepository(repository, "casuser", Set.of("Invalid"), Optional.of(CoreAuthenticationTestUtils.getPrincipal("casuser")));
assertTrue(attrs.isEmpty());
}
use of org.apereo.services.persondir.IPersonAttributeDaoFilter in project cas by apereo.
the class SyncopePersonAttributeDao method getPerson.
@Override
public IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter) {
val attributes = new HashMap<String, List<Object>>();
syncopeSearch(uid).filter(sr -> sr.has("result")).ifPresent(sr -> {
val result = sr.get("result").iterator();
if (result.hasNext()) {
attributes.putAll(SyncopeUserTOConverterUtils.convert(result.next()));
}
});
return new NamedPersonImpl(uid, attributes);
}
Aggregations