Add flag whether to create HTTP session
Issue: SPR-12840
This commit is contained in:
@@ -54,6 +54,8 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor {
|
|||||||
|
|
||||||
private boolean copyHttpSessionId = true;
|
private boolean copyHttpSessionId = true;
|
||||||
|
|
||||||
|
private boolean createSession;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for copying all HTTP session attributes and the HTTP
|
* Default constructor for copying all HTTP session attributes and the HTTP
|
||||||
@@ -121,6 +123,22 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor {
|
|||||||
return this.copyHttpSessionId;
|
return this.copyHttpSessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to allow the HTTP session to be created while accessing it.
|
||||||
|
* <p>By default set to {@code false}.
|
||||||
|
* @see javax.servlet.http.HttpServletRequest#getSession(boolean)
|
||||||
|
*/
|
||||||
|
public void setCreateSession(boolean createSession) {
|
||||||
|
this.createSession = createSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the HTTP session is allowed to be created.
|
||||||
|
*/
|
||||||
|
public boolean isCreateSession() {
|
||||||
|
return this.createSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
|
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
|
||||||
@@ -145,7 +163,7 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor {
|
|||||||
private HttpSession getSession(ServerHttpRequest request) {
|
private HttpSession getSession(ServerHttpRequest request) {
|
||||||
if (request instanceof ServletServerHttpRequest) {
|
if (request instanceof ServletServerHttpRequest) {
|
||||||
ServletServerHttpRequest serverRequest = (ServletServerHttpRequest) request;
|
ServletServerHttpRequest serverRequest = (ServletServerHttpRequest) request;
|
||||||
return serverRequest.getServletRequest().getSession(false);
|
return serverRequest.getServletRequest().getSession(isCreateSession());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user