2015-05-14 75 views
0

的属性我连接到LDAP服务器鲍勃:查看当前连接的LDAP用户

Hashtable props = new Hashtable(); 
props.put(Context.SECURITY_PRINCIPAL, "cn=Bob,cn=Users,dc=myCompany,dc=com"); 
props.put(Context.SECURITY_CREDENTIALS, "Password1"); 
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
props.put(Context.PROVIDER_URL, url); 
InitialLdapContext context = new InitialLdapContext(props, null); 

现在我想看看Bob的姓名和电子邮件地址。

我期待在context上找到一个方法来返回当前连接的用户的属性,但我找不到一个。

Bob没有搜索目录的权限,所以连接后我不能使用context.search

有没有办法获得这些属性,而无需再次调用LDAP服务器,或者必须先以其他人身份连接?

回答

0

您需要使用RFC 4532'whoami'扩展操作,OID = 1.3.6.1.4.1.4203.1.11.3。你需要自己写一个ExtendedRequestExtendedResponse类为该(抱歉不能发表我的,但其实很简单),并且按如下方式使用它:

WhoAmIExtendedResponse response = (WhoAmIExtendedResponse)context.extendedOperation(new WhoAmIExtendedRequest()); 

然后拿到authZId了回应。这是当前用户的DN,前缀为​​。然后你可以通过context.getAttributes("...")