After user registration I want the user to be automatically logged in. This what I got so far:
private void doLogin(DuneUser user) {
UserDetails userDetails = UserDetailsAdapter.adapt(user);
Authentication authentication = UsernamePasswordAuthenticationToken.authenticated(
userDetails,
null,
userDetails.getAuthorities()
);
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
securityContextRepository.saveContext(context, VaadinServletRequest.getCurrent(), VaadinServletResponse.getCurrent());
VaadinServletRequest.getCurrent().changeSessionId();
UI.getCurrent().navigate("/");
}
I avoided using the AuthenticationManager deliberately.
In my SecurityConfigration I registered the SecurityContextRepository as a bean and configured it in the filter chain.
I’m not sure if this is a proper implementation.