KjbProperty 리팩토링
This commit is contained in:
@@ -4,10 +4,6 @@ import com.eactive.apim.portal.user.entity.UserInfo;
|
||||
import com.eactive.eai.rms.common.interceptor.InterceptorSkipController;
|
||||
import com.eactive.eai.rms.common.login.LoginVo;
|
||||
import com.eactive.eai.rms.common.login.MainController;
|
||||
import com.eactive.eai.rms.common.util.CommonConstants;
|
||||
import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService;
|
||||
import com.eactive.ext.kjb.common.KjbProperty;
|
||||
import com.eactive.ext.kjb.util.KjbPropertyInjector;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -23,27 +19,14 @@ import javax.servlet.http.HttpSession;
|
||||
@RequestMapping("/sms-auth")
|
||||
public class SmsAuthController implements InterceptorSkipController {
|
||||
|
||||
public static final String PROP_GROUP_ID = "Monitoring";
|
||||
|
||||
private final MainController mainController;
|
||||
private final KjbPropertyInjector kjbPropertyInjector;
|
||||
|
||||
private SmsAuthService smsAuthService;
|
||||
private KjbProperty kjbProperty;
|
||||
|
||||
public SmsAuthController(MonitoringPropertyService monitoringPropertyService,
|
||||
MainController mainController) {
|
||||
public SmsAuthController(MainController mainController) {
|
||||
this.mainController = mainController;
|
||||
this.kjbPropertyInjector = new KjbPropertyInjector(monitoringPropertyService, PROP_GROUP_ID);
|
||||
reloadProperty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 프로퍼티 리로드 (DB 변경 대응)
|
||||
*/
|
||||
private void reloadProperty() {
|
||||
this.kjbProperty = kjbPropertyInjector.inject(new KjbProperty());
|
||||
this.smsAuthService = new SmsAuthService(kjbProperty);
|
||||
private SmsAuthService getSmsAuthService() {
|
||||
return SmsAuthService.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,11 +35,8 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
@RequestMapping(value = "/send.json", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public SmsAuthDto sendAuthCode(HttpServletRequest request) {
|
||||
// 프로퍼티 리로드 (DB 변경 대응)
|
||||
reloadProperty();
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
UserInfo userInfo = smsAuthService.getUserInfoFromSession(session);
|
||||
UserInfo userInfo = getSmsAuthService().getUserInfoFromSession(session);
|
||||
|
||||
if (userInfo == null) {
|
||||
log.warn("SMS 인증 세션 정보 없음 - send 요청");
|
||||
@@ -66,7 +46,7 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
.build();
|
||||
}
|
||||
|
||||
if (!smsAuthService.hasValidPhoneNumber(userInfo)) {
|
||||
if (!getSmsAuthService().hasValidPhoneNumber(userInfo)) {
|
||||
log.warn("유효한 휴대폰번호 없음 - userId: {}", userInfo.getUserid());
|
||||
return SmsAuthDto.builder()
|
||||
.sent(false)
|
||||
@@ -75,19 +55,19 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
}
|
||||
|
||||
// 인증번호 생성 및 발송
|
||||
String authCode = smsAuthService.generateAuthCode();
|
||||
boolean sent = smsAuthService.sendAuthCode(userInfo.getCphnno(), authCode);
|
||||
String authCode = getSmsAuthService().generateAuthCode();
|
||||
boolean sent = getSmsAuthService().sendAuthCode(userInfo.getCphnno(), authCode);
|
||||
|
||||
if (sent) {
|
||||
// 세션에 인증번호 저장 (기존 UserInfo, LoginVo 유지)
|
||||
LoginVo loginVo = smsAuthService.getLoginVoFromSession(session);
|
||||
smsAuthService.setupAuthSession(session, userInfo, loginVo, authCode);
|
||||
LoginVo loginVo = getSmsAuthService().getLoginVoFromSession(session);
|
||||
getSmsAuthService().setupAuthSession(session, userInfo, loginVo, authCode);
|
||||
|
||||
return SmsAuthDto.builder()
|
||||
.sent(true)
|
||||
.maskedPhone(smsAuthService.maskPhoneNumber(userInfo.getCphnno()))
|
||||
.expiresAt(smsAuthService.getExpiresAt(session))
|
||||
.resendableAt(smsAuthService.getResendableAt(session))
|
||||
.maskedPhone(getSmsAuthService().maskPhoneNumber(userInfo.getCphnno()))
|
||||
.expiresAt(getSmsAuthService().getExpiresAt(session))
|
||||
.resendableAt(getSmsAuthService().getResendableAt(session))
|
||||
.build();
|
||||
} else {
|
||||
return SmsAuthDto.builder()
|
||||
@@ -103,11 +83,8 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
@RequestMapping(value = "/resend.json", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public SmsAuthDto resendAuthCode(HttpServletRequest request) {
|
||||
// 프로퍼티 리로드 (DB 변경 대응)
|
||||
reloadProperty();
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
UserInfo userInfo = smsAuthService.getUserInfoFromSession(session);
|
||||
UserInfo userInfo = getSmsAuthService().getUserInfoFromSession(session);
|
||||
|
||||
if (userInfo == null) {
|
||||
log.warn("SMS 인증 세션 정보 없음 - resend 요청");
|
||||
@@ -117,29 +94,29 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
.build();
|
||||
}
|
||||
|
||||
if (!smsAuthService.canResend(session)) {
|
||||
long waitTime = smsAuthService.getResendWaitTime(session);
|
||||
if (!getSmsAuthService().canResend(session)) {
|
||||
long waitTime = getSmsAuthService().getResendWaitTime(session);
|
||||
log.debug("재발송 대기 중 - 남은 시간: {}ms", waitTime);
|
||||
return SmsAuthDto.builder()
|
||||
.sent(false)
|
||||
.errorMessage(String.format("%.0f초 후에 재발송이 가능합니다.", Math.ceil(waitTime / 1000.0)))
|
||||
.resendableAt(smsAuthService.getResendableAt(session))
|
||||
.resendableAt(getSmsAuthService().getResendableAt(session))
|
||||
.build();
|
||||
}
|
||||
|
||||
// 새 인증번호 생성 및 발송
|
||||
String authCode = smsAuthService.generateAuthCode();
|
||||
boolean sent = smsAuthService.sendAuthCode(userInfo.getCphnno(), authCode);
|
||||
String authCode = getSmsAuthService().generateAuthCode();
|
||||
boolean sent = getSmsAuthService().sendAuthCode(userInfo.getCphnno(), authCode);
|
||||
|
||||
if (sent) {
|
||||
LoginVo loginVo = smsAuthService.getLoginVoFromSession(session);
|
||||
smsAuthService.setupAuthSession(session, userInfo, loginVo, authCode);
|
||||
LoginVo loginVo = getSmsAuthService().getLoginVoFromSession(session);
|
||||
getSmsAuthService().setupAuthSession(session, userInfo, loginVo, authCode);
|
||||
|
||||
return SmsAuthDto.builder()
|
||||
.sent(true)
|
||||
.maskedPhone(smsAuthService.maskPhoneNumber(userInfo.getCphnno()))
|
||||
.expiresAt(smsAuthService.getExpiresAt(session))
|
||||
.resendableAt(smsAuthService.getResendableAt(session))
|
||||
.maskedPhone(getSmsAuthService().maskPhoneNumber(userInfo.getCphnno()))
|
||||
.expiresAt(getSmsAuthService().getExpiresAt(session))
|
||||
.resendableAt(getSmsAuthService().getResendableAt(session))
|
||||
.build();
|
||||
} else {
|
||||
return SmsAuthDto.builder()
|
||||
@@ -157,8 +134,8 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
public SmsAuthDto verifyAuthCode(HttpServletRequest request,
|
||||
@RequestParam("authCode") String authCode) {
|
||||
HttpSession session = request.getSession();
|
||||
UserInfo userInfo = smsAuthService.getUserInfoFromSession(session);
|
||||
LoginVo loginVo = smsAuthService.getLoginVoFromSession(session);
|
||||
UserInfo userInfo = getSmsAuthService().getUserInfoFromSession(session);
|
||||
LoginVo loginVo = getSmsAuthService().getLoginVoFromSession(session);
|
||||
|
||||
if (userInfo == null || loginVo == null) {
|
||||
log.warn("SMS 인증 세션 정보 없음 - verify 요청");
|
||||
@@ -168,16 +145,16 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
.build();
|
||||
}
|
||||
|
||||
if (smsAuthService.isExpired(session)) {
|
||||
if (getSmsAuthService().isExpired(session)) {
|
||||
log.warn("SMS 인증번호 만료됨 - userId: {}", userInfo.getUserid());
|
||||
smsAuthService.clearAuthSession(session);
|
||||
getSmsAuthService().clearAuthSession(session);
|
||||
return SmsAuthDto.builder()
|
||||
.success(false)
|
||||
.errorMessage("인증번호가 만료되었습니다. 다시 시도해주세요.")
|
||||
.build();
|
||||
}
|
||||
|
||||
if (!smsAuthService.validateAuthCode(session, authCode)) {
|
||||
if (!getSmsAuthService().validateAuthCode(session, authCode)) {
|
||||
log.warn("SMS 인증번호 불일치 - userId: {}", userInfo.getUserid());
|
||||
return SmsAuthDto.builder()
|
||||
.success(false)
|
||||
@@ -187,7 +164,7 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
|
||||
// 인증 성공 - 로그인 완료 처리
|
||||
try {
|
||||
smsAuthService.clearAuthSession(session);
|
||||
getSmsAuthService().clearAuthSession(session);
|
||||
|
||||
// MainController의 loadUserInfoAndSetupSession 호출
|
||||
String result = mainController.loadUserInfoAndSetupSession(request, session, loginVo, userInfo);
|
||||
@@ -236,7 +213,7 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
@ResponseBody
|
||||
public SmsAuthDto getStatus(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
UserInfo userInfo = smsAuthService.getUserInfoFromSession(session);
|
||||
UserInfo userInfo = getSmsAuthService().getUserInfoFromSession(session);
|
||||
|
||||
if (userInfo == null) {
|
||||
return SmsAuthDto.builder()
|
||||
@@ -246,10 +223,10 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
}
|
||||
|
||||
return SmsAuthDto.builder()
|
||||
.enabled(smsAuthService.isEnabled())
|
||||
.maskedPhone(smsAuthService.maskPhoneNumber(userInfo.getCphnno()))
|
||||
.expiresAt(smsAuthService.getExpiresAt(session))
|
||||
.resendableAt(smsAuthService.getResendableAt(session))
|
||||
.enabled(getSmsAuthService().isEnabled())
|
||||
.maskedPhone(getSmsAuthService().maskPhoneNumber(userInfo.getCphnno()))
|
||||
.expiresAt(getSmsAuthService().getExpiresAt(session))
|
||||
.resendableAt(getSmsAuthService().getResendableAt(session))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.eactive.eai.rms.ext.kjb.smsauth;
|
||||
import com.eactive.apim.portal.user.entity.UserInfo;
|
||||
import com.eactive.eai.rms.common.login.LoginVo;
|
||||
import com.eactive.ext.kjb.common.KjbProperty;
|
||||
import com.eactive.ext.kjb.common.KjbPropertyHolder;
|
||||
import com.eactive.ext.kjb.common.KjbUmsException;
|
||||
import com.eactive.ext.kjb.ums.KjbUmsService;
|
||||
import com.eactive.ext.kjb.ums.UmsBizWorkCode;
|
||||
@@ -17,6 +18,7 @@ import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Slf4j
|
||||
public class SmsAuthService {
|
||||
private static volatile SmsAuthService instance;
|
||||
|
||||
// 세션 키
|
||||
public static final String SESSION_KEY_AUTH_CODE = "SMS_AUTH_CODE";
|
||||
@@ -33,20 +35,36 @@ public class SmsAuthService {
|
||||
public static final String MODE_HHMM00 = "hhmm00";
|
||||
public static final String MODE_FIXED = "fixed";
|
||||
|
||||
private final KjbProperty kjbProperty;
|
||||
private final KjbUmsService kjbUmsService;
|
||||
private final SecureRandom random = new SecureRandom();
|
||||
|
||||
public SmsAuthService(KjbProperty kjbProperty) {
|
||||
this.kjbProperty = kjbProperty;
|
||||
this.kjbUmsService = new KjbUmsService(kjbProperty);
|
||||
private SmsAuthService() {
|
||||
// 싱글톤
|
||||
}
|
||||
|
||||
public static SmsAuthService getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (SmsAuthService.class) {
|
||||
if (instance == null) {
|
||||
instance = new SmsAuthService();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static KjbProperty getProperty() {
|
||||
return KjbPropertyHolder.get();
|
||||
}
|
||||
|
||||
private KjbUmsService getUmsService() {
|
||||
return KjbUmsService.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* SMS 인증이 필요한지 확인
|
||||
*/
|
||||
public boolean isRequired(UserInfo userInfo) {
|
||||
if (!kjbProperty.isSmsAuthEnabled()) {
|
||||
if (!getProperty().isSmsAuthEnabled()) {
|
||||
log.debug("SMS 인증 비활성화 상태");
|
||||
return false;
|
||||
}
|
||||
@@ -74,10 +92,11 @@ public class SmsAuthService {
|
||||
* 인증번호 생성
|
||||
*/
|
||||
public String generateAuthCode() {
|
||||
String mode = kjbProperty.getSmsAuthMode();
|
||||
KjbProperty prop = getProperty();
|
||||
String mode = prop.getSmsAuthMode();
|
||||
|
||||
if (MODE_FIXED.equalsIgnoreCase(mode)) {
|
||||
String fixedValue = kjbProperty.getSmsAuthFixedValue();
|
||||
String fixedValue = prop.getSmsAuthFixedValue();
|
||||
log.debug("SMS 인증번호 생성 (fixed 모드): {}", fixedValue);
|
||||
return fixedValue;
|
||||
} else if (MODE_HHMM00.equalsIgnoreCase(mode)) {
|
||||
@@ -105,7 +124,7 @@ public class SmsAuthService {
|
||||
.authNumber(authCode)
|
||||
.build();
|
||||
|
||||
kjbUmsService.sendKakaoAlimTalk(guid, UmsBizWorkCode.VERIFY_PHONE, cleanedPhone, content);
|
||||
getUmsService().sendKakaoAlimTalk(guid, UmsBizWorkCode.VERIFY_PHONE, cleanedPhone, content);
|
||||
log.info("SMS 인증번호 발송 완료 - guid: {}, phone: {}****{}",
|
||||
guid, cleanedPhone.substring(0, 3), cleanedPhone.substring(cleanedPhone.length() - 4));
|
||||
log.debug("SMS 인증번호 발송 - authCode: {}", authCode);
|
||||
@@ -265,6 +284,13 @@ public class SmsAuthService {
|
||||
* SMS 인증 활성화 여부
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return kjbProperty.isSmsAuthEnabled();
|
||||
return getProperty().isSmsAuthEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 테스트용 인스턴스 리셋
|
||||
*/
|
||||
public static void resetForTest() {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
|
||||
import com.eactive.eai.rms.common.interceptor.InterceptorSkipController;
|
||||
import com.eactive.eai.rms.common.login.MainController;
|
||||
import com.eactive.eai.rms.common.util.CommonConstants;
|
||||
import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService;
|
||||
import com.eactive.eai.rms.data.entity.man.user.UserInfoService;
|
||||
import com.eactive.eai.rms.data.entity.man.user.UserRole;
|
||||
import com.eactive.eai.rms.data.entity.man.user.UserRoleId;
|
||||
@@ -16,8 +15,8 @@ import com.eactive.eai.rms.data.entity.man.user.UserRoleService;
|
||||
import com.eactive.eai.rms.data.entity.man.user.UserServiceTypeService;
|
||||
import com.eactive.eai.rms.onl.apim.masking.MaskingUtils;
|
||||
import com.eactive.ext.kjb.common.KjbProperty;
|
||||
import com.eactive.ext.kjb.common.KjbPropertyHolder;
|
||||
import com.eactive.ext.kjb.sso.KjbSsoModule;
|
||||
import com.eactive.ext.kjb.util.KjbPropertyInjector;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -34,25 +33,18 @@ import java.util.Properties;
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class SsoController implements InterceptorSkipController {
|
||||
public static final String PROP_GORUP_ID = "Monitoring";
|
||||
|
||||
private final KjbSsoModule ssoModule;
|
||||
private final KjbProperty prop;
|
||||
private final UserInfoService userInfoService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final UserServiceTypeService userServiceTypeService;
|
||||
private final MonitoringContext monitoringContext;
|
||||
private final MainController mainController;
|
||||
|
||||
public SsoController(MonitoringPropertyService monitoringPropertyService,
|
||||
UserInfoService userInfoService,
|
||||
public SsoController(UserInfoService userInfoService,
|
||||
UserRoleService userRoleService,
|
||||
UserServiceTypeService userServiceTypeService,
|
||||
MonitoringContext monitoringContext,
|
||||
MainController mainController) {
|
||||
KjbPropertyInjector kjbPropertyInjector = new KjbPropertyInjector(monitoringPropertyService, PROP_GORUP_ID);
|
||||
prop = kjbPropertyInjector.inject(new KjbProperty());
|
||||
this.ssoModule = KjbSsoModule.getInstance(prop);
|
||||
this.userInfoService = userInfoService;
|
||||
this.userRoleService = userRoleService;
|
||||
this.userServiceTypeService = userServiceTypeService;
|
||||
@@ -60,11 +52,19 @@ public class SsoController implements InterceptorSkipController {
|
||||
this.mainController = mainController;
|
||||
}
|
||||
|
||||
private KjbSsoModule getSsoModule() {
|
||||
return KjbSsoModule.getInstance();
|
||||
}
|
||||
|
||||
private KjbProperty getProperty() {
|
||||
return KjbPropertyHolder.get();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sso/login.do")
|
||||
public String login(HttpServletRequest req, HttpServletResponse res,
|
||||
@RequestParam(name = "UURL", required = false) String uurl) throws Exception {
|
||||
HttpSession session = req.getSession();
|
||||
String ssoId = ssoModule.getSsoId(req);
|
||||
String ssoId = getSsoModule().getSsoId(req);
|
||||
|
||||
log.debug("ssoId : {}", ssoId);
|
||||
log.debug("uurl : {}", uurl);
|
||||
@@ -83,19 +83,19 @@ public class SsoController implements InterceptorSkipController {
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(uurl)) {
|
||||
uurl = ssoModule.getAscpUrl();
|
||||
uurl = getSsoModule().getAscpUrl();
|
||||
}
|
||||
|
||||
if (ssoId == null) {
|
||||
ssoModule.goLoginPage(res, uurl);
|
||||
getSsoModule().goLoginPage(res, uurl);
|
||||
return null;
|
||||
} else {
|
||||
// EAM 세션 검증
|
||||
String retCode = ssoModule.getEamSessionCheck(req, res);
|
||||
String retCode = getSsoModule().getEamSessionCheck(req, res);
|
||||
log.debug("retCode : {}", retCode);
|
||||
|
||||
log.debug("Property - sso.ignore_validation = {}", prop.isSsoIgnoreValidation());
|
||||
if (!prop.isSsoIgnoreValidation() && !"0".equalsIgnoreCase(retCode)) {
|
||||
log.debug("Property - sso.ignore_validation = {}", getProperty().isSsoIgnoreValidation());
|
||||
if (!getProperty().isSsoIgnoreValidation() && !"0".equalsIgnoreCase(retCode)) {
|
||||
// SSO 검증 실패 시 에러 메시지 설정 및 로그인 페이지로 이동
|
||||
session.setAttribute("resultMsg", "SSO 로그인을 실패 하였습니다. 다른 로그인 방식을 시도 하세요");
|
||||
return "redirect:/loginForm.do";
|
||||
@@ -106,11 +106,11 @@ public class SsoController implements InterceptorSkipController {
|
||||
return "redirect:/loginForm.do";
|
||||
}
|
||||
|
||||
if (prop.isSsoSyncInfo()) {
|
||||
if (getProperty().isSsoSyncInfo()) {
|
||||
// 기본 정보
|
||||
Properties info = ssoModule.getUserInfos(ssoId);
|
||||
Properties info = getSsoModule().getUserInfos(ssoId);
|
||||
// 확장 정보
|
||||
Properties extendedInfo = ssoModule.getUserExFields(ssoId);
|
||||
Properties extendedInfo = getSsoModule().getUserExFields(ssoId);
|
||||
|
||||
// 필수 필드 검증
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user