Skip to content

[Minsu] Week8 미션#96

Open
miinsoo wants to merge 3 commits into
Minsufrom
minsu-Week8
Open

[Minsu] Week8 미션#96
miinsoo wants to merge 3 commits into
Minsufrom
minsu-Week8

Conversation

@miinsoo
Copy link
Copy Markdown

@miinsoo miinsoo commented May 19, 2026

🔗 연관 이슈

#94

🛠 작업 내용

Spring Security 의존성 업데이트
UsernamePasswordAuthenticationFilter이라는 필터 체인으로 유효한 ID, PW인지 검증
Security Context Holder에 내가 원하는 형태로 AuthenticationPrincipal 저장
permitAll API 요청 설정

🖼 스크린샷 (선택)

👀 리뷰 요구사항 (선택)

🤖 AI 활용

  • AI 사용 안 함
  • 코드 작성 아이디어 참고
  • 테스트/리팩토링 보조
  • 문서/주석 작성 보조
  • 기타 (아래에 간단히 작성)

💬 나의 프롬프트

계획, 개발, 테스트, 빌드 부분을 파이프라인으로 자동화했다.

🧠 AI 응답

각 단계별로 수행을 해줬다.

✅ 내가 최종 선택한 방법 (이유)

휴먼 에러를 줄이고, 자동화를 하기 위해서 이 방안을 선택했다.

💡 나만의 Tip (선택)

@miinsoo miinsoo self-assigned this May 19, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 806001c60a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(requests -> requests
.requestMatchers(PUBLIC_URIS).permitAll()
.anyRequest().authenticated()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow error dispatch before enforcing authentication

anyRequest().authenticated()만 두면 Spring Boot의 /error 경로와 ERROR 디스패치까지 인증 대상으로 묶여서, 비로그인 요청에서 원래 404/500이어야 할 상황이 401로 덮일 수 있습니다(예: 존재하지 않는 URL 호출, permitAll 엔드포인트 내부 예외). 이러면 전역 예외 처리/에러 응답 학습이 왜곡되므로, /error 또는 dispatcherTypeMatchers(ERROR, FORWARD)permitAll로 열고 실제 보호가 필요한 API 경로 중심으로 인증을 거는 방식으로 수정해 보세요. 다음으로는 Spring Security의 DispatcherType 매칭과 Boot 기본 에러 처리 흐름을 같이 공부하는 것을 권장합니다.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@kjhh2605 kjhh2605 left a comment

Choose a reason for hiding this comment

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

[키워드 조사]
Spring Security의 핵심 흐름을 인증, 인가, SecurityFilterChain, UserDetailsService, PasswordEncoder, Stateful/Stateless 관점으로 정리한 점이 좋습니다. 현재 구현이 formLogin 기반 세션 인증에 가깝기 때문에 SecurityContext, Session, CSRF 설정이 어떤 관계로 동작하는지 추가로 연결하는 것을 권장합니다. 또한 인증 실패 401과 인가 실패 403이 각각 어떤 Spring Security 예외와 핸들러를 거치는지 함께 정리하면 코드 적용력이 높아집니다.

[코드 리뷰]
회원가입 DTO 검증, 비밀번호 암호화, UserDetailsService, AuthMember, SecurityFilterChain, 인증/인가 예외 응답, 통합 테스트까지 Week8 보안 흐름의 핵심 요소를 한 번에 연결한 점이 좋습니다. 특히 비밀번호를 저장 전에 인코딩하고 로그인 테스트를 추가한 방향은 적절합니다. 보완할 부분은 테스트 입력값과 검증 규칙을 일치시키는 것, formLogin 리다이렉트 흐름과 JSON API 응답 전략을 분리해서 설계하는 것, 중복 의존성처럼 빌드 설정을 정리하는 것입니다. 인증 기능은 설정 하나가 전체 요청 흐름에 영향을 주므로 회원가입 → 로그인 → 보호 API 호출 → 예외 응답까지 하나의 시나리오로 확인하는 것을 권장합니다.

{
"name": "홍길동",
"email": "user@example.com",
"password": "password1234"
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.

회원가입 성공 테스트에서는 rawPassword와 요청 JSON의 password 값이 같아야 암호화 검증 의도가 정확해집니다. 현재 값은 @Size(min = 8) 검증에도 걸릴 수 있으므로 password1234처럼 DTO 검증을 통과하는 동일 값을 사용하는 것을 권장합니다.

.formLogin(form -> form
.usernameParameter("email")
.passwordParameter("password")
.defaultSuccessUrl("/swagger-ui/index.html", true)
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.

REST API 응답을 공통 JSON으로 맞추는 흐름이라면 로그인 성공 시 Swagger로 리다이렉트하는 전략과 API 클라이언트 계약이 섞일 수 있습니다. 학습 단계에서는 formLogin 세션 방식인지 JSON 로그인 API 방식인지 먼저 구분하고, 성공/실패 응답 정책을 한 흐름으로 정리하는 것을 권장합니다.

implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
implementation 'org.springframework.boot:spring-boot-starter-validation'
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.

spring-boot-starter-validation이 위에서 이미 선언되어 있어 중복 의존성으로 보입니다. 동작에는 큰 문제가 없을 수 있지만, 빌드 파일은 의존성 의도를 보여주는 문서 역할도 하므로 하나만 남기는 것을 권장합니다.

예를 들어 이메일과 비밀번호로 로그인해서 DB에 저장된 회원인지 확인하는 흐름이 인증이다.
인가(Authorization)는 “인증된 사용자가 이 기능에 접근할 권한이 있는가?”를 확인하는 과정이다.
로그인하지 않은 사용자가 Private API에 접근하면 인증 실패로 401 응답이 나가고, 권한이 부족하면 인가 실패로 403 응답이 나간다.
Spring Security에서는 인증 후 생성된 `Authentication` 객체의 권한 정보를 바탕으로 인가 판단을 수행한다.
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.

인증/인가 차이를 401/403과 연결한 점이 좋습니다. 여기에 AuthenticationExceptionAccessDeniedException이 각각 EntryPoint와 AccessDeniedHandler로 이어지는 흐름을 추가하면 코드의 예외 처리와 개념 정리가 더 잘 연결됩니다.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants