| | |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.context.AuthenticationContextHolder;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.service.ISysConfigService;
|
| | | import com.ruoyi.project.system.service.ISysUserService;
|
| | |
| | | Authentication authentication = null;
|
| | | try
|
| | | {
|
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
|
| | | AuthenticationContextHolder.setContext(authenticationToken);
|
| | | // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
| | | authentication = authenticationManager
|
| | | .authenticate(new UsernamePasswordAuthenticationToken(username, password));
|
| | | authentication = authenticationManager.authenticate(authenticationToken);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | |
| | | throw new ServiceException(e.getMessage());
|
| | | }
|
| | | }
|
| | | finally
|
| | | {
|
| | | AuthenticationContextHolder.clearContext();
|
| | | }
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
| | | LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
| | | recordLoginInfo(loginUser.getUserId());
|