如何检索" Windows活动目录 - 属性的id"在Java中? [英] How to retrieve "windows active directory - attributes id's " in java?
本文介绍了如何检索" Windows活动目录 - 属性的id"在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我寻觅了很多让我的问题的答案。但我不能。
I have searched a lot to get the answer for my question. But I can't .
我所得到的搜索结果:
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();
}
}
}
这是我给这里是完全静态钥匙
。
The keys that I gave here is fully static
.
我需要检索的所有属性,在常规,账号,地址标签动态的广告下面的图片。
I need to retrieve the all the attributes in the 'General , Account , Address' tabs dynamically in the 'AD' picture below.
希望我会得到很好的解决。
Hope I will get a good solution.
推荐答案
我们已经确定的属性,因为他们从LDAP显示: http://ldapwiki.willeke.com/wiki/MMC%20General%20Tab
We have identified the Attributes as they appear from LDAP: http://ldapwiki.willeke.com/wiki/MMC%20General%20Tab
-Jim
这篇关于如何检索&QUOT; Windows活动目录 - 属性的id&QUOT;在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文