packagecom.tfe.sell.common.config;importorg.springframework.session.Session;importorg.springframework.session.web.http.HeaderHttpSessionIdResolver;importorg.springframework.util.Assert;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjava.util.Collections;importjava.util.List;public class UserDefindeHttpSessionStrategy extendsHeaderHttpSessionIdResolver {private static final String HEADER_X_AUTH_TOKEN = "x-auth-token";private static final String HEADER_AUTHENTICATION_INFO = "Authentication-Info";private finalString headerName;/*** Convenience factory to create {@linkHeaderHttpSessionIdResolver} that uses
* "X-Auth-AccessToken" header.
*@returnthe instance configured to use "X-Auth-AccessToken" header*/
public staticHeaderHttpSessionIdResolver xAuthToken() {return newHeaderHttpSessionIdResolver(HEADER_X_AUTH_TOKEN);
}/*** Convenience factory to create {@linkHeaderHttpSessionIdResolver} that uses
* "Authentication-Info" header.
*@returnthe instance configured to use "Authentication-Info" header*/
public staticHeaderHttpSessionIdResolver authenticationInfo() {return newHeaderHttpSessionIdResolver(HEADER_AUTHENTICATION_INFO);
}/*** The name of the header to obtain the session id from.
*@paramheaderName the name of the header to obtain the session id from.*/
publicUserDefindeHttpSessionStrategy(String headerName) {super(headerName);this.headerName =headerName;
}
@Overridepublic ListresolveSessionIds(HttpServletRequest request) {
String headerValue= request.getHeader(this.headerName);return headerValue != null ?Collections.singletonList(headerValue)
: Collections.emptyList();
}
@Overridepublic voidsetSessionId(HttpServletRequest request, HttpServletResponse response,
String sessionId) {
response.setHeader(this.headerName, sessionId);
}
@Overridepublic voidexpireSession(HttpServletRequest request, HttpServletResponse response) {
response.setHeader(this.headerName, "");
}
}