Commit 9815f182 authored by cy's avatar cy

Merge remote-tracking branch 'origin/master'

parents 03a0d007 97402e78
...@@ -21,8 +21,8 @@ public class RedisConfig { ...@@ -21,8 +21,8 @@ public class RedisConfig {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new StringRedisSerializer()); redisTemplate.setHashValueSerializer(new SerializeUtils());
redisTemplate.setValueSerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new SerializeUtils());
redisTemplate.setConnectionFactory(factory); redisTemplate.setConnectionFactory(factory);
return redisTemplate; return redisTemplate;
} }
......
package cn.wisenergy.common.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import java.io.*;
/**
* @author: nh
* @date: 2021/04/08
* @description: redis的value序列化工具
*/
public class SerializeUtils implements RedisSerializer {
private static Logger logger = LoggerFactory.getLogger(SerializeUtils.class);
public static boolean isEmpty(byte[] data) {
return (data == null || data.length == 0);
}
/**
* 序列化
*
* @param object
* @return
* @throws SerializationException
*/
@Override
public byte[] serialize(Object object) throws SerializationException {
byte[] result = null;
if (object == null) {
return new byte[0];
}
try (
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(128);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteStream)
) {
if (!(object instanceof Serializable)) {
throw new IllegalArgumentException(SerializeUtils.class.getSimpleName() + " requires a Serializable payload " +
"but received an object of type [" + object.getClass().getName() + "]");
}
objectOutputStream.writeObject(object);
objectOutputStream.flush();
result = byteStream.toByteArray();
} catch (Exception ex) {
logger.error("Failed to serialize", ex);
}
return result;
}
/**
* 反序列化
*
* @param bytes
* @return
* @throws SerializationException
*/
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
Object result = null;
if (isEmpty(bytes)) {
return null;
}
try (
ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
ObjectInputStream objectInputStream = new ObjectInputStream(byteStream)
) {
result = objectInputStream.readObject();
} catch (Exception e) {
logger.error("Failed to deserialize", e);
}
return result;
}
}
\ No newline at end of file
...@@ -63,6 +63,9 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, User> impleme ...@@ -63,6 +63,9 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, User> impleme
@Autowired @Autowired
private RedisService redisService; private RedisService redisService;
@Autowired
private KickoutSessionControlFilter kickoutSessionControlFilter;
//VIP客户初始密码 //VIP客户初始密码
private static final String PASSWORD = "123456"; private static final String PASSWORD = "123456";
...@@ -206,8 +209,7 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, User> impleme ...@@ -206,8 +209,7 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, User> impleme
UserToken userToken = new UserToken(userVo.getPhone(), credentialsSalt, USER_LOGIN_TYPE); UserToken userToken = new UserToken(userVo.getPhone(), credentialsSalt, USER_LOGIN_TYPE);
try { try {
subject.login(userToken); subject.login(userToken);
KickoutSessionControlFilter kitOut = new KickoutSessionControlFilter(); kickoutSessionControlFilter.changeSession(1);
kitOut.changeSession(1);
//3、构造返回参数 //3、构造返回参数
UserInfoVo userInfoVo = new UserInfoVo(); UserInfoVo userInfoVo = new UserInfoVo();
userInfoVo.setUserId(user.getId()); userInfoVo.setUserId(user.getId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment