| | |
| | | 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; |
| | |
| | | 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")); |