private Vector getAttribute(String entryDN, String attr) {
    Vector v = new Vector();
    LDAPSearchResults searchResults;
    LDAPEntry entry = null;
    try {
      searchResults = connection.search(entryDN, LDAPConnection.SCOPE_BASE, "", null, false);
      entry = searchResults.next();
    } catch (LDAPException e) {
      // e.printStackTrace();
      return v;
    }

    // System.out.println(entry);
    LDAPAttributeSet attributeSet = entry.getAttributeSet();
    // System.out.println(attributeSet);
    Iterator allAttributes = attributeSet.iterator();

    while (allAttributes.hasNext()) {
      LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
      String attributeName = attribute.getName();
      if (attributeName.equalsIgnoreCase(attr)) {
        Enumeration en = attribute.getStringValues();
        for (; en.hasMoreElements(); ) {
          v.add(en.nextElement());
        }
      }
    }
    return v;
  }
  public Group[] getAllChangedGroups(String lds, String extraFilter) throws AdminException {
    Vector<LDAPEntry> groupsCur;
    Iterator<LDAPEntry> it;
    int i;
    Hashtable<String, Group> groupsManaged = new Hashtable<String, Group>();
    LDAPEntry[] les = getChildGroupsEntry(lds, null, extraFilter);
    LDAPEntry theGroup;

    Vector<LDAPEntry> groupsIdsSet = new Vector<LDAPEntry>(les.length);
    for (i = 0; i < les.length; i++) {
      groupsIdsSet.add(les[i]);
      groupsManaged.put(les[i].getDN(), translateGroup(lds, les[i]));
    }
    // Go recurs to all group's ancestors
    while (groupsIdsSet.size() > 0) {
      it = groupsIdsSet.iterator();
      groupsCur = new Vector<LDAPEntry>();
      while (it.hasNext()) {
        theGroup = it.next();
        SilverTrace.info(
            "admin",
            "LDAPGroupSamse.getAllChangedGroups()",
            "root.MSG_GEN_PARAM_VALUE",
            "GroupTraite2=" + theGroup.getDN());
        les =
            LDAPUtility.search1000Plus(
                lds,
                driverSettings.getGroupsSpecificGroupsBaseDN(),
                driverSettings.getScope(),
                "(&"
                    + driverSettings.getGroupsFullFilter()
                    + "("
                    + driverSettings.getGroupsMemberField()
                    + "="
                    + LDAPUtility.dblBackSlashesForDNInFilters(theGroup.getDN())
                    + "))",
                driverSettings.getGroupsNameField(),
                driverSettings.getGroupAttributes());
        for (i = 0; i < les.length; i++) {
          SilverTrace.info(
              "admin",
              "LDAPGroupSamse.getAllChangedGroups()",
              "root.MSG_GEN_PARAM_VALUE",
              "GroupFound2=" + les[i].getDN());
          if (!groupsManaged.containsKey(les[i].getDN())) {
            SilverTrace.info(
                "admin",
                "LDAPGroupSamse.getAllChangedGroups()",
                "root.MSG_GEN_PARAM_VALUE",
                "GroupAjoute2=" + les[i].getDN());
            groupsCur.add(les[i]);
            groupsManaged.put(les[i].getDN(), translateGroup(lds, les[i]));
          }
        }
      }
      groupsIdsSet = groupsCur;
    }
    return groupsManaged.values().toArray(new Group[groupsManaged.size()]);
  }
  /**
   * Gives the members, in the ldap, that are corresponding to the logic definition of a group.
   *
   * @param definition The logic definition of the members of the group.
   * @return The set of the members ids.
   * @see
   *     org.esco.dynamicgroups.dao.ldap.IMembersFromDefinitionDAO#getMembers(DynamicGroupDefinition)
   */
  public Set<String> getMembers(final DynamicGroupDefinition definition) {
    final Set<String> userIds = new HashSet<String>();
    if (definition.isValid()) {
      checkConnection();

      final String filter = translateToLdapFilter(definition);

      try {
        final LDAPSearchResults result =
            getConnection()
                .search(
                    ldapParameters.getLdapSearchBase(),
                    LDAPConnection.SCOPE_SUB,
                    filter,
                    uidAttributeArray,
                    false,
                    constraints);

        while (result.hasMore()) {
          final LDAPEntry entry = result.next();
          userIds.add(entry.getAttribute(ldapParameters.getLdapUidAttribute()).getStringValue());
        }

      } catch (LDAPException e) {
        LOGGER.error(
            "Error while trying to retrieve the members for the definition: "
                + definition
                + " - associated filter: "
                + filter);
        LOGGER.error(e, e);
        final String filter2 = translateToLdapFilter(definition);
        LOGGER.error("!!! Remove this message : " + filter2);
      }
    }
    return userIds;
  }
  protected Vector<String> getTRUEUserIds(String lds, LDAPEntry groupEntry) throws AdminException {
    SilverTrace.info(
        "admin",
        "LDAPGroupSamse.getTRUEUserIds()",
        "root.MSG_GEN_ENTER_METHOD",
        "lds = " + lds + ", group = " + groupEntry.getDN());

    Vector<String> usersVector = new Vector<String>();
    String groupsMemberField = driverSettings.getGroupsMemberField();

    // retrieve all memberUid
    String[] stringVals = LDAPUtility.getAttributeValues(groupEntry, groupsMemberField);
    for (int i = 0; i < stringVals.length; i++) {
      SilverTrace.info(
          "admin",
          "LDAPGroupSamse.getTRUEUserIds()",
          "root.MSG_GEN_PARAM_VALUE",
          "stringVals[" + i + "] = " + stringVals[i]);
      usersVector.add(stringVals[i]);
    }
    stringVals = null;
    SilverTrace.info("admin", "LDAPGroupSamse.getTRUEUserIds()", "root.MSG_GEN_EXIT_METHOD");
    return usersVector;
  }
  protected String[] getMemberGroupIds(String lds, String memberId, boolean isGroup)
      throws AdminException {
    Vector<String> groupsVector = new Vector<String>();
    LDAPEntry[] theEntries = null;
    LDAPEntry memberEntry = null;
    int i;

    SilverTrace.info(
        "admin",
        "LDAPGroupUniqueDescriptor.getMemberGroupIds()",
        "root.MSG_GEN_ENTER_METHOD",
        "MemberId=" + memberId + ", isGroup=" + isGroup);
    if (isGroup) {
      memberEntry =
          LDAPUtility.getFirstEntryFromSearch(
              lds,
              driverSettings.getGroupsSpecificGroupsBaseDN(),
              driverSettings.getScope(),
              driverSettings.getGroupsIdFilter(memberId),
              driverSettings.getGroupAttributes());
    } else {
      memberEntry =
          LDAPUtility.getFirstEntryFromSearch(
              lds,
              driverSettings.getLDAPUserBaseDN(),
              driverSettings.getScope(),
              driverSettings.getUsersIdFilter(memberId),
              driverSettings.getGroupAttributes());
    }
    if (memberEntry == null) {
      throw new AdminException(
          "LDAPGroupUniqueDescriptor.getMemberGroupIds",
          SilverpeasException.ERROR,
          "admin.EX_ERR_LDAP_USER_ENTRY_ISNULL",
          "Id=" + memberId + " IsGroup=" + isGroup);
    }
    theEntries =
        LDAPUtility.search1000Plus(
            lds,
            driverSettings.getGroupsSpecificGroupsBaseDN(),
            driverSettings.getScope(),
            "(&"
                + driverSettings.getGroupsFullFilter()
                + "("
                + driverSettings.getGroupsMemberField()
                + "="
                + LDAPUtility.dblBackSlashesForDNInFilters(memberEntry.getDN())
                + "))",
            driverSettings.getGroupsNameField(),
            driverSettings.getGroupAttributes());
    for (i = 0; i < theEntries.length; i++) {
      SilverTrace.info(
          "admin",
          "LDAPGroupUniqueDescriptor.getMemberGroupIds()",
          "root.MSG_GEN_PARAM_VALUE",
          "GroupFound=" + theEntries[i].getDN());
      groupsVector.add(
          LDAPUtility.getFirstAttributeValue(theEntries[i], driverSettings.getGroupsIdField()));
    }
    return groupsVector.toArray(new String[groupsVector.size()]);
  }
 public LDAPUser login(String aUserName, String aPassword) throws InvalidLoginException {
   LDAPUser onlineUser = null;
   try {
     connection.connect(ldapHost, ldapPort);
     System.out.println("Connect Successfull");
     System.out.println(aUserName);
     LDAPSearchQueue searchResults =
         connection.search(
             "o=Aerothai",
             LDAPConnection.SCOPE_SUB,
             "cn=" + aUserName,
             new String[] {LDAPConnection.NO_ATTRS},
             true,
             (LDAPSearchQueue) null);
     LDAPMessage message;
     message = searchResults.getResponse();
     if (message instanceof LDAPSearchResult) {
       LDAPEntry entry = ((LDAPSearchResult) message).getEntry();
       String dn = entry.getDN();
       String[] userDn = dn.split(",");
       String fullDn = userDn[0] + "," + userDn[1] + "," + userDn[2] + ",o=Aerothai";
       connection.bind(ldapVersion, fullDn, aPassword.getBytes("UTF8"));
       System.out.println("Bind Successfull");
       onlineUser = new LDAPUser();
       try {
         onlineUser.setFirstName((String) getAttribute(fullDn, "givenName").elementAt(0));
         onlineUser.setLastName((String) getAttribute(fullDn, "sn").elementAt(0));
         try {
           Integer.parseInt((String) getAttribute(fullDn, "cn").elementAt(1));
           onlineUser.setEmployeeCode((String) getAttribute(fullDn, "cn").elementAt(1));
         } catch (NumberFormatException e) {
           onlineUser.setEmployeeCode((String) getAttribute(fullDn, "cn").elementAt(0));
         }
         onlineUser.setDepartment((String) getAttribute(fullDn, "ou").elementAt(0));
         onlineUser.setLocation((userDn[2].split("="))[1]);
       } catch (ArrayIndexOutOfBoundsException e1) {
         e1.printStackTrace();
         onlineUser = null;
         throw new InvalidLoginException(
             "à¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´ÃÐËÇèÒ§¡Òô֧¢éÍÁÙÅ ¡ÃØ³Ò Login ãËÁèÍÕ¡¤ÃÑé§");
       }
     } else {
       disconnect();
       throw new InvalidLoginException(
           "äÁ辺¼Ùéãªé§Ò¹ª×èÍ "
               + aUserName
               + " ¡ÃسÒÅͧÍÕ¡¤ÃÑé§ ËÃ×Í µÔ´µèÍà¨éÒ˹éÒ·Õè¡Í§Ç¤.¾Ç. à¾×è͵ÃǨÊͺ¢éÍÁÙŢͧ·èÒ¹");
     }
     disconnect();
   } catch (LDAPException e) {
     e.printStackTrace();
     throw new InvalidLoginException(
         "ÃËÑʼèÒ¹äÁè¶Ù¡µéͧ ¡ÃسÒÅͧÍÕ¡¤ÃÑé§ ËÃ×Í µÔ´µèÍà¨éÒ˹éÒ·Õè¡Í§Ç¤.¾Ç. à¾×è͵ÃǨÊͺ¢éÍÁÙŢͧ·èÒ¹");
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
     throw new InvalidLoginException(e);
   } finally {
     disconnect();
   }
   return onlineUser;
 }