guoshilong
2023-05-04 6b6807125d21dba0cf2b440e0899b1ed53d6584f
skjcmanager/skjcmanager-auth/src/main/java/cn/gistack/auth/config/MyAuthenticationProvider.java
@@ -16,6 +16,7 @@
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.oauth2.common.exceptions.UserDeniedAuthorizationException;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.time.Duration;
@@ -32,6 +33,7 @@
     * 免密常量
     */
    public static final String CUSTOM_LOGIN_SMS = "CUSTOM_LOGIN_SMS";
    public static final String CUSTOM_LOGIN_WX = "CUSTOM_LOGIN_WX";
    @Autowired
   private BladeRedis bladeRedis;
@@ -60,7 +62,7 @@
        } else {
         String password = authentication.getCredentials().toString();
         // 手机号登录时不验证密码
         if(!CUSTOM_LOGIN_SMS.equals(password)){
         if(!CUSTOM_LOGIN_SMS.equals(password)&&!CUSTOM_LOGIN_WX.equals(password)){
            HttpServletRequest request = WebUtil.getRequest();
            String grantType = request.getParameter(TokenUtil.GRANT_TYPE_KEY);
            // 获取租户ID
@@ -70,12 +72,11 @@
            String tenantId = StringUtils.isBlank(headerTenant) ? paramTenant : headerTenant;
            String detailsPassword = userDetails.getPassword().substring(7);
            if (!detailsPassword.equals(DigestUtil.hex(password))) {
               int count = getFailCount(tenantId, userDetails.getUsername());
               // 用户存在但密码错误,超过次数则锁定账号
               if (grantType != null && !grantType.equals(TokenUtil.REFRESH_TOKEN_KEY)) {
                  setFailCount(tenantId, userDetails.getUsername(), count);
                  throw new UsernameNotFoundException(TokenUtil.USER_NOT_FOUND);
                  throw new UserDeniedAuthorizationException(TokenUtil.USER_NOT_FOUND);
               }
               this.logger.debug("Failed to authenticate since password does not match stored value");
               throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));