我正在开发的 Jetty 9 应用程序会自动扫描一组 JarFiles 中的 web.xml,然后以编程方式将包含的 Web 应用程序导入为 WebAppContext。我需要在各个 Web 应用程序之间实现单点登录,如以下 Jetty 6 教程中所述:http://docs.codehaus.org/display/JETTY/Single+Sign+On+-+Jetty+HashSSORealm http://docs.codehaus.org/display/JETTY/Single+Sign+On+-+Jetty+HashSSORealm。不幸的是,HashSSORealm 似乎已从 Jetty 中删除。是否有任何可行的替代方案来实施简单的 SSO?
我确实发现这篇文章推荐 Fediz jetty 插件,但如果存在这样的东西,我更愿意使用本机 jetty 解决方案:http://dev.eclipse.org/mhonarc/lists/jetty-users/msg03176.html http://dev.eclipse.org/mhonarc/lists/jetty-users/msg03176.html
更多信息:
核心问题似乎是每个 WebAppContext 必须有自己的 SessionManager,这使得即使使用相同的 cookie,WebAppContext 也无法彼此共享信息。
我解决了这个问题 - 您只需将 SessionManager 的相同实例分配给每个 WebAappContext 的 SessionManager 即可。它看起来有点像这样,假设所有 WebAppContext 都分组在 /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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)