コード例 #1
0
  /**
   * Retrieve the input attributes from the Active Directory for the given search query
   *
   * <p>Method getAttributes.
   *
   * @param searchBase String
   * @return List<User>
   * @throws NamingException
   */
  private final List<User> getAttributes(String searchBase) throws NamingException {
    LOGGER.info(">> getAttributes()");

    NamingEnumeration<SearchResult> results =
        localInitialLdapContext.search(searchBase, searchFilter, searchctls);

    List<User> users = new ArrayList<User>();
    User user = null;

    while (results.hasMoreElements()) {
      user = new User();
      SearchResult searchResult = results.next();
      Attributes attrs = searchResult.getAttributes();

      if (attrs != null && attrs.size() != 0) {
        Attribute attribute = null;

        String[] retrieveAttributes = parameters.getRetrieveAttributes();
        String[] attributesValues = new String[retrieveAttributes.length];
        for (int i = 0; i < retrieveAttributes.length; i++) {
          attribute = attrs.get(retrieveAttributes[i]);
          if (attribute != null && attribute.get() != null) {
            if (!isNullOrEmpty(attribute.get().toString())) {
              attributesValues[i] = attribute.get().toString();
            }
          }
        }
        user.setAttributeValues(attributesValues);
      }
      users.add(user);
    }

    LOGGER.info("<< getAttributes()");
    return users;
  }
コード例 #2
0
  /** Method setSearchParameters. */
  private void setSearchParameters() {
    LOGGER.info(">> setSearchParameters()");

    // Search controls and setting up the returning attributes
    searchctls = new SearchControls();
    searchctls.setReturningAttributes(parameters.getRetrieveAttributes());

    // Set the search scope. You can change this as according your
    // structure.
    // Remember this value has effect on performance.
    // Example: setting the scope to Subtree.
    searchctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    // Set the search filter. Change as according by changing the values in
    // properties class.
    searchFilter =
        new StringBuilder("(&(objectClass=")
            .append(Properties.FILTER_OBJECT_CLASS)
            .append(")(objectCategory=")
            .append(Properties.FILTER_OBJECT_CATEGORY)
            .append("))")
            .toString();

    LOGGER.info("<< setSearchParameters");
  }