0

私は自分の質問に対する答えを得るためにたくさん検索しました。しかし、私はできません。

私が検索で得たもの:

public class RetrieveUserAttributes {
 
    public static void main(String[] args) {
    RetrieveUserAttributes retrieveUserAttributes = new RetrieveUserAttributes();
    retrieveUserAttributes.getUserBasicAttributes("anand", retrieveUserAttributes.getLdapContext());
    }
 
    
    public LdapContext getLdapContext(){
    LdapContext ctx = null;
    try{
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.SECURITY_PRINCIPAL, "anand@tstdmn.com");
        env.put(Context.SECURITY_CREDENTIALS, "password@123");
        env.put(Context.PROVIDER_URL, "ldap://192.168.100.182:389");
        ctx = new InitialLdapContext(env, null);
        System.out.println("Connection Successful.");
    }catch(NamingException nex){
        System.out.println("LDAP Connection: FAILED");
    }
    return ctx;
    }
 
    private void getUserBasicAttributes(String username, LdapContext ctx) {
    try {
 
        SearchControls constraints = new SearchControls();
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String searchFilter = "(objectClass=person)";
 
        String[] attrIDs = { "distinguishedName","sn","givenname","mail", "telephonenumber","lockoutThreshold", "lockoutDuration", "minPwdAge","maxPwdAge", "minPwdLength","pwdLastSet"};
        constraints.setReturningAttributes(attrIDs);

        NamingEnumeration answer = ctx.search(searchBase, searchFilter, constraints);
        if (answer.hasMore()) {
        Attributes attrs = ((SearchResult) answer.next()).getAttributes();
           
        for(String obj : attrIDs){
            System.out.println(obj+" : "+ attrs.get(obj));
        }
           
        
        }else{
        throw new Exception("Invalid User");
        }
 
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    }
 
}

ここで指定したキーは完全にstatic.

下の「AD」の図で、「General」、「Account」、「Address」タブのすべての属性を動的に取得する必要があります。

ここに画像の説明を入力

良い解決策が得られることを願っています。

4

1 に答える 1

0

LDAP から表示される属性を特定しました: http://ldapwiki.willeke.com/wiki/MMC%20General%20Tab

-ジム

于 2014-06-12T14:20:06.853 に答える