org.springframework.ldap.filter.OrFilter Java Examples

The following examples show how to use org.springframework.ldap.filter.OrFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapClient.java    From taskana with Apache License 2.0 6 votes vote down vote up
public List<AccessIdRepresentationModel> searchGroupsByName(final String name)
    throws InvalidArgumentException {
  LOGGER.debug("entry to searchGroupsByName(name = {}).", name);
  isInitOrFail();
  testMinSearchForLength(name);

  final AndFilter andFilter = new AndFilter();
  andFilter.and(new EqualsFilter(getGroupSearchFilterName(), getGroupSearchFilterValue()));
  final OrFilter orFilter = new OrFilter();
  orFilter.or(new WhitespaceWildcardsFilter(getGroupNameAttribute(), name));
  if (!CN.equals(getGroupNameAttribute())) {
    orFilter.or(new WhitespaceWildcardsFilter(CN, name));
  }
  andFilter.and(orFilter);

  final List<AccessIdRepresentationModel> accessIds =
      ldapTemplate.search(
          getGroupSearchBase(),
          andFilter.encode(),
          SearchControls.SUBTREE_SCOPE,
          getLookUpGroupAttributesToReturn(),
          new GroupContextMapper());
  LOGGER.debug("Exit from searchGroupsByName. Retrieved the following groups: {}", accessIds);
  return accessIds;
}
 
Example #2
Source File: LdapClient.java    From taskana with Apache License 2.0 5 votes vote down vote up
public List<AccessIdRepresentationModel> searchUsersByNameOrAccessId(final String name)
    throws InvalidArgumentException {
  LOGGER.debug("entry to searchUsersByNameOrAccessId(name = {}).", name);
  isInitOrFail();
  testMinSearchForLength(name);

  final AndFilter andFilter = new AndFilter();
  andFilter.and(new EqualsFilter(getUserSearchFilterName(), getUserSearchFilterValue()));
  final OrFilter orFilter = new OrFilter();

  orFilter.or(new WhitespaceWildcardsFilter(getUserFirstnameAttribute(), name));
  orFilter.or(new WhitespaceWildcardsFilter(getUserLastnameAttribute(), name));
  orFilter.or(new WhitespaceWildcardsFilter(getUserIdAttribute(), name));
  andFilter.and(orFilter);

  String[] userAttributesToReturn = {
    getUserFirstnameAttribute(), getUserLastnameAttribute(), getUserIdAttribute()
  };

  final List<AccessIdRepresentationModel> accessIds =
      ldapTemplate.search(
          getUserSearchBase(),
          andFilter.encode(),
          SearchControls.SUBTREE_SCOPE,
          userAttributesToReturn,
          new UserContextMapper());
  LOGGER.debug(
      "exit from searchUsersByNameOrAccessId. Retrieved the following users: {}.", accessIds);
  return accessIds;
}
 
Example #3
Source File: LdapPrincipalDaoImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
public <T> List<T> search(Class<T> type, Map<String, Object> criteria) {
    AndFilter filter = new AndFilter();
    
    for (Map.Entry<String, Object> entry : criteria.entrySet()) {
        //attempting to handle null values to prevent NPEs in this code.
        if (entry.getValue() == null) {
            entry.setValue("null");
        }
        if (entry.getValue() instanceof Iterable) {
            OrFilter orFilter = new OrFilter();
            for (String value : (Iterable<String>) entry.getValue()) {
                if (value.startsWith("!")) {
                    orFilter.or(new NotFilter(new LikeFilter(entry.getKey(), value.substring(1))));
                } else {
                    orFilter.or(new LikeFilter(entry.getKey(), value));
                }
            }
            filter.and(orFilter);
        }
        else {
            if (((String)entry.getValue()).startsWith("!")) {
                filter.and(new NotFilter(new LikeFilter(entry.getKey(), ((String)entry.getValue()).substring(1))));
            } else {
                filter.and(new LikeFilter(entry.getKey(), (String) entry.getValue()));
            }
        }
    };
    
    info("Using filter ", filter);

    debug("Looking up mapper for ", type.getSimpleName());
    final ContextMapper customMapper = contextMappers.get(type.getSimpleName());

    ContextMapperCallbackHandler callbackHandler = new CustomContextMapperCallbackHandler(customMapper);
    
    try {
        getLdapTemplate().search(DistinguishedName.EMPTY_PATH, 
                                 filter.encode(), 
                                 getSearchControls(), callbackHandler);
    }
    catch (SizeLimitExceededException e) {
        // Ignore this. We want to limit our results.
    }

    return callbackHandler.getList();
}