mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-12-26 22:25:39 +08:00
处理因jfinal,jboot默认序列化方法不同导致的乱码问题,统一使用SaJdkSerializer进行缓存序列化
This commit is contained in:
@@ -42,7 +42,7 @@ public class PathAnalyzer {
|
||||
p = p.replace("$", "\\$");
|
||||
p = p.replace("**", ".[]");
|
||||
p = p.replace("*", "[^/]*");
|
||||
if (p.indexOf("{") >= 0) {
|
||||
if (p.contains("{")) {
|
||||
if (p.indexOf("_}") > 0) {
|
||||
p = p.replaceAll("\\{[^\\}]+?\\_\\}", "(.+?)");
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.jfinal.render.RenderManager;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class SaTokenActionHandler extends ActionHandler {
|
||||
protected boolean devMode;
|
||||
protected ActionMapping actionMapping;
|
||||
|
||||
@@ -11,9 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 缓存处理类
|
||||
*/
|
||||
public class SaTokenDaoRedis implements SaTokenDao {
|
||||
|
||||
protected Cache redis;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package cn.dev33.satoken.jfinal.test;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.config.SaCookieConfig;
|
||||
import cn.dev33.satoken.config.SaTokenConfig;
|
||||
import cn.dev33.satoken.context.SaTokenContext;
|
||||
import cn.dev33.satoken.jfinal.*;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import com.jfinal.config.*;
|
||||
import com.jfinal.plugin.redis.RedisPlugin;
|
||||
import com.jfinal.plugin.redis.serializer.ISerializer;
|
||||
import com.jfinal.template.Engine;
|
||||
|
||||
public class Config extends JFinalConfig {
|
||||
@@ -15,7 +19,17 @@ public class Config extends JFinalConfig {
|
||||
SaManager.setSaTokenContext(saTokenContext);
|
||||
//加载权限角色设置数据接口
|
||||
SaManager.setStpInterface(new StpInterfaceImpl());
|
||||
|
||||
//设置token生成类型
|
||||
SaTokenConfig saTokenConfig = new SaTokenConfig();
|
||||
saTokenConfig.setTokenStyle(SaTokenConsts.TOKEN_STYLE_SIMPLE_UUID);
|
||||
saTokenConfig.setTimeout(60*60*4); //登录有效时间4小时
|
||||
saTokenConfig.setActivityTimeout(30*60); //半小时无操作过期处理
|
||||
saTokenConfig.setIsShare(false);
|
||||
saTokenConfig.setTokenName("token"); //更改satoken的cookies名称
|
||||
SaCookieConfig saCookieConfig = new SaCookieConfig();
|
||||
saCookieConfig.setHttpOnly(true); //开启cookies 的httponly属性
|
||||
saTokenConfig.setCookie(saCookieConfig);
|
||||
SaManager.setConfig(saTokenConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,7 +51,7 @@ public class Config extends JFinalConfig {
|
||||
@Override
|
||||
public void configPlugin(Plugins plugins) {
|
||||
//添加redis扩展
|
||||
// plugins.add(createRedisPlugin("satoken",10));
|
||||
plugins.add(createRedisPlugin("satoken",1, SaJdkSerializer.me));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,16 +70,17 @@ public class Config extends JFinalConfig {
|
||||
* 创建Redis插件
|
||||
* @param name 名称
|
||||
* @param dbIndex 使用的库ID
|
||||
* @param serializer 自定义序列化方法
|
||||
* @return
|
||||
*/
|
||||
private RedisPlugin createRedisPlugin(String name, Integer dbIndex) {
|
||||
RedisPlugin redisPlugin=new RedisPlugin(name, "redis-host", 6379, 3000,"pwd",dbIndex);
|
||||
redisPlugin.setSerializer(SaJdkSerializer.me);
|
||||
private RedisPlugin createRedisPlugin(String name, Integer dbIndex, ISerializer serializer) {
|
||||
RedisPlugin redisPlugin = new RedisPlugin(name, "redis-host", 6379, 3000,"pwd",dbIndex);
|
||||
redisPlugin.setSerializer(serializer);
|
||||
return redisPlugin;
|
||||
}
|
||||
@Override
|
||||
public void onStart(){
|
||||
//增加redis缓存,需要先配置redis地址
|
||||
// SaManager.setSaTokenDao(new SaTokenDaoRedis("satoken"));
|
||||
SaManager.setSaTokenDao(new SaTokenDaoRedis("satoken"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user