|
@@ -4,7 +4,6 @@ import jakarta.annotation.Resource;
|
|
|
import jp.yamoto.farm.common.config.AppConfig;
|
|
import jp.yamoto.farm.common.config.AppConfig;
|
|
|
import jp.yamoto.farm.crm.biz.user.service.ISysConfigService;
|
|
import jp.yamoto.farm.crm.biz.user.service.ISysConfigService;
|
|
|
import jp.yamoto.farm.crm.biz.user.service.ISysUserService;
|
|
import jp.yamoto.farm.crm.biz.user.service.ISysUserService;
|
|
|
-import jp.yamoto.farm.common.constant.CacheConstants;
|
|
|
|
|
import jp.yamoto.farm.common.constant.Constants;
|
|
import jp.yamoto.farm.common.constant.Constants;
|
|
|
import jp.yamoto.farm.common.constant.UserConstants;
|
|
import jp.yamoto.farm.common.constant.UserConstants;
|
|
|
import jp.yamoto.farm.common.core.domain.entity.SysUser;
|
|
import jp.yamoto.farm.common.core.domain.entity.SysUser;
|
|
@@ -58,14 +57,10 @@ public class SysLoginService
|
|
|
*
|
|
*
|
|
|
* @param username ユーザー名
|
|
* @param username ユーザー名
|
|
|
* @param password パスワード
|
|
* @param password パスワード
|
|
|
- * @param code 認証コード
|
|
|
|
|
- * @param uuid UUID
|
|
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String login(String username, String password, String code, String uuid)
|
|
|
|
|
|
|
+ public String login(String username, String password)
|
|
|
{
|
|
{
|
|
|
- // 検証コード検証
|
|
|
|
|
- validateCaptcha(username, code, uuid);
|
|
|
|
|
// ログイン前チェック
|
|
// ログイン前チェック
|
|
|
loginPreCheck(username, password);
|
|
loginPreCheck(username, password);
|
|
|
// ユーザー認証
|
|
// ユーザー認証
|
|
@@ -80,7 +75,7 @@ public class SysLoginService
|
|
|
{
|
|
{
|
|
|
if (e instanceof BadCredentialsException)
|
|
if (e instanceof BadCredentialsException)
|
|
|
{
|
|
{
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
|
|
|
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("E0004")));
|
|
|
throw new UserPasswordNotMatchException();
|
|
throw new UserPasswordNotMatchException();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -93,7 +88,7 @@ public class SysLoginService
|
|
|
{
|
|
{
|
|
|
AuthenticationContextHolder.clearContext();
|
|
AuthenticationContextHolder.clearContext();
|
|
|
}
|
|
}
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
|
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("I0008")));
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
recordLoginInfo(loginUser.getUserId());
|
|
recordLoginInfo(loginUser.getUserId());
|
|
|
// token
|
|
// token
|
|
@@ -101,35 +96,6 @@ public class SysLoginService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 検証コード
|
|
|
|
|
- *
|
|
|
|
|
- * @param username ユーザー名
|
|
|
|
|
- * @param code コード
|
|
|
|
|
- * @param uuid UUID
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
- public void validateCaptcha(String username, String code, String uuid)
|
|
|
|
|
- {
|
|
|
|
|
- boolean captchaEnabled = configService.selectCaptchaEnabled();
|
|
|
|
|
- if (captchaEnabled)
|
|
|
|
|
- {
|
|
|
|
|
- String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
|
|
|
|
|
- String captcha = appCache.getCacheObject(verifyKey, String.class);
|
|
|
|
|
- if (captcha == null)
|
|
|
|
|
- {
|
|
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
|
|
|
|
|
- throw new CaptchaExpireException();
|
|
|
|
|
- }
|
|
|
|
|
- appCache.deleteObject(verifyKey);
|
|
|
|
|
- if (!code.equalsIgnoreCase(captcha))
|
|
|
|
|
- {
|
|
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
|
|
|
|
- throw new CaptchaException();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
* ログイン前チェック
|
|
* ログイン前チェック
|
|
|
* @param username ユーザー名
|
|
* @param username ユーザー名
|
|
|
* @param password ユーザーパスワード
|
|
* @param password ユーザーパスワード
|
|
@@ -139,28 +105,28 @@ public class SysLoginService
|
|
|
// ユーザー名またはパスワードがNULLのエラー
|
|
// ユーザー名またはパスワードがNULLのエラー
|
|
|
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password))
|
|
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password))
|
|
|
{
|
|
{
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("not.null")));
|
|
|
|
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("E0052")));
|
|
|
throw new UserNotExistsException();
|
|
throw new UserNotExistsException();
|
|
|
}
|
|
}
|
|
|
// パスワードが指定された範囲内でなければエラー
|
|
// パスワードが指定された範囲内でなければエラー
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
|
|
{
|
|
{
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
|
|
|
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("E0004")));
|
|
|
throw new UserPasswordNotMatchException();
|
|
throw new UserPasswordNotMatchException();
|
|
|
}
|
|
}
|
|
|
// ユーザー名が指定された範囲外のエラー
|
|
// ユーザー名が指定された範囲外のエラー
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
|
|
{
|
|
{
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
|
|
|
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("E0004")));
|
|
|
throw new UserPasswordNotMatchException();
|
|
throw new UserPasswordNotMatchException();
|
|
|
}
|
|
}
|
|
|
// IPブラックリスト検証
|
|
// IPブラックリスト検証
|
|
|
String blackStr = configService.selectConfigByKey("sys.login.blackIPList");
|
|
String blackStr = configService.selectConfigByKey("sys.login.blackIPList");
|
|
|
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
|
|
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
|
|
|
{
|
|
{
|
|
|
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("login.blocked")));
|
|
|
|
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(appConfig.getName(), username, Constants.LOGIN_FAIL, MessageUtils.message("E0061")));
|
|
|
throw new BlackListException();
|
|
throw new BlackListException();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|