|
|
@@ -1,26 +1,25 @@
|
|
|
package jp.yamoto.farm.sankin.biz.auth.service;
|
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import jp.yamoto.farm.common.biz.enums.BssUserCertificationType;
|
|
|
+import jp.yamoto.farm.common.biz.enums.SankinPgIdEnum;
|
|
|
import jp.yamoto.farm.common.config.AppConfig;
|
|
|
import jp.yamoto.farm.common.constant.Constants;
|
|
|
-import jp.yamoto.farm.common.constant.UserConstants;
|
|
|
import jp.yamoto.farm.common.core.domain.entity.FarmerUserInfo;
|
|
|
-import jp.yamoto.farm.common.core.domain.entity.SysUser;
|
|
|
import jp.yamoto.farm.common.core.domain.model.LoginUser;
|
|
|
import jp.yamoto.farm.common.core.service.TokenService;
|
|
|
-import jp.yamoto.farm.common.enums.AuthStatusEnum;
|
|
|
import jp.yamoto.farm.common.enums.UserStatus;
|
|
|
import jp.yamoto.farm.common.exception.ServiceException;
|
|
|
import jp.yamoto.farm.common.exception.user.AuthVerifyCodeNotMatchException;
|
|
|
-import jp.yamoto.farm.common.exception.user.UserNotExistsException;
|
|
|
import jp.yamoto.farm.common.exception.user.UserPasswordNotMatchException;
|
|
|
import jp.yamoto.farm.common.manager.AsyncManager;
|
|
|
import jp.yamoto.farm.common.manager.factory.AsyncFactory;
|
|
|
import jp.yamoto.farm.common.security.context.AuthenticationContextHolder;
|
|
|
import jp.yamoto.farm.common.utils.*;
|
|
|
-import jp.yamoto.farm.common.utils.ip.IpUtils;
|
|
|
import jp.yamoto.farm.sankin.biz.auth.domain.*;
|
|
|
+import jp.yamoto.farm.sankin.biz.domain.bo.BssUserAuthCodeMailBo;
|
|
|
import jp.yamoto.farm.sankin.biz.mapper.FarmerUserMapper;
|
|
|
+import jp.yamoto.farm.sankin.biz.service.IBssUserCertificationService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -28,13 +27,9 @@ import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
-import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
-import org.springframework.security.core.userdetails.UserDetails;
|
|
|
-import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
-import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
@@ -58,6 +53,9 @@ public class AuthService {
|
|
|
@Autowired
|
|
|
private FarmerUserMapper farmerMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IBssUserCertificationService bssUserCertificationService;
|
|
|
+
|
|
|
/**
|
|
|
* ログイン検証
|
|
|
*
|
|
|
@@ -76,7 +74,13 @@ public class AuthService {
|
|
|
}
|
|
|
|
|
|
// 認証コードを送信する
|
|
|
- String sendId = "123";
|
|
|
+ BssUserAuthCodeMailBo bssUserAuthCodeMailBo = new BssUserAuthCodeMailBo();
|
|
|
+ bssUserAuthCodeMailBo.setUserId(userDetails.getFarmerId());
|
|
|
+ bssUserAuthCodeMailBo.setMailAddress(userDetails.getMailAddress());
|
|
|
+ bssUserAuthCodeMailBo.setType(BssUserCertificationType.FRAMER);
|
|
|
+ bssUserAuthCodeMailBo.setPgId(SankinPgIdEnum.N001.getCode());
|
|
|
+
|
|
|
+ String sendId = bssUserCertificationService.sendAuthCodeByEmail(bssUserAuthCodeMailBo);
|
|
|
|
|
|
return this.createTempToken(sendId, userDetails.getMailAddress());
|
|
|
}
|
|
|
@@ -86,6 +90,7 @@ public class AuthService {
|
|
|
* @param authSecondBo
|
|
|
* @return
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
public String authenticateSecond(AuthSecondVerifyBo authSecondBo){
|
|
|
|
|
|
// ユーザー認証
|
|
|
@@ -132,6 +137,7 @@ public class AuthService {
|
|
|
/**
|
|
|
* 認証コードを再送信する
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
public String resendAuthCode(AuthReSendVerifyCodeBo authReSendVerifyCodeBo) throws Exception {
|
|
|
|
|
|
AuthTempTokenBo authTempTokenBo = getTempToken(authReSendVerifyCodeBo.getTempToken());
|
|
|
@@ -139,9 +145,15 @@ public class AuthService {
|
|
|
// ユーザー
|
|
|
FarmerUserInfo userDetails = this.selectUserByMailAddress(authTempTokenBo.getMailAddess());
|
|
|
|
|
|
- // TODO 認証コードを再送信する
|
|
|
- // emailService.generateAndSendVerificationCode(user.getEmail());
|
|
|
- String sendId = "5698";
|
|
|
+ // 認証コードを再送信する
|
|
|
+ BssUserAuthCodeMailBo bssUserAuthCodeMailBo = new BssUserAuthCodeMailBo();
|
|
|
+ bssUserAuthCodeMailBo.setUserId(userDetails.getFarmerId());
|
|
|
+ bssUserAuthCodeMailBo.setMailAddress(userDetails.getMailAddress());
|
|
|
+ bssUserAuthCodeMailBo.setType(BssUserCertificationType.FRAMER);
|
|
|
+ bssUserAuthCodeMailBo.setPgId(SankinPgIdEnum.N003.getCode());
|
|
|
+ bssUserAuthCodeMailBo.setPreSendId(authTempTokenBo.getSendVerifyCodeId());
|
|
|
+
|
|
|
+ String sendId = bssUserCertificationService.sendAuthCodeByEmail(bssUserAuthCodeMailBo);
|
|
|
|
|
|
return this.createTempToken(sendId, userDetails.getMailAddress());
|
|
|
}
|
|
|
@@ -150,6 +162,7 @@ public class AuthService {
|
|
|
* パスワード再設定
|
|
|
* @param authResetPwdBo
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
public void resetPwd(AuthResetPwdBo authResetPwdBo){
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
|
|
|
@@ -168,10 +181,13 @@ public class AuthService {
|
|
|
|
|
|
/**
|
|
|
* 認証コードを送信します。
|
|
|
+ * パスワードを忘れた方
|
|
|
+ *
|
|
|
* @param authSendVerifyCodeBo
|
|
|
*
|
|
|
* @return 一時token
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
public String sendAuthCode(AuthSendVerifyCodeBo authSendVerifyCodeBo){
|
|
|
// メールアドレス 必須入力
|
|
|
if(ValueUtils.isEmpty(authSendVerifyCodeBo.getMailAddress())){
|
|
|
@@ -187,9 +203,16 @@ public class AuthService {
|
|
|
throw new ServiceException(MessageUtils.message("E0062", authSendVerifyCodeBo.getMailAddress()));
|
|
|
}
|
|
|
|
|
|
- // TODO 認証コードを送信
|
|
|
+ // 認証コードを送信する
|
|
|
+ BssUserAuthCodeMailBo bssUserAuthCodeMailBo = new BssUserAuthCodeMailBo();
|
|
|
+ bssUserAuthCodeMailBo.setUserId(user.getFarmerId());
|
|
|
+ bssUserAuthCodeMailBo.setMailAddress(user.getMailAddress());
|
|
|
+ bssUserAuthCodeMailBo.setType(BssUserCertificationType.FRAMER);
|
|
|
+ bssUserAuthCodeMailBo.setPgId(SankinPgIdEnum.N002.getCode());
|
|
|
+
|
|
|
+ String sendId = bssUserCertificationService.sendAuthCodeByEmail(bssUserAuthCodeMailBo);
|
|
|
|
|
|
- return null;
|
|
|
+ return this.createTempToken(sendId, user.getMailAddress());
|
|
|
}
|
|
|
|
|
|
public FarmerUserInfo selectUserByUserName(String username){
|
|
|
@@ -241,7 +264,7 @@ public class AuthService {
|
|
|
/**
|
|
|
* 認証トークンの生成
|
|
|
*
|
|
|
- * @param sendAuthVerifyCodeId セッション管理ID
|
|
|
+ * @param sendAuthVerifyCodeId ユーザー認証情報ID
|
|
|
* @param email メールアドレス
|
|
|
* @return 認証トークン
|
|
|
*/
|
|
|
@@ -250,7 +273,7 @@ public class AuthService {
|
|
|
try {
|
|
|
Map<String, Object> encryptMap = Map.of(
|
|
|
"sendId", sendAuthVerifyCodeId,
|
|
|
- "email", email);
|
|
|
+ "sendAddress", email);
|
|
|
String tokenFormat = JsonUtil.toJsonStr(encryptMap);
|
|
|
resultToken = DecryptUtils.decryptAES(tokenFormat);
|
|
|
} catch (Exception ex) {
|
|
|
@@ -284,7 +307,7 @@ public class AuthService {
|
|
|
|
|
|
if (null != tokenMap && tokenMap.containsKey("sendId") && StringUtils.isNotNull(tokenMap.get("sendId"))) {
|
|
|
result.setSendVerifyCodeId(String.valueOf(tokenMap.get("sendId")));
|
|
|
- result.setMailAddess(String.valueOf(tokenMap.get("email")));
|
|
|
+ result.setMailAddess(String.valueOf(tokenMap.get("sendAddress")));
|
|
|
}
|
|
|
|
|
|
return result;
|