CAn有人形容我如何使用weblogic安全性从AD获取其他用户属性? 我已经配置了安全提供程序并尝试在我的JEE应用程序中进行身份验证。
HttpServletRequest request =
(HttpServletRequest)((ServletRequest)ADFContext.getCurrent().getEnvironment().getRequest());
CallbackHandler handler =
new SimpleCallbackHandler(username, password);
try {
Subject subject = Authentication.login(handler);
ServletAuthentication.runAs(subject, request);
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
一切都好。但是从主题我可以只接受用户登录和角色,但我需要用户电话和employeeNumber。我该怎么办?
答案 0 :(得分:0)
从Subject
检索用户名后,您必须发出LDAP查询以获取额外信息。它看起来如下所示:
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
properties.put(Context.PROVIDER_URL, "LDAP://yourldap:389");
properties.put(Context.SECURITY_PRINCIPAL, ldapqueryuser + "@yourldap");
properties.put(Context.SECURITY_CREDENTIALS, ldapqueryuserpassword);
// initializing active directory LDAP connection
dirContext = new InitialDirContext(properties);
dirContext.search(name, filter, cons)
这些例子非常透彻:
http://docs.oracle.com/javase/jndi/tutorial/getStarted/examples/directory.html http://myjeeva.com/querying-active-directory-using-java.html
InitialDirContext的java文档在这里:
http://docs.oracle.com/javase/7/docs/api/javax/naming/directory/InitialDirContext.html