I am upgrading an application to Spring Boot 3. We are using a custom authentication framework where we manually set the authentication object after authenticating the user.
After logging the user in, we call SecurityContextHolder.getContext().setAuthentication(authentication);
. This has worked in previous Spring Boot/Security versions without issue. However, after the upgrade SecurityContextHolder.getContext().getAuthentication()
returns an AnonymousAuthenticationToken and not the Token we use and need to authenticate and authorise users. The odd thing is that the first time the authentication is checked it contains the proper token, but any time I call SecurityContextHolder.getContext().getAuthentication()
after that it returns an AnonymousAuthenticationToken.
Has anyone experienced something similar? This is a Vaadin application, if it makes a difference.
I have found the following tips in the spring docs:
For example, the following code:
SecurityContextHolder.setContext(securityContext);
should be replaced withSecurityContextHolder.setContext(securityContext); securityContextRepository.saveContext(securityContext, httpServletRequest, httpServletResponse);
However, this is not really useful to me, as this is a Vaadin application and I'm not handling any requests myself.