|
|
|
@ -1,7 +1,10 @@ |
|
|
|
package com.hxhq.auth.service; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import com.hxhq.common.security.service.TokenService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import com.hxhq.common.core.constant.CacheConstants; |
|
|
|
import com.hxhq.common.core.constant.Constants; |
|
|
|
@ -27,6 +30,11 @@ public class SysPasswordService |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SysRecordLogService recordLogService; |
|
|
|
@Autowired |
|
|
|
private TokenService tokenService; |
|
|
|
|
|
|
|
@Value("${spring.profiles.active:dev}") |
|
|
|
private String activeProfile; |
|
|
|
|
|
|
|
/** |
|
|
|
* 登录账户密码错误次数缓存键名 |
|
|
|
@ -41,14 +49,14 @@ public class SysPasswordService |
|
|
|
|
|
|
|
public void validate(SysUser user, String password) |
|
|
|
{ |
|
|
|
String username = user.getUserName(); |
|
|
|
|
|
|
|
Integer retryCount = redisService.getCacheObject(getCacheKey(username)); |
|
|
|
|
|
|
|
if (retryCount == null) |
|
|
|
{ |
|
|
|
retryCount = 0; |
|
|
|
} |
|
|
|
// String username = user.getUserName(); |
|
|
|
// |
|
|
|
// Integer retryCount = redisService.getCacheObject(getCacheKey(username)); |
|
|
|
// |
|
|
|
// if (retryCount == null) |
|
|
|
// { |
|
|
|
// retryCount = 0; |
|
|
|
// } |
|
|
|
|
|
|
|
// if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) |
|
|
|
// { |
|
|
|
@ -59,20 +67,23 @@ public class SysPasswordService |
|
|
|
|
|
|
|
if (!matches(user, password)) |
|
|
|
{ |
|
|
|
retryCount = retryCount + 1; |
|
|
|
// retryCount = retryCount + 1; |
|
|
|
// recordLogService.recordLogininfor(username,user.getNickName(), Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount)); |
|
|
|
redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); |
|
|
|
// redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); |
|
|
|
throw new ServiceException("用户不存在/密码错误"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
clearLoginRecordCache(username); |
|
|
|
} |
|
|
|
// else |
|
|
|
// { |
|
|
|
// clearLoginRecordCache(username); |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
public boolean matches(SysUser user, String rawPassword) |
|
|
|
{ |
|
|
|
return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); |
|
|
|
if ("dev".equals(activeProfile)){ |
|
|
|
return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); |
|
|
|
} |
|
|
|
return tokenService.checkPassword(user.getUserName(),rawPassword); |
|
|
|
} |
|
|
|
|
|
|
|
public void clearLoginRecordCache(String loginName) |
|
|
|
|