我有一个使用LDAP登录的Web应用程序。
我正在使用 Openid4Java 让用户使用开放ID登录,这很有效但是当我想重定向到我的index.jsp页面时,会重定向我返回登录页面,因为我未使用LDAP 进行身份验证。
我已经制作了一个方法来向一个带有LDAP的演示用户进行身份验证,但问题是如何从我使用LDAP登录的open id“告诉”HttpResponse?
这是servlet的doGet方法,它负责OpenId身份验证。此外,您会注意到我进行了LDAP身份验证。在进行重定向之前(单个问题是对于openId我使用我的gmail帐户而对于LDAP我使用模拟帐户而我不知道如何处理响应...)
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("--------GET----------------");
System.out.println("context: " + context);
Identifier identifier = this.verifyResponse(req);
System.out.println("identifier: " + identifier);
if (identifier == null) {
this.getServletContext().getRequestDispatcher("/login_new.jsp")
.forward(req, resp);
} else {
req.setAttribute("identifier", identifier.getIdentifier());
final String applicationUrl = req.getRequestURL().toString();
final String redirectTo = applicationUrl.substring(0,
applicationUrl.indexOf("/servlet")) + "/" + "index.jsp";
System.out.println("Login through open id succeded, redirect to: "
+ redirectTo);
if (authenticateUserInJbossLDAP())
resp.sendRedirect(redirectTo);
}
}
你有什么建议吗?
感谢。
答案 0 :(得分:0)
终于解决了这个问题。
关键是从servlet对Web容器进行身份验证。名为“org.jboss.web.tomcat.security.login。 WebAuthentication ”的新类可用于此目的。
所以最终改进的方法将是:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
log.debug("------------------------");
log.debug("context: " + context);
Identifier identifier = this.verifyResponse(req);
log.debug("identifier: " + identifier);
// if openid login succeded redirect to home page using our demo account
if (identifier != null) {
WebAuthentication pwl = new WebAuthentication();
pwl.login("guest", "guest");**
resp.sendRedirect("/index.jsp");
} else {
System.out.println("login with openid failed");
}
}
我写下的完整的openid解决方案here。