jetty java 实例_java – 具有多个WebAppContext实例的单一登录Jetty

我有一个嵌入式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应用进行身份验证?

如果我不清楚或者您有任何疑问,请告诉我.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值