로그 저장 수정
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.kamco.cd.kamcoback.auth;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.enums.StatusType;
|
||||
import com.kamco.cd.kamcoback.common.enums.error.AuthErrorCode;
|
||||
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MemberEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.members.MembersRepository;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
@@ -26,38 +26,35 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
|
||||
String username = authentication.getName();
|
||||
String rawPassword = authentication.getCredentials().toString();
|
||||
|
||||
// 1. 유저 조회
|
||||
// 유저 조회
|
||||
MemberEntity member =
|
||||
membersRepository
|
||||
.findByUserId(username)
|
||||
.orElseThrow(() -> new CustomApiException(AuthErrorCode.LOGIN_ID_NOT_FOUND));
|
||||
|
||||
// 2. jBCrypt + 커스텀 salt 로 저장된 패스워드 비교
|
||||
// jBCrypt + 커스텀 salt 로 저장된 패스워드 비교
|
||||
if (!BCrypt.checkpw(rawPassword, member.getPassword())) {
|
||||
// 실패 카운트 저장
|
||||
int cnt = member.getLoginFailCount() + 1;
|
||||
if (cnt >= 5) {
|
||||
member.setStatus("INACTIVE");
|
||||
member.setStatus(StatusType.INACTIVE.getId());
|
||||
}
|
||||
member.setLoginFailCount(cnt);
|
||||
membersRepository.save(member);
|
||||
throw new CustomApiException(AuthErrorCode.LOGIN_PASSWORD_MISMATCH);
|
||||
}
|
||||
|
||||
// 3. 패스워드 실패 횟수 체크
|
||||
// 삭제 상태
|
||||
if (member.getStatus().equals(StatusType.DELETED.getId())) {
|
||||
throw new CustomApiException(AuthErrorCode.LOGIN_ID_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 패스워드 실패 횟수 체크
|
||||
if (member.getLoginFailCount() >= 5) {
|
||||
throw new CustomApiException(AuthErrorCode.LOGIN_PASSWORD_EXCEEDED);
|
||||
}
|
||||
|
||||
// 4. 인증 성공 로그인 시간 저장
|
||||
if (member.getFirstLoginDttm() == null) {
|
||||
member.setFirstLoginDttm(ZonedDateTime.now());
|
||||
}
|
||||
member.setLastLoginDttm(ZonedDateTime.now());
|
||||
member.setLoginFailCount(0);
|
||||
membersRepository.save(member);
|
||||
|
||||
// 5. 인증 성공 → UserDetails 생성
|
||||
// 인증 성공 → UserDetails 생성
|
||||
CustomUserDetails userDetails = new CustomUserDetails(member);
|
||||
|
||||
return new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
|
||||
|
||||
Reference in New Issue
Block a user