| | |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
| | | import org.springframework.security.core.Authentication;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.constant.CacheConstants;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.exception.ServiceException;
|
| | | import com.ruoyi.common.exception.user.CaptchaException;
|
| | |
| | | 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;
|
| | |
| | | */
|
| | | public String login(String username, String password, String code, String uuid)
|
| | | {
|
| | | boolean captchaOnOff = configService.selectCaptchaOnOff();
|
| | | boolean captchaEnabled = configService.selectCaptchaEnabled();
|
| | | // 验证码开关
|
| | | if (captchaOnOff)
|
| | | if (captchaEnabled)
|
| | | {
|
| | | validateCaptcha(username, code, uuid);
|
| | | }
|
| | |
| | | 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)
|
| | | {
|
| | |
| | | */
|
| | | public void validateCaptcha(String username, String code, String uuid)
|
| | | {
|
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
|
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
|
| | | String captcha = redisCache.getCacheObject(verifyKey);
|
| | | redisCache.deleteObject(verifyKey);
|
| | | if (captcha == null)
|