| | |
| | | package com.ard.framework.web.service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.ard.framework.security.handle.CustomAuthenticationSuccessHandler; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.userdetails.UserDetailsService; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ard.common.constant.CacheConstants; |
| | | import com.ard.common.constant.Constants; |
| | |
| | | /** |
| | | * 登录校验方法 |
| | | * |
| | | * @author ruoyi |
| | | * @author ard |
| | | */ |
| | | @Component |
| | | public class SysLoginService |
| | |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @Resource |
| | | private CustomAuthenticationSuccessHandler successHandler; |
| | | |
| | | @Autowired |
| | | private UserDetailsService userDetailsService; |
| | | |
| | | /** |
| | | * 登录验证 |
| | |
| | | AuthenticationContextHolder.setContext(authenticationToken); |
| | | // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername |
| | | authentication = authenticationManager.authenticate(authenticationToken); |
| | | // 登录成功逻辑 |
| | | if (authentication.isAuthenticated()) { |
| | | // 检查是否已登录 |
| | | successHandler.onAuthenticationSuccess(authentication); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | if (!soloLogin) |
| | | { |
| | | // 如果用户不允许多终端同时登录,清除缓存信息 |
| | | String userIdKey = Constants.LOGIN_USERID_KEY + loginUser.getUser().getUserId(); |
| | | String userIdKey = CacheConstants.LOGIN_USERID_KEY + loginUser.getUser().getUserId(); |
| | | String userKey = redisCache.getCacheObject(userIdKey); |
| | | if (StringUtils.isNotEmpty(userKey)) |
| | | { |
| | |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); |
| | | throw new UserNotExistsException(); |
| | | } |
| | | |
| | | // 密码如果不在指定范围内 错误 |
| | | if (password.length() < UserConstants.PASSWORD_MIN_LENGTH |
| | | || password.length() > UserConstants.PASSWORD_MAX_LENGTH) |