I have some spring-boot
application (it exposes rest api). The mentioned REST API
is secured by spring-security
. Everything is fine, however now I need
On your second question: clear thread local in the same filter in which you set it.
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
boolean contextSetViaThreadLocal = false;
if (authentication != null && authentication.isAuthenticated()) {
contextSetViaThreadLocal = true;
// here we set context
}
// immediately after the conditional context store
try {
filterChain.doFilter(request, response);
} finally {
if (contextSetViaThreadLocal) {
// clear the context
}
}