资源简介
NULL
博文链接:https://309593586-qq-com.iteye.com/blog/2415463
代码片段和文件信息
package springboot.example;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashSet;
import java.util.linkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import org.springframework.session.Session;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.CookieSerializer.CookieValue;
import org.springframework.session.web.http.DefaultCookieSerializer;
import org.springframework.session.web.http.HeaderHttpSessionStrategy;
import org.springframework.session.web.http.HttpSessionManager;
import org.springframework.session.web.http.MultiHttpSessionStrategy;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* 综合了cookie和header策略
* @author TWSW
*
*/
public class CookieHeaderHttpSessionStrategy implements MultiHttpSessionStrategy HttpSessionManager {
private String headerName = “x-auth-token“;
/**
* The default delimiter for both serialization and deserialization.
*/
private static final String DEFAULT_DELIMITER = “ “;
private static final String SESSION_IDS_WRITTEN_ATTR = CookieHeaderHttpSessionStrategy.class
.getName().concat(“.SESSIONS_WRITTEN_ATTR“);
static final String DEFAULT_ALIAS = “0“;
static final String DEFAULT_SESSION_ALIAS_PARAM_NAME = “_s“;
private static final Pattern ALIAS_PATTERN = Pattern.compile(“^[\\w-]{150}$“);
private String sessionParam = DEFAULT_SESSION_ALIAS_PARAM_NAME;
private CookieSerializer cookieSerializer = new DefaultCookieSerializer();
/**
* The delimiter between a session alias and a session id when reading a cookie value.
* The default value is “ “.
*/
private String deserializationDelimiter = DEFAULT_DELIMITER;
/**
* The delimiter between a session alias and a session id when writing a cookie value.
* The default is “ “.
*/
private String serializationDelimiter = DEFAULT_DELIMITER;
public void setHeaderName(String headerName) {
Assert.notNull(headerName “headerName cannot be null“);
this.headerName = headerName;
}
public String getRequestedSessionId(HttpServletRequest request) {
String authToken = request.getHeader(this.headerName);
if(StringUtils.hasText(authToken)){
return authToken;
}else{
Map sessionIds = getSessionIds(request);
String sessionAlias = getCurrentSessionAlias(request);
String sessionId= sessionIds.get(sessionAlias);
return sessionId;
}
}
public String getCurrentSessionAlias(HttpServletRequest request) {
if (this.sessionParam == null) {
return DEFAULT_ALIAS;
}
String u = request.getParameter(this.sessionParam);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12288 2018-01-19 15:32 CookieHeaderHttpSessionStrategy.java
相关资源
- redis使用过程中由于序列化工具引起的
- OpenCV+SVM简单应用-------路面箭头分类
- IM_layim
- Bootstrap学习笔记之Nestable可拖拽树结构
- jersey 2.2 +spring 3.1.0.RELEASE+hibernate 3.3
- 视图对象VO、DTO的应用!
- QTreeView 使用自定义Model
- 页面分区域展示
- 海量图片的分布式存储及负载均衡研
- 网上票务系统概要设计二
- util类
- CKEDITOR 编辑器本地上传图片好
-
ba
se64加密解密的hive udf函数 - 精通Hadoop电子书(中文版)
- 将文件到指定路径的OCX控件
- 绿色版FTP quick easy ftp server
- 如何将windows里面的文件导入到Linux虚
- 终于成功使用asdoc生成了文档
- 画图板总结
- PageRank&HITS算法
- Hibernate 单表实现树结构
- 天气预报案例
- 使用cisco模拟器组建局域网
- 惠普HP 4411s拆机 图文教程 适用于441
- 基于SOA和ESB企业总线的OSGi企业级应用
-
将图片转成二进制并生成ba
se64编码 - [教程] 任意形状的碰撞检测 原理(附
- 五子棋(含较高级的人机对战)
-
Actionsc
ript 3.0 Game Programming Universit - sap LSMW
评论
共有 条评论