在Jetty9 WebAppContexts之间实现SSO

我正在开发的Jetty 9应用程序自动扫描一组JarFiles for web.xml,然后以编程方式将包含的webapps导入为WebAppContexts。 我需要在各个Web应用程序之间实现单点登录,如以下Jetty 6教程中所述: http : //docs.codehaus.org/display/JETTY/Single+Sign+On+-+Jetty+HashSSORealm 。 不幸的是,HashSSORealm似乎已从Jetty中移除。 有没有可行的替代方案来实施简单的SSO?

我确实发现这篇文章推荐了Fediz jetty插件,但是如果存在这样的话,我更愿意使用本机docker解决方案: http : //dev.eclipse.org/mhonarc/lists/jetty-users/msg03176.html

更多信息:

核心问题似乎是每个WebAppContext都必须有自己的SessionManager,这使得即使使用相同的cookie,WebAppContexts也无法相互共享信息。

如果您跨WebAppContexts共享SessionManager,则所有这些WebAppContexts共享完全相同的会话实例。 Servlet规范说WebAppContexts应该共享会话ID, 而不是会话内容。

一月

我解决了这个问题 – 你只需要为每个WebAappContext的SessionManager分配相同的SessionManager实例。 假设所有WebAppContexts都在/ webapps / context路径下分组,它看起来会像这样:

// To be passed to all scanned webapps. Ensures SSO between contexts SessionManager sessManager = new HashSessionManager(); SessionCookieConfig config = sessManager.getSessionCookieConfig(); config.setPath("/webapps/"); // Ensures all webapps share the same cookie // Create the Handler (aka the WebAppContext). App app = new App(deployer, provider, module.getFile().getAbsolutePath()); WebAppContext handler = (WebAppContext)app.getContextHandler(); // getContextHandler does the extraction // Consolidating all scanned webapps under a single context path allows SSO handler.setContextPath("/webapps" + handler.getContextPath()); // Cookies need to be shared between webapps for SSO SessionHandler sessHandler = handler.getSessionHandler(); sessHandler.setSessionManager(sessManager);