apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/FilterLdapByGroupUserSearch.java/FilterLdapByGroupUserSearch/searchForUser
class FilterLdapByGroupUserSearch:  @Override
  public DirContextOperations searchForUser(String username) {
    if (logger.isDebugEnabled()) {
      logger.debug("Searching for user '" + username + "', with user search " + this);
    }
    SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(this.contextSource);
    template.setSearchControls(searchControls);
    return template
        .searchForObject(groupBase, groupSearch, ctx -> {
          if (!MEMBER_UID_ATTR_NAME.equals(groupMembershipAttrName)) {
            String[] members = ((DirContextAdapter) ctx)
                .getStringAttributes(groupMembershipAttrName);
            for (String item : members) {
              LdapName memberDn = LdapUtils.newLdapName(item);
              LdapName memberRdn = LdapUtils
                  .removeFirst(memberDn, LdapUtils.newLdapName(searchBase));
              String rdnValue = LdapUtils.getValue(memberRdn, rdnKey).toString();
              if (rdnValue.equalsIgnoreCase(username)) {
                return new DirContextAdapter(memberRdn.toString());
              }
            }
            throw new UsernameNotFoundException("User " + username + " not found in directory.");
          }
          String[] memberUids = ((DirContextAdapter) ctx)
              .getStringAttributes(groupMembershipAttrName);
          for (String memberUid : memberUids) {
            if (memberUid.equalsIgnoreCase(username)) {
              Name name = searchUserById(memberUid);
              LdapName ldapName = LdapUtils.newLdapName(name);
              LdapName ldapRdn = LdapUtils
                  .removeFirst(ldapName, LdapUtils.newLdapName(searchBase));
              return new DirContextAdapter(ldapRdn);
            }
          }
          throw new UsernameNotFoundException("User " + username + " not found in directory.");
        });
  }