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
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);
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.