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”图片中动态检索“常规、帐户、地址”选项卡中的所有属性。

在此处输入图像描述

希望我能得到一个好的解决方案。

4

1 回答 1

0

我们已经确定了从 LDAP 中出现的属性:http: //ldapwiki.willeke.com/wiki/MMC%20General%20Tab

-吉姆

于 2014-06-12T14:20:06.853 回答