I am having the @PreAuthorize("hasRole('ADMIN')")
check methods when I am calling from the UI (It will take around 2 to 3 hours meanwhile session is getting expired) I am geetting the SecurityContext
as null
.
Tried with MODE_INHERITABLETHREADLOCAL
, but I'm still getting the same error.
Also I tried the following code:
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();
}
}
});
}
}
but I'm still getting the same error:
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext