我有一个嵌入式jetty服务器,它从许多不同的位置迭代一个webapps列表(列表在不同的部署之间).我正在尝试从基本身份验证转换为表单身份验证.
我想做的是:
// create constraint
Constraint usersOnly = new Constraint(Constraint.__FORM_AUTH, "user");
usersOnly.setAuthenticate(true);
ConstraintMapping requireAuthentication = new ConstraintMapping();
requireAuthentication.setConstraint(usersOnly);
requireAuthentication.setPathSpec("/*");
// create login service
LoginService loginService = new HashLoginService("realm");
loginService.setConfig("users.txt");
// create form authentication
FormAuthenticator formAuthenticator = new FormAuthenticator("/login", "/login", true);
// create /login route
ServletHolder loginServlet = new ServletHolder(new DefaultServlet() {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("\n
\nLogin\n\n\n"+ "
\n"+ "\n"
+ "\n"
+ "\n
\n\n\n");}
});
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.addMapping(requireAuthentication);
securityHandler.setLoginService(loginService);
securityHandler.setAuthenticator(formAuthenticator);
// assign security to each webapp
for (WebAppContext webapp : webapps) {
webapp.setSecurityHandler(securityHandler);
webapp.addServlet(loginServlet, "/login");
}
如果webapps中只有一个webapp,则可以正常工作,但如果有多个webapp,则每次跟踪从一个webapp到另一个webapp的链接时都会提示您登录,每次重新进行身份验证时,都会被重定向到基础webapp.路由“/”并且仅针对该路由进行身份验证.
我想让我的背景分享会话.
根据this question,为每个WebAppContext实例配置一个公共SessionManager应该可以解决问题,但是asker只有一个WebAppContext实例.如果我尝试将相同的SessionManager实例分配给每个WebAppContext,我会得到NPE.
我还看到一些资源指向将每个上下文的SessionCookieConfig的路径设置为公共上下文路径,并将useRequestedId设置为每个WebAppContext的SessionManager的true,但此解决方案适用于org.mortbay.jetty并且已过时.
如果您对具有多个WebAppContexts的嵌入式Jetty服务器设置SSO有任何见解或经验,或者如果您能想到使用一个公共服务器提供多个不同Web应用程序的更好方法,请指出我正确的方向.
如何通过填写单个表单允许用户对一台服务器处理的所有Web应用进行身份验证?
如果我不清楚或者您有任何疑问,请告诉我.