fix : 路由关键key改为登录uuid
This commit is contained in:
@@ -72,6 +72,7 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
|||||||
@Override
|
@Override
|
||||||
public void force(String tokenId) {
|
public void force(String tokenId) {
|
||||||
redisTemplate.delete(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
|
redisTemplate.delete(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
|
||||||
|
redisTemplate.delete(CacheConstants.ROUTE_CACHE_KEY + tokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnlineUser toOnlineUser(LoginUser user) {
|
private OnlineUser toOnlineUser(LoginUser user) {
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
batchUserPost(dto, Boolean.TRUE);
|
batchUserPost(dto, Boolean.TRUE);
|
||||||
dto.setPassword(null);
|
dto.setPassword(null);
|
||||||
UserBase user = dto.toUser();
|
UserBase user = dto.toUser();
|
||||||
|
|
||||||
return userMapper.update(user);
|
return userMapper.update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.springframework.security.authentication.BadCredentialsException;
|
|||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -95,7 +96,7 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
throw new CustomException("验证码错误!");
|
throw new CustomException("验证码错误!");
|
||||||
}
|
}
|
||||||
redisTemplate.delete(uuid);
|
redisTemplate.delete(uuid);
|
||||||
//用户验证
|
//用户验证
|
||||||
Authentication authentication = null;
|
Authentication authentication = null;
|
||||||
try {
|
try {
|
||||||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
||||||
@@ -156,11 +157,15 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RouterVo> getMenuRouterByUserId() {
|
public List<RouterVo> getMenuRouterByUserId() {
|
||||||
List<RouterVo> result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId());
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
|
if (ObjectUtils.isEmpty(loginUser)){
|
||||||
|
throw new CustomException("获取用户信息失败!");
|
||||||
|
}
|
||||||
|
List<RouterVo> result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid());
|
||||||
if (result == null || result.isEmpty()) {
|
if (result == null || result.isEmpty()) {
|
||||||
RLock lock = redissonClient.getLock(CacheConstants.ROUTE_CACHE_KEY + "lock:" + SecurityUtils.getUserId());
|
RLock lock = redissonClient.getLock(CacheConstants.ROUTE_CACHE_KEY + "lock:" + loginUser.getUuid());
|
||||||
try {
|
try {
|
||||||
result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId());
|
result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid());
|
||||||
if (result == null || result.isEmpty()) {
|
if (result == null || result.isEmpty()) {
|
||||||
result = menuService.selectMenuRouterByUserId(SecurityUtils.getUserId());
|
result = menuService.selectMenuRouterByUserId(SecurityUtils.getUserId());
|
||||||
if (result == null || result.isEmpty()) {
|
if (result == null || result.isEmpty()) {
|
||||||
@@ -168,7 +173,7 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
// throw new CustomException("获取路由异常!");
|
// throw new CustomException("获取路由异常!");
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
redisTemplate.opsForValue().set(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId(),result,30, TimeUnit.MINUTES);
|
redisTemplate.opsForValue().set(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid(), result, 30, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class CacheConstants {
|
|||||||
/**
|
/**
|
||||||
* 路由缓存地址
|
* 路由缓存地址
|
||||||
*/
|
*/
|
||||||
public static final String ROUTE_CACHE_KEY = "router_key:";
|
public static final String ROUTE_CACHE_KEY = "router:key:";
|
||||||
/**
|
/**
|
||||||
* 登录用户 redis key
|
* 登录用户 redis key
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user