Skip to content

Commit 095929f

Browse files
ilpyoyangmarcusdacoregio
authored andcommitted
Include FilterChain in SessionInformationExpiredEvent
Closes gh-14077
1 parent 3117fef commit 095929f

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

web/src/main/java/org/springframework/security/web/session/ConcurrentSessionFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -141,7 +141,7 @@ private void doFilter(HttpServletRequest request, HttpServletResponse response,
141141
.of(() -> "Requested session ID " + request.getRequestedSessionId() + " has expired."));
142142
doLogout(request, response);
143143
this.sessionInformationExpiredStrategy
144-
.onExpiredSessionDetected(new SessionInformationExpiredEvent(info, request, response));
144+
.onExpiredSessionDetected(new SessionInformationExpiredEvent(info, request, response, chain));
145145
return;
146146
}
147147
// Non-expired - update last request date/time

web/src/main/java/org/springframework/security/web/session/SessionInformationExpiredEvent.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.web.session;
1818

19+
import jakarta.servlet.FilterChain;
1920
import jakarta.servlet.http.HttpServletRequest;
2021
import jakarta.servlet.http.HttpServletResponse;
2122

@@ -35,6 +36,8 @@ public final class SessionInformationExpiredEvent extends ApplicationEvent {
3536

3637
private final HttpServletResponse response;
3738

39+
private final FilterChain filterChain;
40+
3841
/**
3942
* Creates a new instance
4043
* @param sessionInformation the SessionInformation that is expired
@@ -43,11 +46,25 @@ public final class SessionInformationExpiredEvent extends ApplicationEvent {
4346
*/
4447
public SessionInformationExpiredEvent(SessionInformation sessionInformation, HttpServletRequest request,
4548
HttpServletResponse response) {
49+
this(sessionInformation, request, response, null);
50+
}
51+
52+
/**
53+
* Creates a new instance
54+
* @param sessionInformation the SessionInformation that is expired
55+
* @param request the HttpServletRequest
56+
* @param response the HttpServletResponse
57+
* @param filterChain the FilterChain
58+
* @since 6.4
59+
*/
60+
public SessionInformationExpiredEvent(SessionInformation sessionInformation, HttpServletRequest request,
61+
HttpServletResponse response, FilterChain filterChain) {
4662
super(sessionInformation);
4763
Assert.notNull(request, "request cannot be null");
4864
Assert.notNull(response, "response cannot be null");
4965
this.request = request;
5066
this.response = response;
67+
this.filterChain = filterChain;
5168
}
5269

5370
/**
@@ -68,4 +85,12 @@ public SessionInformation getSessionInformation() {
6885
return (SessionInformation) getSource();
6986
}
7087

88+
/**
89+
* @return the filter chain. Can be {@code null}.
90+
* @since 6.4
91+
*/
92+
public FilterChain getFilterChain() {
93+
return this.filterChain;
94+
}
95+
7196
}

web/src/test/java/org/springframework/security/web/session/SessionInformationExpiredEventTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,12 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23+
import org.springframework.mock.web.MockFilterChain;
2324
import org.springframework.mock.web.MockHttpServletRequest;
2425
import org.springframework.mock.web.MockHttpServletResponse;
2526
import org.springframework.security.core.session.SessionInformation;
2627

28+
import static org.assertj.core.api.Assertions.assertThat;
2729
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2830

2931
/**
@@ -50,4 +52,13 @@ public void constructorWhenResponseNullThenThrowsException() {
5052
new SessionInformation("fake", "sessionId", new Date()), new MockHttpServletRequest(), null));
5153
}
5254

55+
@Test
56+
void constructorWhenFilterChainThenGetFilterChainReturnsNotNull() {
57+
MockFilterChain filterChain = new MockFilterChain();
58+
SessionInformationExpiredEvent event = new SessionInformationExpiredEvent(
59+
new SessionInformation("fake", "sessionId", new Date()), new MockHttpServletRequest(),
60+
new MockHttpServletResponse(), filterChain);
61+
assertThat(event.getFilterChain()).isSameAs(filterChain);
62+
}
63+
5364
}

0 commit comments

Comments
 (0)