이메일 소문자 처리

This commit is contained in:
현성필
2025-12-04 16:34:18 +09:00
parent 5965404e4f
commit 1d2eaba24e
7 changed files with 36 additions and 16 deletions
@@ -262,9 +262,10 @@ public class OrgRegisterFacadeImpl implements OrgRegisterFacade {
// PortalOrgService를 통한 기관 등록
PortalOrg newOrg = portalOrgService.registerOrgFromDTOWithFile(orgDTO, uploadedFile);
// 새 사용자 생성
existingUser.setLoginId(newEmail);
existingUser.setEmailAddr(newEmail);
// 새 사용자 생성 (이메일 소문자 변환 적용)
String normalizedNewEmail = newEmail != null ? newEmail.toLowerCase() : null;
existingUser.setLoginId(normalizedNewEmail);
existingUser.setEmailAddr(normalizedNewEmail);
existingUser.setPortalOrg(newOrg);
existingUser.setRoleCode(PortalUserEnums.RoleCode.ROLE_CORP_MANAGER);
existingUser.setUserStatus(PortalUserEnums.UserStatus.READY);
@@ -55,7 +55,9 @@ public class PortalUserAuthService implements UserDetailsService {
@Transactional(noRollbackFor = UsernameNotFoundException.class)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
try {
PortalUser portalUser = findByEmailAddr(username);
// 이메일 소문자 변환 적용 (대소문자 구분 없이 로그인 가능하도록)
String normalizedUsername = username != null ? username.toLowerCase() : null;
PortalUser portalUser = findByEmailAddr(normalizedUsername);
RoleCode userRole = portalUser.getRoleCode() == null ? RoleCode.ROLE_USER : portalUser.getRoleCode();
List<String> roles = portalProperties.getPortalSecurity().get(userRole);
PortalAuthenticatedUser authenticatedUser = portalUserMapper.portalUserToAuthenticatedUser(portalUser);
@@ -46,11 +46,15 @@ public class PortalUserService {
}
public Optional<PortalUser> findByLoginId(String loginId) {
return portalUserRepository.findByLoginId(loginId);
// 이메일 소문자 변환 적용
String normalizedLoginId = loginId != null ? loginId.toLowerCase() : null;
return portalUserRepository.findByLoginId(normalizedLoginId);
}
public PortalUser findByEmailAddr(String emailAddr) {
return portalUserRepository.findPortalUserByEmailAddr(emailAddr)
// 이메일 소문자 변환 적용
String normalizedEmail = emailAddr != null ? emailAddr.toLowerCase() : null;
return portalUserRepository.findPortalUserByEmailAddr(normalizedEmail)
.orElseThrow(() -> new IllegalArgumentException("해당 이메일 주소의 사용자를 찾을 수 없습니다."));
}
@@ -59,7 +63,9 @@ public class PortalUserService {
}
public boolean existsByLoginId(String loginId) {
return portalUserRepository.existsByLoginId(loginId);
// 이메일 소문자 변환 적용
String normalizedLoginId = loginId != null ? loginId.toLowerCase() : null;
return portalUserRepository.existsByLoginId(normalizedLoginId);
}
public boolean checkOrgHasOtherUsers(PortalOrg portalOrg) {
@@ -137,11 +143,13 @@ public class PortalUserService {
}
private void mapDtoToEntity(PortalUser user, PortalUserRegistrationDTO dto) {
user.setLoginId(dto.getLoginId());
// 이메일 소문자 변환 적용 (대소문자 구분 없이 로그인 가능하도록)
String normalizedEmail = dto.getLoginId() != null ? dto.getLoginId().toLowerCase() : null;
user.setLoginId(normalizedEmail);
user.setUserName(dto.getUserName());
user.setPasswordHash(passwordEncoder.encode(dto.getPassword()));
user.setMobileNumber(dto.getMobileNumber());
user.setEmailAddr(dto.getLoginId());
user.setEmailAddr(normalizedEmail);
}
/**
@@ -176,7 +184,9 @@ public class PortalUserService {
}
public boolean checkPassword(String loginId, String inputPassword) {
PortalUser user = portalUserRepository.findByLoginId(loginId)
// 이메일 소문자 변환 적용
String normalizedLoginId = loginId != null ? loginId.toLowerCase() : null;
PortalUser user = portalUserRepository.findByLoginId(normalizedLoginId)
.orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다."));
return passwordEncoder.matches(inputPassword, user.getPasswordHash());
}
@@ -49,6 +49,8 @@ public class PortalAuthenticationFailureHandler implements AuthenticationFailure
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {AuthenticationException.class, UserNotFoundException.class})
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
String username = request.getParameter("id");
// 이메일 소문자 변환 적용
String normalizedUsername = username != null ? username.toLowerCase() : null;
String ip = request.getRemoteAddr();
String sessionId = request.getSession().getId();
@@ -56,8 +58,8 @@ public class PortalAuthenticationFailureHandler implements AuthenticationFailure
logger.error(exception.getLocalizedMessage());
} else if (!(exception instanceof UsernameNotFoundException)) {
try {
PortalUser user = portalUserRepository.findPortalUserByEmailAddr(username)
.orElseThrow(() -> new UserNotFoundException(username));
PortalUser user = portalUserRepository.findPortalUserByEmailAddr(normalizedUsername)
.orElseThrow(() -> new UserNotFoundException(normalizedUsername));
user.setLoginFailureCount(user.getLoginFailureCount() + 1);
if (user.getLoginFailureCount() >= 5) {
@@ -46,7 +46,9 @@ public class PortalAuthenticationSuccessHandler implements AuthenticationSuccess
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
String username = request.getParameter("id");
PortalUser user = portalUserRepository.findPortalUserByEmailAddr(username).orElse(null);
// 이메일 소문자 변환 적용
String normalizedUsername = username != null ? username.toLowerCase() : null;
PortalUser user = portalUserRepository.findPortalUserByEmailAddr(normalizedUsername).orElse(null);
if (user == null) {
response.sendRedirect(request.getContextPath() + "/login?error=true");
return;
@@ -160,6 +160,9 @@
// Show loading state
$('#loginLoading').addClass('active');
// 이메일(아이디) 소문자 변환 적용
form.id.value = form.id.value.toLowerCase();
if ($('#checkId').is(':checked')) {
setCookie('saveid', $('#id').val(), new Date(new Date().getTime() + 1000 * 3600 * 24 * 30));
} else {
@@ -39,10 +39,10 @@
</body>
<th:block>
<script th:fragment="commonUserInfoScript" th:inline="javascript">
// 이메일 조합 함수
// 이메일 조합 함수 (소문자 변환 적용)
function combineEmail() {
let emailId = $('#userId').val();
let domain = $('#domain').val();
let emailId = $('#userId').val().toLowerCase();
let domain = $('#domain').val().toLowerCase();
let combined = emailId + '@' + domain;
$('#loginId').val(combined);
}