Search in sources :

Example 1 with IPersonAttributeDaoFilter

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));
}
Also used : lombok.val(lombok.val) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) CouchbasePrincipalAttributesProperties(org.apereo.cas.configuration.model.support.couchbase.authentication.CouchbasePrincipalAttributesProperties) SneakyThrows(lombok.SneakyThrows) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) BasePersonAttributeDao(org.apereo.services.persondir.support.BasePersonAttributeDao) Set(java.util.Set) Collectors(java.util.stream.Collectors) IPersonAttributeDaoFilter(org.apereo.services.persondir.IPersonAttributeDaoFilter) ArrayList(java.util.ArrayList) CouchbaseClientFactory(org.apereo.cas.couchbase.core.CouchbaseClientFactory) LinkedHashMap(java.util.LinkedHashMap) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SimpleUsernameAttributeProvider(org.apereo.services.persondir.support.SimpleUsernameAttributeProvider) IUsernameAttributeProvider(org.apereo.services.persondir.support.IUsernameAttributeProvider) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) CaseInsensitiveNamedPersonImpl(org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl) LinkedHashSet(java.util.LinkedHashSet) Collection(java.util.Collection) CaseInsensitiveNamedPersonImpl(org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl) LinkedHashMap(java.util.LinkedHashMap) SneakyThrows(lombok.SneakyThrows)

Example 2 with IPersonAttributeDaoFilter

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());
}
Also used : lombok.val(lombok.val) IPersonAttributeDaoFilter(org.apereo.services.persondir.IPersonAttributeDaoFilter) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.jupiter.api.Test)

Example 3 with IPersonAttributeDaoFilter

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);
}
Also used : lombok.val(lombok.val) SneakyThrows(lombok.SneakyThrows) HttpStatus(org.apache.http.HttpStatus) BasePersonAttributeDao(org.apereo.services.persondir.support.BasePersonAttributeDao) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) EntityUtils(org.apache.http.util.EntityUtils) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) NamedPersonImpl(org.apereo.services.persondir.support.NamedPersonImpl) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) JsonNode(com.fasterxml.jackson.databind.JsonNode) OrSearchCondition(org.apache.cxf.jaxrs.ext.search.OrSearchCondition) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) LinkedHashSet(java.util.LinkedHashSet) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) HttpMethod(org.springframework.http.HttpMethod) FiqlParser(org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser) Set(java.util.Set) HttpUtils(org.apereo.cas.util.HttpUtils) Collectors(java.util.stream.Collectors) IPersonAttributeDaoFilter(org.apereo.services.persondir.IPersonAttributeDaoFilter) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SyncopePrincipalAttributesProperties(org.apereo.cas.configuration.model.support.syncope.SyncopePrincipalAttributesProperties) JacksonObjectMapperFactory(org.apereo.cas.util.serialization.JacksonObjectMapperFactory) HttpResponse(org.apache.http.HttpResponse) Optional(java.util.Optional) EncodingUtils(org.apereo.cas.util.EncodingUtils) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) NamedPersonImpl(org.apereo.services.persondir.support.NamedPersonImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

lombok.val (lombok.val)3 IPersonAttributeDaoFilter (org.apereo.services.persondir.IPersonAttributeDaoFilter)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 SneakyThrows (lombok.SneakyThrows)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CollectionUtils (org.apereo.cas.util.CollectionUtils)2 IPersonAttributes (org.apereo.services.persondir.IPersonAttributes)2 BasePersonAttributeDao (org.apereo.services.persondir.support.BasePersonAttributeDao)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1