我有一个doLogin()
从 JSF 页面调用的 Java 方法,该页面从用户那里获取一个 id ( String netId
) 和密码 ( String password
)。使用Active Directory 登录中的主体doLogin()
启动身份验证。netId
之后,我想从保护我的应用程序的目录中获取除主体名称之外的其他属性。
我的安全性在容器中配置并且它可以工作,这样
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;这将要求代码知道server / bind-DN / bind-password configuration
Web 服务器(JBoss EAP 6.2)已经知道的所有 LDAP(来自<login-module>
定义在 中standalone.xml
)。例如,方法喜欢getUserPrincipal()
并且isUserInRole()
需要访问我想要访问的同一个目录配置文件。
所以我的问题是:有没有办法从 FacesContext 或 HTTPServletRequest 或任何可从 HTTPServlet 访问的对象获取 LDAP 连接或上下文?