@@ -106,6 +106,8 @@ public class SessionRepositoryFilter<S extends Session> extends OncePerRequestFi
106
106
107
107
private HttpSessionIdResolver httpSessionIdResolver = new CookieHttpSessionIdResolver ();
108
108
109
+ private boolean commitSessionOncePerRequest = false ;
110
+
109
111
/**
110
112
* Creates a new instance.
111
113
* @param sessionRepository the <code>SessionRepository</code> to use. Cannot be null.
@@ -130,6 +132,15 @@ public void setHttpSessionIdResolver(HttpSessionIdResolver httpSessionIdResolver
130
132
this .httpSessionIdResolver = httpSessionIdResolver ;
131
133
}
132
134
135
+ /**
136
+ * Sets the {@link #commitSessionOncePerRequest} to be used. The default is a
137
+ * {@code false}.
138
+ * @param commitSessionOncePerRequest the value to use.
139
+ */
140
+ public void setCommitSessionOncePerRequest (boolean commitSessionOncePerRequest ) {
141
+ this .commitSessionOncePerRequest = commitSessionOncePerRequest ;
142
+ }
143
+
133
144
@ Override
134
145
protected void doFilterInternal (HttpServletRequest request , HttpServletResponse response , FilterChain filterChain )
135
146
throws ServletException , IOException {
@@ -207,6 +218,8 @@ private final class SessionRepositoryRequestWrapper extends HttpServletRequestWr
207
218
208
219
private boolean hasCommittedInInclude ;
209
220
221
+ private boolean committed ;
222
+
210
223
private SessionRepositoryRequestWrapper (HttpServletRequest request , HttpServletResponse response ) {
211
224
super (request );
212
225
this .response = response ;
@@ -217,6 +230,10 @@ private SessionRepositoryRequestWrapper(HttpServletRequest request, HttpServletR
217
230
* and persist the Session.
218
231
*/
219
232
private void commitSession () {
233
+ if (this .committed && SessionRepositoryFilter .this .commitSessionOncePerRequest ) {
234
+ return ;
235
+ }
236
+ this .committed = true ;
220
237
HttpSessionWrapper wrappedSession = getCurrentSession ();
221
238
if (wrappedSession == null ) {
222
239
if (isInvalidateClientSession ()) {
0 commit comments