mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 18:15:56 +08:00
update 更新 THREAD_LOCAL 初始化方法支持异步 ;
update 更新 RepeatSubmitAspect 方法以防强转报错 ; update 更新 ResourcesConfig 拦截器重写方法删除用户缓存 ; delete 删除 UserInfoInterceptor ;
This commit is contained in:
parent
daa6ebb1bd
commit
c182fcd103
@ -11,9 +11,14 @@ import java.util.Map;
|
|||||||
public class ThreadLocalHolder {
|
public class ThreadLocalHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化 (支持异步)
|
||||||
*/
|
*/
|
||||||
private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL = ThreadLocal.withInitial(HashMap::new);
|
private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL = new InheritableThreadLocal<>() {
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> initialValue() {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置值
|
* 设置值
|
||||||
|
|||||||
@ -83,7 +83,8 @@ public class RepeatSubmitAspect {
|
|||||||
if (r.getCode() == R.SUCCESS) {
|
if (r.getCode() == R.SUCCESS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RedisUtils.deleteObject((String) ThreadLocalHolder.get(KEY_CACHE));
|
String cacheKey = ThreadLocalHolder.get(KEY_CACHE);
|
||||||
|
RedisUtils.deleteObject(cacheKey);
|
||||||
} finally {
|
} finally {
|
||||||
ThreadLocalHolder.remove(KEY_CACHE);
|
ThreadLocalHolder.remove(KEY_CACHE);
|
||||||
}
|
}
|
||||||
@ -98,7 +99,8 @@ public class RepeatSubmitAspect {
|
|||||||
*/
|
*/
|
||||||
@AfterThrowing(value = "@annotation(repeatSubmit)", throwing = "e")
|
@AfterThrowing(value = "@annotation(repeatSubmit)", throwing = "e")
|
||||||
public void doAfterThrowing(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Exception e) {
|
public void doAfterThrowing(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Exception e) {
|
||||||
RedisUtils.deleteObject((String) ThreadLocalHolder.get(KEY_CACHE));
|
String cacheKey = ThreadLocalHolder.get(KEY_CACHE);
|
||||||
|
RedisUtils.deleteObject(cacheKey);
|
||||||
ThreadLocalHolder.remove(KEY_CACHE);
|
ThreadLocalHolder.remove(KEY_CACHE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import cn.dev33.satoken.exception.NotLoginException;
|
|||||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
import cn.dev33.satoken.router.SaRouter;
|
import cn.dev33.satoken.router.SaRouter;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.dromara.common.core.utils.ServletUtils;
|
import org.dromara.common.core.utils.ServletUtils;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
@ -70,7 +72,13 @@ public class SecurityConfig implements WebMvcConfigurer {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
});
|
});
|
||||||
})).addPathPatterns("/**")
|
})
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||||
|
ThreadLocalHolder.remove(LoginHelper.LOGIN_USER_KEY);
|
||||||
|
}
|
||||||
|
}).addPathPatterns("/**")
|
||||||
// 排除不需要拦截的路径
|
// 排除不需要拦截的路径
|
||||||
.excludePathPatterns(securityProperties.getExcludes());
|
.excludePathPatterns(securityProperties.getExcludes());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package org.dromara.common.web.config;
|
package org.dromara.common.web.config;
|
||||||
|
|
||||||
import org.dromara.common.web.interceptor.PlusWebInvokeTimeInterceptor;
|
import org.dromara.common.web.interceptor.PlusWebInvokeTimeInterceptor;
|
||||||
import org.dromara.common.web.interceptor.UserInfoInterceptor;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
@ -23,8 +22,6 @@ public class ResourcesConfig implements WebMvcConfigurer {
|
|||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// 全局访问性能拦截
|
// 全局访问性能拦截
|
||||||
registry.addInterceptor(new PlusWebInvokeTimeInterceptor());
|
registry.addInterceptor(new PlusWebInvokeTimeInterceptor());
|
||||||
// 用户信息拦截
|
|
||||||
registry.addInterceptor(new UserInfoInterceptor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
package org.dromara.common.web.interceptor;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.dromara.common.core.constant.UserConstants;
|
|
||||||
import org.dromara.common.core.context.ThreadLocalHolder;
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户信息拦截器
|
|
||||||
*
|
|
||||||
* @author Michelle.Chung
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class UserInfoInterceptor implements HandlerInterceptor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
||||||
if (ObjectUtil.isNotNull(ThreadLocalHolder.get(UserConstants.LOGIN_USER_KEY))) {
|
|
||||||
// 清除用户信息
|
|
||||||
ThreadLocalHolder.remove(UserConstants.LOGIN_USER_KEY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user