Skip to content

[8 주차] 정용환 / Chapter 8. Spring Security - Security 구조, 폼 로그인 - #40

Open
hwahwahwan wants to merge 6 commits into
UMC-AYU:mainfrom
hwahwahwan:hwan-Chapter08
Open

hwahwahwan wants to merge 6 commits into
UMC-AYU:mainfrom
hwahwahwan:hwan-Chapter08

Conversation

@hwahwahwan

Copy link
Copy Markdown
Contributor

🔗 Issue Number


📝 개요


🚀 주요 변경 사항


🖼️ 실행 결과 (Screenshots)

image

💬 고민 및 질문

생각보다 필터 구조에 대해 완벽하게 이해하지 못한 것 같습니다 틀린 내용 있으면 피드백 부탁드려요

✅ 실습 체크리스트

  • 이론 학습을 완료 했나요?
  • 미션 요구사항을 이해했나요?
  • 미션을 완료 했나요?

⚙️ 환경 및 컨벤션 체크 (Final Check)

  • 디렉토리 구조 컨벤션을 지켰나요?
  • pr 제목을 컨벤션에 맞게 작성하였나요?
  • pr에 해당되는 이슈를 연결하였나요?
  • Assignees을 본인으로 설정했나요?
  • Reviewers을 설정 했나요?
  • 적절한 라벨을 설정하였나요?

@hwahwahwan
hwahwahwan requested review from a team and zldzldzz May 19, 2026 00:22
@hwahwahwan hwahwahwan self-assigned this May 19, 2026
@hwahwahwan
hwahwahwan requested review from cho-hj-dev and m4ppy and removed request for a team May 19, 2026 00:22
Comment on lines +45 to +65
.exceptionHandling(exception -> exception
.accessDeniedHandler(customAccessDenied()) // 403 응답 통일
.authenticationEntryPoint(customEntryPoint()) // 401 응답 통일
);
return http.build();
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public CustomAccessDenied customAccessDenied() {
return new CustomAccessDenied();
}

@Bean
public CustomEntryPoint customEntryPoint() {
return new CustomEntryPoint();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 단순 Handler 클래스라서 직접 생성했는데, 스프링 방식과 확장성을 고려하면 Bean 등록 후 주입받는 구조도 좋을 것 같겠네요.

Comment on lines +19 to +31
public static Member toMember(MemberReqDTO.SignUp dto, String encodedPassword) {
return Member.builder()
.email(dto.email())
.password(encodedPassword)
.name(dto.name())
.gender(dto.gender() != null
? Gender.valueOf(dto.gender().toUpperCase())
: Gender.NONE)
.birthDate(dto.birthDate())
.address(dto.address())
.snsType(dto.snsType())
.build();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컨버터가 매개변수로 암호화된 패스워드를 받게 되면 컨버터 자체의 책임이 애매해 질 수 있을 것 같습니다. 암호화된 패스워드는 서비스 로직 쪽에서 처리하는 게 맞는 방향인 것 같습니다.

@@ -20,22 +19,4 @@ public record SignUp(
List<String> foodTypes,
SnsType snsType

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재는 snsType 만 존재하는데 소셜 로그인을 고려하신다면 소셜 uid 도 함께 관리하는 게 좋을 것 같습니다. 실제 소셜 로그인에서는 일반적으로 (provider, providerUserId) 조합으로 회원을 식별하는 경우가 많다고 알고 있습니다.


public abstract class BaseSecurityHandler {

private static final ObjectMapper objectMapper = new ObjectMapper();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static으로 직접 생성한 ObjectMapper 대신 스프링의 싱글톤 빈을 주입받아 사용하도록 한다면, 형석님이 리뷰 달아주신 빈 주입 구조와도 잘 맞물릴 것 같습니다..!!

Comment on lines +24 to +26
.gender(dto.gender() != null
? Gender.valueOf(dto.gender().toUpperCase())
: Gender.NONE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 이번에 미션을 하면서 대소문자 구분이 안되는 경우랑 null 값이 들어와서 IllegalArgumentException으로 삽질을 좀 했었는데, 용환님이 작성하신걸 보니까 삼항 연산자로 null 방어를 하고, .toUpperCase()로 잘 매핑하신 것 같습니다.

@zldzldzz

zldzldzz commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

아직도 각종 서비스 계층에서 RuntimeException를 사용중입니다.

gender 변환 시 잘못된 값인 경우 500이 나갈 수 있어요

  • ender.valueOf(dto.gender().toUpperCase()) DTO gender가 String이라 "MAN" 같은 잘못된 값이 오면 IllegalArgumentException(500)이 납니다. enum 타입으로 직접 받거나(자동 검증) 변환 실패 시 도메인 예외로 감싸는 편이 좋을 것 같아요

비밀번호 어노테이션에 최소 길이 추가 추천

  지금은 `@NotBlank`만 존재해 "1" 한 글자도 통과합니다.
  // 추천 코드
  @NotBlank(message = "비밀번호는 필수입니다.")
  @Size(min = 8, message = "비밀번호는 8자 이상이어야 합니다.")
  String password

MemberConverter의 인스터스화 방지하는 것도 좋을 것 같아요.

private MemberConverter() {
        // 혹시나 클래스 내부나 리플렉션으로 호출하는 것도 막기 위해 예외를 던지기도 합니다.
        throw new IllegalStateException("Utility class");
    }

사용하지 않는 중복 BaseEntity가 있습니다 (global/apiPayload/BaseEntity.java)

  • 엔티티들은 전부 global.base.BaseEntity를 상속하고 있어서, global/apiPayload/BaseEntity.java는 아무도 안 쓰는 죽은 코드예요. 머지 전에 지워도 동작이 같습니다.
  • (참고로 실제 쓰는 base.BaseEntity의 createdAt에는 @Column(updatable = false)를 붙여주면 수정 시 생성일이 안 바뀌어서 더 안전해요)

미구현

  • 선호 음식 정보가 회원가입 과정에 연결하는 과정이 없는 것 같아요

    • DTO로 foodTypes를 받기만 하고 저장하지 않습니다. MemberConverter.toMember()에서 foodTypes가 누락되어 있고, FoodCategoryRepository 자체가 존재하지 않습니다.
  • 아래 이미지 같이 약관 동의 기능을 추가해도 좋을 것 같아요

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chapter08_Spring Security - Security 구조, 폼 로그인

4 participants