简体   繁体   English

在Jetty9 WebAppContexts之间实现SSO

[英]Implementing SSO between Jetty9 WebAppContexts

The Jetty 9 application I am developing automatically scans a set of JarFiles for web.xml, then programmatically imports the contained webapps as WebAppContexts. 我正在开发的Jetty 9应用程序会自动扫描一组JarFiles中的web.xml,然后以编程方式将包含的webapps导入为WebAppContexts。 I need to implement single sign-on between the individual webapps, as explained in the following tutorial for Jetty 6: http://docs.codehaus.org/display/JETTY/Single+Sign+On+-+Jetty+HashSSORealm . 我需要在各个Web应用之间实现单点登录,如Jetty 6的以下教程所述: http : //docs.codehaus.org/display/JETTY/Single+Sign+On+-++Jetty+HashSSORealm Unfortunately, HashSSORealm seems to have been removed from Jetty. 不幸的是,HashSSORealm似乎已从Jetty中删除。 Are there any viable alternatives for implementing simple SSO? 是否有可行的方法来实现简单的SSO?

I did find this post recommending the Fediz jetty plugin, but would prefer to use a native jetty solution if such a thing exists: http://dev.eclipse.org/mhonarc/lists/jetty-users/msg03176.html 我确实找到了推荐Fediz码头插件的帖子,但是如果存在此类问题,我更愿意使用本地码头解决方案: http : //dev.eclipse.org/mhonarc/lists/jetty-users/msg03176.html

Further info: 更多信息:

The central issue seems to be that each WebAppContext must have its own SessionManager, making it impossible for the WebAppContexts to share information with one another even when using the same cookie. 中心问题似乎是每个WebAppContext必须具有自己的SessionManager,即使使用相同的cookie,WebAppContext也无法彼此共享信息。

I solved the issue- you simply have to assign the same instance of SessionManager to each WebAappContext's SessionManager. 我解决了这个问题-您只需要将相同的SessionManager实例分配给每个WebAappContext的SessionManager。 It'll look a little something like this, assuming all WebAppContexts are grouped under the /webapps/ context path: 假设所有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);

If you share the SessionManager across WebAppContexts, then all of those WebAppContexts share exactly the same session instances. 如果跨WebAppContext共享SessionManager,则所有这些WebAppContext都共享完全相同的会话实例。 The Servlet Spec says that the WebAppContexts should share session ids, not session contents. Servlet规范说,WebAppContexts应该共享会话ID, 而不是会话内容。

Jan 一月

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM