Manual authentication with spring security and remember me provider
java, spring, spring-mvc, spring-security
Solution
The solution is the following:
- Check user's password
Authorize user:
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getEmail(), user.getPassword());
token.setDetails(new WebAuthenticationDetails(request));
Authentication authenticatedUser = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
Autowire `rememberMeService` and call:
`rememberMeServices.onLoginSuccess(request, response, authenticatedUser);`
Problem
I need to implement a manual login process. The authentication works fine: ``` UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getEmail(), user.getPassword()); token.setDetails(new WebAuthenticationDetails(request)); Authentication authenticatedUser = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authenticatedUser); ``` But how can I use remember me provider in this case? Thank you in advance