|
@@ -92,11 +92,11 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
|
|
|
|
private Logger LOG = LoggerFactory.getLogger(getClass());
|
|
private Logger LOG = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
- private void createLog(DefaultUsernamepasswordToken uptoken) {
|
|
|
|
|
|
+ private void createLog(DefaultUsernamepasswordToken uptoken, String reason) {
|
|
Object username = uptoken.getUsername();
|
|
Object username = uptoken.getUsername();
|
|
Date date = new Date();
|
|
Date date = new Date();
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
- LOG.error("用户{}登录失败,失败时间:{}",username,df.format(date));
|
|
|
|
|
|
+ LOG.error("用户{}登录失败,失败时间:{},失败原因:{}",new Object[]{username,df.format(date), reason});
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -106,18 +106,21 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
String loginType = upToken.getLoginType();
|
|
String loginType = upToken.getLoginType();
|
|
if (loginType.equals("mobile")) {
|
|
if (loginType.equals("mobile")) {
|
|
if (userService.findByMobile(username) == null) {
|
|
if (userService.findByMobile(username) == null) {
|
|
- createLog(upToken);
|
|
|
|
|
|
+ String reason = "手机登录用户不存在";
|
|
|
|
+ createLog(upToken, reason);
|
|
throw new AccountException("user not exist");
|
|
throw new AccountException("user not exist");
|
|
}
|
|
}
|
|
|
|
|
|
if (!mobileVerificationService.validateMobileVerification(username, new String(upToken.getPassword()))) {
|
|
if (!mobileVerificationService.validateMobileVerification(username, new String(upToken.getPassword()))) {
|
|
- createLog(upToken);
|
|
|
|
|
|
+ String reason = "手机登录验证错误";
|
|
|
|
+ createLog(upToken, reason);
|
|
throw new IncorrectCredentialsException("wrong verification");
|
|
throw new IncorrectCredentialsException("wrong verification");
|
|
}
|
|
}
|
|
return new SimpleAuthenticationInfo(username, upToken.getPassword(), getName());
|
|
return new SimpleAuthenticationInfo(username, upToken.getPassword(), getName());
|
|
} else if (loginType.equals("email&mobile")) {
|
|
} else if (loginType.equals("email&mobile")) {
|
|
if (username.isEmpty()) {
|
|
if (username.isEmpty()) {
|
|
- createLog(upToken);
|
|
|
|
|
|
+ String reason = "邮箱登录用户名为空";
|
|
|
|
+ createLog(upToken, reason);
|
|
throw new AccountException("empty username");
|
|
throw new AccountException("empty username");
|
|
}
|
|
}
|
|
UserDTOForMT userDTOForMT = userService.getUserByEmail(username);
|
|
UserDTOForMT userDTOForMT = userService.getUserByEmail(username);
|
|
@@ -125,11 +128,13 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
userDTOForMT = userService.findByMobile(username);
|
|
userDTOForMT = userService.findByMobile(username);
|
|
}
|
|
}
|
|
if (userDTOForMT == null) {
|
|
if (userDTOForMT == null) {
|
|
- createLog(upToken);
|
|
|
|
|
|
+ String reason = "邮箱登录用户不存在";
|
|
|
|
+ createLog(upToken, reason);
|
|
throw new HttpBadRequestException("user not exist");
|
|
throw new HttpBadRequestException("user not exist");
|
|
}
|
|
}
|
|
if (!userDTOForMT.getPassword().equals(new String(upToken.getPassword()))) {
|
|
if (!userDTOForMT.getPassword().equals(new String(upToken.getPassword()))) {
|
|
- createLog(upToken);
|
|
|
|
|
|
+ String reason = "邮箱登录密码错误";
|
|
|
|
+ createLog(upToken, reason);
|
|
throw new IncorrectCredentialsException("wrong password");
|
|
throw new IncorrectCredentialsException("wrong password");
|
|
}
|
|
}
|
|
return new SimpleAuthenticationInfo(username, userDTOForMT.getPassword(), getName());
|
|
return new SimpleAuthenticationInfo(username, userDTOForMT.getPassword(), getName());
|