当我从用户界面调用时,我正在使用@PreAuthorize("hasRole('ADMIN')")
检查方法(会话过期需要大约2到3个小时)我正在将SecurityContext
设为null
}。
尝试使用MODE_INHERITABLETHREADLOCAL
,但我仍然遇到同样的错误。
我还尝试了以下代码:
public class CustomThreadPoolTaskExecutor extends ThreadPoolTaskExecutor{
@Override
public void execute(final Runnable r) {
final Authentication a = SecurityContextHolder.getContext().getAuthentication();
super.execute(new Runnable() {
public void run() {
try {
SecurityContext ctx = SecurityContextHolder.createEmptyContext();
ctx.setAuthentication(a);
SecurityContextHolder.setContext(ctx);
r.run();
} finally {
SecurityContextHolder.clearContext();
}
}
});
}
}
但我仍然遇到同样的错误:
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException:在SecurityContext中找不到Authentication对象