Search in sources :

Example 1 with CaseInsensitiveNamedPersonImpl

use of org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl 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 CaseInsensitiveNamedPersonImpl

use of org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl in project uPortal by Jasig.

the class ImpersonationStatusPersonAttributeDao method getPeopleWithMultivaluedAttributes.

@Override
public Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(Map<String, List<Object>> query) {
    // default (per spec?)
    Set<IPersonAttributes> rslt = null;
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("invoking getPeopleWithMultivaluedAttributes(" + query + ")");
    }
    final IUsernameAttributeProvider usernameAttributeProvider = super.getUsernameAttributeProvider();
    final String queryUid = usernameAttributeProvider.getUsernameFromQuery(query);
    if (queryUid == null) {
        this.logger.debug("No username attribute found in query, returning null");
    } else {
        final HttpServletRequest req = portalRequestUtils.getCurrentPortalRequest();
        final IPerson person = personManager.getPerson(req);
        final String currentUid = person.getUserName();
        if (currentUid.equals(queryUid)) {
            final String value = identitySwapperManager.isImpersonating(req) ? "true" : "false";
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Gathering attributes for the current user [" + currentUid + "];  impersonating=" + value);
            }
            final List<Object> values = Collections.singletonList((Object) value);
            final Map<String, List<Object>> attrs = Collections.singletonMap(IMPERSONATING_ATTRIBUTE_NAME, values);
            final IPersonAttributes ipa = new CaseInsensitiveNamedPersonImpl(currentUid, attrs);
            rslt = Collections.singleton(ipa);
        }
    }
    return rslt;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IUsernameAttributeProvider(org.apereo.services.persondir.support.IUsernameAttributeProvider) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) List(java.util.List) CaseInsensitiveNamedPersonImpl(org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl)

Example 3 with CaseInsensitiveNamedPersonImpl

use of org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl in project cas by apereo.

the class CouchbasePersonAttributeDao method getPerson.

@Override
@SneakyThrows
public IPersonAttributes getPerson(final String uid) {
    final N1qlQueryResult result = couchbase.query(couchbaseProperties.getUsernameAttribute(), uid);
    final Map<String, ?> attributes;
    if (result.allRows().isEmpty()) {
        LOGGER.debug("Couchbase query did not return any results/rows.");
        attributes = new LinkedHashMap<>();
    } else {
        attributes = result.allRows().stream().filter(row -> row.value().containsKey(couchbase.getBucket().name())).filter(row -> {
            final JsonObject value = (JsonObject) row.value().get(couchbase.getBucket().name());
            return value.containsKey(couchbaseProperties.getUsernameAttribute());
        }).map(row -> (JsonObject) row.value().get(couchbase.getBucket().name())).map(entity -> couchbase.collectAttributesFromEntity(entity, s -> !s.equals(couchbaseProperties.getUsernameAttribute())).entrySet()).flatMap(Collection::stream).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
    return new CaseInsensitiveNamedPersonImpl(uid, stuffAttributesIntoList(attributes));
}
Also used : IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult) CouchbasePrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.CouchbasePrincipalAttributesProperties) SneakyThrows(lombok.SneakyThrows) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BasePersonAttributeDao(org.apereo.services.persondir.support.BasePersonAttributeDao) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) JsonObject(com.couchbase.client.java.document.json.JsonObject) 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) JsonObject(com.couchbase.client.java.document.json.JsonObject) Collection(java.util.Collection) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult) CaseInsensitiveNamedPersonImpl(org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl) SneakyThrows(lombok.SneakyThrows)

Example 4 with CaseInsensitiveNamedPersonImpl

use of org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl in project cas by apereo.

the class OktaPersonAttributeDao method getPerson.

