【发布时间】:2015-04-06 19:48:21
【问题描述】:
我有一个从 JSF 页面调用的 Java doLogin() 方法,该方法从用户那里获取一个 id (String netId) 和密码 (String password)。 doLogin() 使用 netId 作为 Active Directory 登录中的主体来启动身份验证。之后,我想从保护我的应用程序的目录中获取除主体名称之外的其他属性。
我的安全性已在容器中配置并且可以正常工作,因此
HttpSession ses = FacesContext.getCurrentInstance().getExternalContext().getSession (false);
HttpServletRequest req = FacesContext.getCurrentInstance().getExternalContext().getRequest();
req.login(netID, password);
成功了
req.getUserPrincipal().getName();
返回用户的netID。但是,我的应用程序仅使用 netId 进行身份验证。访问另一个数据库的应用程序的其他部分需要其他属性(例如commonName)。我想做类似的事情
usefulLDAPobj = *getLDAPSession from "somewhere" in the HTTP Session, the FacesContext or some other available object*
String cn = usefulLDAPobj.getAttributeFromProfile ("cn");
ses.setAttribute("username", cn);
然后使用用户名,存储在会话中,在我的 Hibernate ORM 中。
我知道头脑简单的usefulLDAPobj.getAttributeFromProfile ("cn") 会更复杂,但如果我能找到让我访问 LDAP 目录的起点,我可以填写它。
由于容器设置了一个明显的 LDAP 连接,我觉得 必须 是我使用它的一种方式,而无需以编程方式手动构建 LdapContext;这将要求代码知道 Web 服务器(JBoss EAP 6.2)已经知道的所有 LDAP server / bind-DN / bind-password configuration(来自 standalone.xml 中定义的 <login-module>)。例如,getUserPrincipal() 和 isUserInRole() 之类的方法需要访问我想要访问的同一个目录配置文件。
所以我的问题是:有没有办法从 FacesContext 或 HTTPServletRequest 或任何可从 HTTPServlet 访问的对象获取 LDAP 连接或上下文?
【问题讨论】:
标签: jsf ldap httpsession jboss-eap-6 facescontext