Login Issues after migration to Vaadin 24

I have a problem with the login to my Vaadin application after migrating Vaadin from 23 to 24 and Spring Boot from 2.7 to 3.2.
I have a custom LoginView. When the user has entered the credentials, these are verified by an REST Api call. If this call is successful, I set the Authentication by the following code snippet:
CustomPrincipal principal = new CustomPrincipal(tenant, domain, username); Authentication auth = new UsernamePasswordAuthenticationToken(principal, password, Collections.emptyList()); SecurityContextHolder.getContext().setAuthentication(auth);

Then I have access to my start page. But whenever I try to navigate to another page, I get redirected to the login page. The Log contains the following message:
Access to view 'my.app.view.CustomView' with path 'customView' is denied

The CustomView hat the Annotation @PermitAll
Does anyone has seen a problem like this or an idea what I am missing?

Maybe the import is wrong?
import jakarta.annotation.security.PermitAll;

Thanks for the suggestion, but I already moved my imports to jakarta.

I’ve had this or something similar. I think you need to save context after setting the authentication

@Autowired
private SecurityContextRepository securityContextRepository;
...
SecurityContextHolder.getContext().setAuthentication(auth);
securityContextRepository.saveContext(SecurityContextHolder.getContext(), getRequest(), getResponse());
private static HttpServletRequest getRequest() {
    return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
}

private static HttpServletResponse getResponse() {
    return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getResponse();
}

Thanks a lot! Creating a SecurityContextRepository bean and saving the context has fixed the problem.