2013-10-22 35 views
2

我開發的Jetty 9應用程序會自動掃描一組用於web.xml的JarFiles,然後以編程方式將包含的Webapps作爲WebAppContexts導入。我需要在各個webapps之間實現單點登錄,如以下Jetty 6教程:http://docs.codehaus.org/display/JETTY/Single+Sign+On+-+Jetty+HashSSORealm中所述。不幸的是,HashSSORealm似乎已經從Jetty中刪除。 是否有任何可行的替代方案來實施簡單的SSO?在Jetty9之間實現SSO WebAppContexts

我發現這個職位推薦的Fediz碼頭插件,但我們更希望,如果這樣的事情存在使用本地碼頭的解決方案:http://dev.eclipse.org/mhonarc/lists/jetty-users/msg03176.html

進一步信息:

的核心問題似乎是,每個WebAppContext都必須擁有自己的SessionManager,因此即使使用相同的cookie,WebAppContext也不可能彼此共享信息。

+1

由於我是新來的StackOverflow,請讓我知道,如果我能在經過深刻反省更有幫助的或特定的方式 –

回答

1

如果您在WebAppContexts共享SessionManager,那麼所有這些WebAppContexts共享完全相同的會話實例。 Servlet規範說WebAppContexts應該共享會話ID,而不是會話內容。

2

我解決了這個問題 - 你只需要將相同的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); 
+1

框架的問題,我決定去與這個解決方案。對於我的應用程序,如果WebAppContexts共享cookie,沒有什麼大不了的,並且我認爲不需要教條式地遵守servlet規範。 –