Reputation: 6363
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
Upvotes: 4
Views: 2053
Reputation: 827
Nice answer . it worked for me.
with new version of spring security :
RememberMeAuthenticationToken auth = new RememberMeAuthenticationToken("your key",userDetails, autorities);
String p = request.getParameter("rememberme");
// your request need this parameter
Authentication authenticatedUser = authenticationManager.authenticate(auth);
SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
myrememberMeService.loginSuccess(request, response, authenticatedUser);
Upvotes: 1
Reputation: 6363
The solution is the following:
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);
Upvotes: 4