@Override
@SuppressWarnings("JavaUtilDate")
public IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter) {
    val attributes = new HashMap<String, Object>();
    val user = oktaClient.getUser(uid);
    FunctionUtils.doIfNotNull(user.getActivated(), attribute -> attributes.put("oktaUserActivatedDate", user.getActivated().getTime()));
    FunctionUtils.doIfNotNull(user.getCreated(), attribute -> attributes.put("oktaUserCreatedDate", user.getCreated().getTime()));
    FunctionUtils.doIfNotNull(user.getLastLogin(), attribute -> attributes.put("oktaUserLastLoginDate", user.getLastLogin().getTime()));
    FunctionUtils.doIfNotNull(user.getLastUpdated(), attribute -> attributes.put("oktaUserLastUpdatedDate", user.getLastUpdated().getTime()));
    FunctionUtils.doIfNotNull(user.getPasswordChanged(), attribute -> attributes.put("oktaUserPasswordChangedDate", user.getPasswordChanged().getTime()));
    FunctionUtils.doIfNotNull(user.getId(), attribute -> attributes.put("oktaUserId", attribute));
    FunctionUtils.doIfNotNull(user.getStatus(), attribute -> attributes.put("oktaUserStatus", attribute.toString()));
    FunctionUtils.doIfNotNull(user.getType(), attribute -> attributes.put("oktaUserType", attribute));
    val profile = user.getProfile();
    FunctionUtils.doIfNotNull(profile.getCity(), attribute -> attributes.put("oktaCity", attribute));
    FunctionUtils.doIfNotNull(profile.getCostCenter(), attribute -> attributes.put("oktaCostCenter", attribute));
    FunctionUtils.doIfNotNull(profile.getCountryCode(), attribute -> attributes.put("oktaCountryCode", attribute));
    FunctionUtils.doIfNotNull(profile.getDepartment(), attribute -> attributes.put("oktaDepartment", attribute));
    FunctionUtils.doIfNotNull(profile.getDisplayName(), attribute -> attributes.put("oktaDisplayName", attribute));
    FunctionUtils.doIfNotNull(profile.getDivision(), attribute -> attributes.put("oktaDivision", attribute));
    FunctionUtils.doIfNotNull(profile.getEmail(), attribute -> attributes.put("oktaEmail", attribute));
    FunctionUtils.doIfNotNull(profile.getEmployeeNumber(), attribute -> attributes.put("oktaEmployeeNumber", attribute));
    FunctionUtils.doIfNotNull(profile.getFirstName(), attribute -> attributes.put("oktaFirstName", attribute));
    FunctionUtils.doIfNotNull(profile.getHonorificPrefix(), attribute -> attributes.put("oktaPrefix", attribute));
    FunctionUtils.doIfNotNull(profile.getHonorificSuffix(), attribute -> attributes.put("oktaSuffix", attribute));
    FunctionUtils.doIfNotNull(profile.getLastName(), attribute -> attributes.put("oktaLastName", attribute));
    FunctionUtils.doIfNotNull(profile.getLocale(), attribute -> attributes.put("oktaLocale", attribute));
    FunctionUtils.doIfNotNull(profile.getManager(), attribute -> attributes.put("oktaManager", attribute));
    FunctionUtils.doIfNotNull(profile.getManagerId(), attribute -> attributes.put("oktaManagerId", attribute));
    FunctionUtils.doIfNotNull(profile.getMiddleName(), attribute -> attributes.put("oktaMiddleName", attribute));
    FunctionUtils.doIfNotNull(profile.getMobilePhone(), attribute -> attributes.put("oktaMobilePhone", attribute));
    FunctionUtils.doIfNotNull(profile.getNickName(), attribute -> attributes.put("oktaNickName", attribute));
    FunctionUtils.doIfNotNull(profile.getOrganization(), attribute -> attributes.put("oktaOrganization", attribute));
    FunctionUtils.doIfNotNull(profile.getPostalAddress(), attribute -> attributes.put("oktaPostalAddress", attribute));
    FunctionUtils.doIfNotNull(profile.getPreferredLanguage(), attribute -> attributes.put("oktaPreferredLanguage", attribute));
    FunctionUtils.doIfNotNull(profile.getPrimaryPhone(), attribute -> attributes.put("oktaPrimaryPhone", attribute));
    FunctionUtils.doIfNotNull(profile.getSecondEmail(), attribute -> attributes.put("oktaSecondEmail", attribute));
    FunctionUtils.doIfNotNull(profile.getState(), attribute -> attributes.put("oktaState", attribute));
    FunctionUtils.doIfNotNull(profile.getStreetAddress(), attribute -> attributes.put("oktaStreetAddress", attribute));
    FunctionUtils.doIfNotNull(profile.getTimezone(), attribute -> attributes.put("oktaTimezone", attribute));
    FunctionUtils.doIfNotNull(profile.getTitle(), attribute -> attributes.put("oktaTitle", attribute));
    FunctionUtils.doIfNotNull(profile.getLogin(), attribute -> attributes.put("oktaLogin", attribute));
    return new CaseInsensitiveNamedPersonImpl(uid, stuffAttributesIntoList(attributes));
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) CaseInsensitiveNamedPersonImpl(org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl)

Aggregations

CaseInsensitiveNamedPersonImpl (org.apereo.services.persondir.support.CaseInsensitiveNamedPersonImpl)4 List (java.util.List)3 IPersonAttributes (org.apereo.services.persondir.IPersonAttributes)3 IUsernameAttributeProvider (org.apereo.services.persondir.support.IUsernameAttributeProvider)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 SneakyThrows (lombok.SneakyThrows)2 Slf4j (lombok.extern.slf4j.Slf4j)2 lombok.val (lombok.val)2 CouchbaseClientFactory (org.apereo.cas.couchbase.core.CouchbaseClientFactory)2 CollectionUtils (org.apereo.cas.util.CollectionUtils)2 BasePersonAttributeDao (org.apereo.services.persondir.support.BasePersonAttributeDao)2 SimpleUsernameAttributeProvider (org.apereo.services.persondir.support.SimpleUsernameAttributeProvider)2