fix redis反序列化异常问题
This commit is contained in:
parent
ca903ebd1f
commit
3131b7ea9d
|
@ -81,6 +81,7 @@ public class LoginUser implements UserDetails
|
||||||
return user.getPassword();
|
return user.getPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Override
|
@Override
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
|
@ -133,6 +134,7 @@ public class LoginUser implements UserDetails
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities()
|
public Collection<? extends GrantedAuthority> getAuthorities()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
package com.ruoyi.framework.config;
|
package com.ruoyi.framework.config;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
|
||||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* redis配置
|
* redis配置
|
||||||
|
@ -30,19 +25,15 @@ public class RedisConfig extends CachingConfigurerSupport
|
||||||
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||||
template.setConnectionFactory(connectionFactory);
|
template.setConnectionFactory(connectionFactory);
|
||||||
|
|
||||||
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);
|
GenericFastJsonRedisSerializer serializer = new GenericFastJsonRedisSerializer();
|
||||||
|
StringRedisSerializer keySerializer = new StringRedisSerializer();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
||||||
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
|
||||||
serializer.setObjectMapper(mapper);
|
|
||||||
|
|
||||||
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||||
template.setKeySerializer(new StringRedisSerializer());
|
template.setKeySerializer(keySerializer);
|
||||||
template.setValueSerializer(serializer);
|
template.setValueSerializer(serializer);
|
||||||
|
|
||||||
// Hash的key也采用StringRedisSerializer的序列化方式
|
// Hash的key也采用StringRedisSerializer的序列化方式
|
||||||
template.setHashKeySerializer(new StringRedisSerializer());
|
template.setHashKeySerializer(keySerializer);
|
||||||
template.setHashValueSerializer(serializer);
|
template.setHashValueSerializer(serializer);
|
||||||
|
|
||||||
template.afterPropertiesSet();
|
template.afterPropertiesSet();
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
package com.ruoyi.framework.web.service;
|
package com.ruoyi.framework.web.service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
|
@ -22,6 +15,14 @@ import com.ruoyi.common.utils.ip.IpUtils;
|
||||||
import com.ruoyi.framework.manager.AsyncManager;
|
import com.ruoyi.framework.manager.AsyncManager;
|
||||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录校验方法
|
* 登录校验方法
|
||||||
|
@ -102,6 +103,7 @@ public class SysLoginService
|
||||||
{
|
{
|
||||||
user.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
user.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
||||||
user.setLoginDate(DateUtils.getNowDate());
|
user.setLoginDate(DateUtils.getNowDate());
|
||||||
|
user.setUpdateBy(user.getUserName());
|
||||||
userService.updateUserProfile(user);
|
userService.updateUserProfile(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue