【问题标题】:Implementing SSO between Jetty9 WebAppContexts在 Jetty9 WebAppContexts 之间实现 SSO
【发布时间】:2013-10-31 19:12:23
【问题描述】:

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

我确实发现这篇文章推荐了 Fediz 码头插件,但如果存在这种情况,我更愿意使用原生码头解决方案:http://dev.eclipse.org/mhonarc/lists/jetty-users/msg03176.html

更多信息:

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

【问题讨论】:

  • 由于我是 StackOverflow 的新手,如果我能以更有用或更具体的方式提出问题,请告诉我

标签: java jakarta-ee servlets jetty single-sign-on


【解决方案1】:

我解决了这个问题——您只需将相同的 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);

【讨论】:

  • 经过深思熟虑,我决定采用这个解决方案。对于我的应用程序,WebAppContexts 共享 cookie 没什么大不了的,我认为没有必要教条地遵守 servlet 规范。
【解决方案2】:

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

一月

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 2018-11-12
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多