|
@@ -40,6 +40,8 @@ public class SessionManagementFilter extends SpringSecurityFilter {
|
|
|
|
|
|
private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();
|
|
private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();
|
|
|
|
|
|
|
|
+ private String invalidSessionUrl;
|
|
|
|
+
|
|
public SessionManagementFilter(SecurityContextRepository securityContextRepository) {
|
|
public SessionManagementFilter(SecurityContextRepository securityContextRepository) {
|
|
this.securityContextRepository = securityContextRepository;
|
|
this.securityContextRepository = securityContextRepository;
|
|
}
|
|
}
|
|
@@ -60,12 +62,23 @@ public class SessionManagementFilter extends SpringSecurityFilter {
|
|
if (authentication != null && !authenticationTrustResolver.isAnonymous(authentication)) {
|
|
if (authentication != null && !authenticationTrustResolver.isAnonymous(authentication)) {
|
|
// The user has been authenticated during the current request, so call the session strategy
|
|
// The user has been authenticated during the current request, so call the session strategy
|
|
sessionStrategy.onAuthenticationSuccess(authentication, request, response);
|
|
sessionStrategy.onAuthenticationSuccess(authentication, request, response);
|
|
|
|
+ } else {
|
|
|
|
+ // No security context or authentication present. Check for a session timeout
|
|
|
|
+ if (request.getRequestedSessionId() != null && !request.isRequestedSessionIdValid()) {
|
|
|
|
+ invalidSessionRequested(request, response);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
chain.doFilter(request, response);
|
|
chain.doFilter(request, response);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ protected void invalidSessionRequested(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
+ if (invalidSessionUrl != null) {
|
|
|
|
+ response.sendRedirect(invalidSessionUrl);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Sets the strategy object which handles the session management behaviour when a
|
|
* Sets the strategy object which handles the session management behaviour when a
|
|
* user has been authenticated during the current request.
|
|
* user has been authenticated during the current request.
|
|
@@ -76,4 +89,8 @@ public class SessionManagementFilter extends SpringSecurityFilter {
|
|
Assert.notNull(sessionStrategy, "authenticatedSessionStratedy must not be null");
|
|
Assert.notNull(sessionStrategy, "authenticatedSessionStratedy must not be null");
|
|
this.sessionStrategy = sessionStrategy;
|
|
this.sessionStrategy = sessionStrategy;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void setInvalidSessionUrl(String sessionTimeoutUrl) {
|
|
|
|
+ this.invalidSessionUrl = sessionTimeoutUrl;
|
|
|
|
+ }
|
|
}
|
|
}
|