Skip to content

Commit

Permalink
Rework single-sign-on to cope with Jetty 11
Browse files Browse the repository at this point in the history
Sharing the session handler between contexts leads to an NPE,
because startup of the first context now reaches into the
lifecycle of the second webapp, which has not started yet.
SessionHandler objects, which carry context-specific
lifecycle information, must not be shared between contexts.
  • Loading branch information
f4lco committed Nov 13, 2020
1 parent 48f243e commit 18a14f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class JettyConfigurerImpl implements JettyConfigurer {
private static final Logger log = LoggerFactory.getLogger(JettyConfigurerImpl)

private SSOAuthenticatorFactory ssoAuthenticatorFactory
private SessionHandler sharedSessionHandler

@Override
def addLifeCycleListener(lifecycle, listener) {
Expand Down Expand Up @@ -175,12 +174,9 @@ class JettyConfigurerImpl implements JettyConfigurer {
void configureSessionManager(server, context, Map serverParams, Map webappParams) {
SessionHandler sessionHandler
if(serverParams.singleSignOn) {
sessionHandler = sharedSessionHandler
if(sessionHandler == null) {
sessionHandler = sharedSessionHandler = new SessionHandler()
sessionHandler.setMaxInactiveInterval(60 * 30) // 30 minutes
sessionHandler.getSessionCookieConfig().setPath('/')
}
sessionHandler = new SingleSignOnSessionHandler()
sessionHandler.setMaxInactiveInterval(60 * 30) // 30 minutes
sessionHandler.getSessionCookieConfig().setPath('/')
} else {
sessionHandler = new SessionHandler()
sessionHandler.setMaxInactiveInterval(60 * 30) // 30 minutes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.akhikhl.gretty

import org.eclipse.jetty.server.session.Session
import org.eclipse.jetty.server.session.SessionHandler

class SingleSignOnSessionHandler extends SessionHandler {

@Override
Session getSession(String id) {
Session session = getLocalSession(id)
if (session == null) {
for (SessionHandler handler : getSessionIdManager().getSessionHandlers()) {

if (handler == this || !(handler instanceof SingleSignOnSessionHandler)) {
continue
}

session = ((SingleSignOnSessionHandler) handler).getLocalSession(id)
if (session != null) {
break
}
}
}

return session
}

private Session getLocalSession(String id) {
return super.getSession(id)
}
}

0 comments on commit 18a14f8

Please sign in to comment.