gpt4 book ai didi

java - 在 Jetty WebAppContext 之间实现 SSO

转载 作者:行者123 更新时间:2023-11-30 08:29:17 26 4
gpt4 key购买 nike

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

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

更多信息:

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

最佳答案

我解决了这个问题 - 您只需将相同的 SessionManager 实例分配给每个 WebAappContext 的 SessionManager。它看起来有点像这样,假设所有 WebAppContexts 都分组在/webapps/上下文路径下:

 // 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);

关于java - 在 Jetty WebAppContext 之间实现 SSO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19525948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com