Search in sources :

Example 1 with ContainerCriteria

use of org.springframework.ldap.query.ContainerCriteria in project apollo by ctripcorp.

the class LdapUserService method findByUserIds.

@Override
public List<UserInfo> findByUserIds(List<String> userIds) {
    if (CollectionUtils.isEmpty(userIds)) {
        return Collections.emptyList();
    }
    if (StringUtils.isNotBlank(groupSearch)) {
        return searchUserInfoByGroup(groupBase, groupSearch, null, userIds);
    }
    ContainerCriteria criteria = query().where(loginIdAttrName).is(userIds.get(0));
    userIds.stream().skip(1).forEach(userId -> criteria.or(loginIdAttrName).is(userId));
    return ldapTemplate.search(ldapQueryCriteria().and(criteria), ldapUserInfoMapper);
}
Also used : ContainerCriteria(org.springframework.ldap.query.ContainerCriteria)

Example 2 with ContainerCriteria

use of org.springframework.ldap.query.ContainerCriteria in project apollo by ctripcorp.

the class LdapUserService method searchUsers.

@Override
public List<UserInfo> searchUsers(String keyword, int offset, int limit) {
    List<UserInfo> users = new ArrayList<>();
    if (StringUtils.isNotBlank(groupSearch)) {
        List<UserInfo> userListByGroup = searchUserInfoByGroup(groupBase, groupSearch, keyword, null);
        users.addAll(userListByGroup);
        return users.stream().collect(collectingAndThen(toCollection(() -> new TreeSet<>((o1, o2) -> {
            if (o1.getUserId().equals(o2.getUserId())) {
                return 0;
            }
            return -1;
        })), ArrayList::new));
    }
    ContainerCriteria criteria = ldapQueryCriteria();
    if (!Strings.isNullOrEmpty(keyword)) {
        criteria.and(query().where(loginIdAttrName).like(keyword + "*").or(userDisplayNameAttrName).like(keyword + "*"));
    }
    users = ldapTemplate.search(criteria, ldapUserInfoMapper);
    return users;
}
Also used : Arrays(java.util.Arrays) LdapName(javax.naming.ldap.LdapName) Autowired(org.springframework.beans.factory.annotation.Autowired) LdapUtils(org.springframework.ldap.support.LdapUtils) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) LdapTemplate(org.springframework.ldap.core.LdapTemplate) StringUtils(org.apache.commons.lang3.StringUtils) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) Value(org.springframework.beans.factory.annotation.Value) Collectors.toCollection(java.util.stream.Collectors.toCollection) Strings(com.google.common.base.Strings) Attribute(javax.naming.directory.Attribute) LdapExtendProperties(com.ctrip.framework.apollo.portal.spi.configuration.LdapExtendProperties) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SearchScope(org.springframework.ldap.query.SearchScope) ContainerCriteria(org.springframework.ldap.query.ContainerCriteria) Set(java.util.Set) Sets(com.google.common.collect.Sets) List(java.util.List) ContextMapper(org.springframework.ldap.core.ContextMapper) AttributesMapper(org.springframework.ldap.core.AttributesMapper) LdapProperties(com.ctrip.framework.apollo.portal.spi.configuration.LdapProperties) LdapQueryBuilder.query(org.springframework.ldap.query.LdapQueryBuilder.query) CollectionUtils(org.springframework.util.CollectionUtils) Collections(java.util.Collections) UserService(com.ctrip.framework.apollo.portal.spi.UserService) ArrayList(java.util.ArrayList) ContainerCriteria(org.springframework.ldap.query.ContainerCriteria) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 3 with ContainerCriteria

use of org.springframework.ldap.query.ContainerCriteria in project apollo by ctripcorp.

the class LdapUserService method ldapQueryCriteria.

/**
 * 查询条件
 */
private ContainerCriteria ldapQueryCriteria() {
    ContainerCriteria criteria = query().searchScope(SearchScope.SUBTREE).where("objectClass").is(objectClassAttrName);
    if (memberOf.length > 0 && !StringUtils.isEmpty(memberOf[0])) {
        ContainerCriteria memberOfFilters = query().where(MEMBER_OF_ATTR_NAME).is(memberOf[0]);
        Arrays.stream(memberOf).skip(1).forEach(filter -> memberOfFilters.or(MEMBER_OF_ATTR_NAME).is(filter));
        criteria.and(memberOfFilters);
    }
    return criteria;
}
Also used : ContainerCriteria(org.springframework.ldap.query.ContainerCriteria)

Aggregations

ContainerCriteria (org.springframework.ldap.query.ContainerCriteria)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)1 UserService (com.ctrip.framework.apollo.portal.spi.UserService)1 LdapExtendProperties (com.ctrip.framework.apollo.portal.spi.configuration.LdapExtendProperties)1 LdapProperties (com.ctrip.framework.apollo.portal.spi.configuration.LdapProperties)1 Strings (com.google.common.base.Strings)1 Sets (com.google.common.collect.Sets)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Collectors.collectingAndThen (java.util.stream.Collectors.collectingAndThen)1 Collectors.toCollection (java.util.stream.Collectors.toCollection)1 Attribute (javax.naming.directory.Attribute)1 LdapName (javax.naming.ldap.LdapName)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1