
Originally Posted by
Luke Taylor
You may want to use the AuthenticationManager to do the programmatic authentication, in order to tie into the event infrastructure, but it's up to you, depending on your requirements.
Thanks for the response. Yes we are currently using the AuthenticationManager which is injected into the action that creates the account.
So doing something like the following is the best practice with spring security after account creation?
Code:
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user, pw);
token.setDetails(new WebAuthenticationDetails(request));
Authentication authentication = authenticationManager.authenticate(token);
authInitializer.initializeAuthenticatedUser(request, authentication);
SecurityContextHolder.getContext().setAuthentication(authentication);