Java 在Jetty9 WebAppContext之间实现SSO

Java 在Jetty9 WebAppContext之间实现SSO,java,jakarta-ee,servlets,jetty,single-sign-on,Java,Jakarta Ee,Servlets,Jetty,Single Sign On,我正在开发的Jetty 9应用程序会自动扫描一组jar文件中的web.xml,然后以编程方式将包含的webapps作为webappcontext导入。我需要在各个Web应用程序之间实现单点登录,如以下Jetty 6教程所述:。不幸的是,HashSSORealm似乎已从码头上移除实现简单SSO是否有可行的替代方案? 我确实发现这篇文章推荐了Fediz jetty插件,但如果存在这样的问题,我更愿意使用原生jetty解决方案: 进一步资料: 中心问题似乎是每个WebAppContext都必须有自己的

我正在开发的Jetty 9应用程序会自动扫描一组jar文件中的web.xml,然后以编程方式将包含的webapps作为webappcontext导入。我需要在各个Web应用程序之间实现单点登录,如以下Jetty 6教程所述:。不幸的是,HashSSORealm似乎已从码头上移除实现简单SSO是否有可行的替代方案?

我确实发现这篇文章推荐了Fediz jetty插件,但如果存在这样的问题,我更愿意使用原生jetty解决方案:

进一步资料:


中心问题似乎是每个WebAppContext都必须有自己的SessionManager,这使得WebAppContext即使在使用相同的cookie时也无法彼此共享信息

我解决了这个问题-您只需将相同的SessionManager实例分配给每个WebAappContext的SessionManager即可。假设所有webappcontext都分组在/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 (a.k.a 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);

如果您在WebAppContexts之间共享SessionManager,那么所有这些WebAppContexts共享完全相同的会话实例。Servlet规范规定WebAppContext应该共享会话ID,而不是会话内容


Jan

由于我是StackOverflow的新手,请让我知道我是否可以用一种更有用或更具体的方式来阐述这个问题。经过多次的自我反省,我决定采用这个解决方案。对于我的应用程序,如果WebAppContexts共享cookies,那没什么大不了的,我认为没有必要武断地遵守servlet规范。