Skip to content

Commit d98d23e

Browse files
committed
Fix HttpServlet3RequestFactory Logout Handlers
Previously there was a problem with Servlet API logout integration when Servlet API was configured before log out. This ensures that logout handlers is a reference to the logout handlers vs copying the logout handlers. This ensures that the ordering does not matter. Closes gh-4760
1 parent f892746 commit d98d23e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

web/src/main/java/org/springframework/security/web/servletapi/HttpServlet3RequestFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.springframework.security.core.context.SecurityContext;
4343
import org.springframework.security.core.context.SecurityContextHolder;
4444
import org.springframework.security.web.AuthenticationEntryPoint;
45-
import org.springframework.security.web.authentication.logout.CompositeLogoutHandler;
4645
import org.springframework.security.web.authentication.logout.LogoutHandler;
4746
import org.springframework.util.Assert;
4847
import org.springframework.util.CollectionUtils;
@@ -82,7 +81,7 @@ final class HttpServlet3RequestFactory implements HttpServletRequestFactory {
8281
private AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
8382
private AuthenticationEntryPoint authenticationEntryPoint;
8483
private AuthenticationManager authenticationManager;
85-
private LogoutHandler logoutHandler;
84+
private List<LogoutHandler> logoutHandlers;
8685

8786
HttpServlet3RequestFactory(String rolePrefix) {
8887
this.rolePrefix = rolePrefix;
@@ -146,7 +145,7 @@ public void setAuthenticationManager(AuthenticationManager authenticationManager
146145
* {@link HttpServletRequest#logout()}.
147146
*/
148147
public void setLogoutHandlers(List<LogoutHandler> logoutHandlers) {
149-
this.logoutHandler = CollectionUtils.isEmpty(logoutHandlers) ? null : new CompositeLogoutHandler(logoutHandlers);
148+
this.logoutHandlers = logoutHandlers;
150149
}
151150

152151
/**
@@ -246,16 +245,18 @@ public void login(String username, String password) throws ServletException {
246245

247246
@Override
248247
public void logout() throws ServletException {
249-
LogoutHandler handler = HttpServlet3RequestFactory.this.logoutHandler;
250-
if (handler == null) {
248+
List<LogoutHandler> handlers = HttpServlet3RequestFactory.this.logoutHandlers;
249+
if (CollectionUtils.isEmpty(handlers)) {
251250
HttpServlet3RequestFactory.this.logger.debug(
252251
"logoutHandlers is null, so allowing original HttpServletRequest to handle logout");
253252
super.logout();
254253
return;
255254
}
256255
Authentication authentication = SecurityContextHolder.getContext()
257256
.getAuthentication();
258-
handler.logout(this, this.response, authentication);
257+
for (LogoutHandler handler : handlers) {
258+
handler.logout(this, this.response, authentication);
259+
}
259260
}
260261

261262
private boolean isAuthenticated() {

0 commit comments

Comments
 (0)