-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 비밀번호 변경 API 구현 #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
whqtker
merged 18 commits into
solid-connection:develop
from
whqtker:feat/446-change-password-api
Aug 14, 2025
Merged
feat: 비밀번호 변경 API 구현 #448
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ddf8c9b
feat: 비밀번호 변경 DTO 작성
whqtker a191838
feat: 비밀번호 변경 검증 관련 어노테이션 작성
whqtker 7edef0c
feat: 비밀번호 변경 API 구현
whqtker 8b0f39b
test: 비밀번호 변경 관련 테스트 코드 작성
whqtker aa5cbcf
chore: 코드 리포매팅
whqtker b6daeb3
test: 검증 방식 변경
whqtker 03b08fa
chore: Password 어노테이션 추가
whqtker 24170c8
chore: 명확하게 의미 전달이 가능한 변수명으로 수정
whqtker 2f0675f
test: 테스트 코드 수정
whqtker cb212d9
test: 실제 비밀번호 변경 플로우에 맞도록 테스트 코드 수정
whqtker c1403c3
chore: matches 메서드 정의에 맞게 파라미터 수정
whqtker d0f6df0
chore: 역할을 더 잘 드러내도록 검증 메서드명 변경
whqtker a1888c2
feat: 비밀번호 검증 추가
Gyuhyeok99 7df664e
Merge branch 'develop' into feat/446-change-password-api
whqtker 99a1f6d
fix: Password 어노테이션 import문 추가
whqtker 8833132
Merge branch 'feat/446-change-password-api' of https://github.com/whq…
whqtker a58199e
fix: currentPassword가 인코딩되었던 문제 해결
whqtker 43a720b
Merge branch 'develop' into feat/446-change-password-api
whqtker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/solidconnection/siteuser/dto/PasswordUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.example.solidconnection.siteuser.dto; | ||
|
|
||
| import com.example.solidconnection.auth.dto.validation.Password; | ||
| import com.example.solidconnection.siteuser.dto.validation.PasswordConfirmation; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| @PasswordConfirmation | ||
| public record PasswordUpdateRequest( | ||
| @NotBlank(message = "현재 비밀번호를 입력해주세요.") | ||
| String currentPassword, | ||
|
|
||
| @NotBlank(message = "새 비밀번호를 입력해주세요.") | ||
| @Password | ||
| String newPassword, | ||
|
|
||
| @NotBlank(message = "새 비밀번호를 다시 한번 입력해주세요.") | ||
| String newPasswordConfirmation | ||
| ) { | ||
|
|
||
| } | ||
whqtker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/solidconnection/siteuser/dto/validation/PasswordConfirmation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.example.solidconnection.siteuser.dto.validation; | ||
|
|
||
| import jakarta.validation.Constraint; | ||
| import jakarta.validation.Payload; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Constraint(validatedBy = PasswordConfirmationValidator.class) | ||
| @Target({ElementType.TYPE}) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface PasswordConfirmation { | ||
|
|
||
| String message() default "비밀번호 변경 과정에서 오류가 발생했습니다."; | ||
|
|
||
| Class<?>[] groups() default {}; | ||
|
|
||
| Class<? extends Payload>[] payload() default {}; | ||
| } |
45 changes: 45 additions & 0 deletions
45
...va/com/example/solidconnection/siteuser/dto/validation/PasswordConfirmationValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.example.solidconnection.siteuser.dto.validation; | ||
|
|
||
| import static com.example.solidconnection.common.exception.ErrorCode.PASSWORD_NOT_CHANGED; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.PASSWORD_NOT_CONFIRMED; | ||
|
|
||
| import com.example.solidconnection.siteuser.dto.PasswordUpdateRequest; | ||
| import jakarta.validation.ConstraintValidator; | ||
| import jakarta.validation.ConstraintValidatorContext; | ||
| import java.util.Objects; | ||
|
|
||
| public class PasswordConfirmationValidator implements ConstraintValidator<PasswordConfirmation, PasswordUpdateRequest> { | ||
|
|
||
| @Override | ||
| public boolean isValid(PasswordUpdateRequest request, ConstraintValidatorContext context) { | ||
| context.disableDefaultConstraintViolation(); | ||
|
|
||
| if (isNewPasswordNotConfirmed(request)) { | ||
| addConstraintViolation(context, PASSWORD_NOT_CONFIRMED.getMessage(), "newPasswordConfirmation"); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| if (isPasswordUnchanged(request)) { | ||
| addConstraintViolation(context, PASSWORD_NOT_CHANGED.getMessage(), "newPassword"); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private boolean isNewPasswordNotConfirmed(PasswordUpdateRequest request) { | ||
| return !Objects.equals(request.newPassword(), request.newPasswordConfirmation()); | ||
| } | ||
|
|
||
| private boolean isPasswordUnchanged(PasswordUpdateRequest request) { | ||
| return Objects.equals(request.currentPassword(), request.newPassword()); | ||
| } | ||
|
|
||
| private void addConstraintViolation(ConstraintValidatorContext context, String message, String propertyName) { | ||
| context.buildConstraintViolationWithTemplate(message) | ||
| .addPropertyNode(propertyName) | ||
| .addConstraintViolation(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...om/example/solidconnection/siteuser/dto/validation/PasswordConfirmationValidatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package com.example.solidconnection.siteuser.dto.validation; | ||
|
|
||
| import static com.example.solidconnection.common.exception.ErrorCode.PASSWORD_NOT_CHANGED; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.PASSWORD_NOT_CONFIRMED; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.example.solidconnection.siteuser.dto.PasswordUpdateRequest; | ||
| import jakarta.validation.ConstraintViolation; | ||
| import jakarta.validation.Validation; | ||
| import jakarta.validation.Validator; | ||
| import jakarta.validation.ValidatorFactory; | ||
| import java.util.Set; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| @DisplayName("비밀번호 변경 유효성 검사 테스트") | ||
| class PasswordConfirmationValidatorTest { | ||
|
|
||
| private static final String MESSAGE = "message"; | ||
|
|
||
| private Validator validator; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); | ||
| validator = factory.getValidator(); | ||
| } | ||
|
|
||
| @Test | ||
| void 유효한_비밀번호_변경_요청은_검증을_통과한다() { | ||
| // given | ||
| PasswordUpdateRequest request = new PasswordUpdateRequest("currentPassword123", "newPassword123!", "newPassword123!"); | ||
|
|
||
| // when | ||
| Set<ConstraintViolation<PasswordUpdateRequest>> violations = validator.validate(request); | ||
|
|
||
| // then | ||
| assertThat(violations).isEmpty(); | ||
| } | ||
|
|
||
| @Nested | ||
| class 유효하지_않은_비밀번호_변경_테스트 { | ||
|
|
||
| @Test | ||
| void 새로운_비밀번호와_확인_비밀번호가_일치하지_않으면_검증에_실패한다() { | ||
| // given | ||
| PasswordUpdateRequest request = new PasswordUpdateRequest("currentPassword123", "newPassword123!", "differentPassword123!"); | ||
|
|
||
| // when | ||
| Set<ConstraintViolation<PasswordUpdateRequest>> violations = validator.validate(request); | ||
|
|
||
| // then | ||
| assertThat(violations) | ||
| .isNotEmpty() | ||
| .extracting(MESSAGE) | ||
| .contains(PASSWORD_NOT_CONFIRMED.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void 현재_비밀번호와_새로운_비밀번호가_같으면_검증에_실패한다() { | ||
| // given | ||
| PasswordUpdateRequest request = new PasswordUpdateRequest("currentPassword123", "currentPassword123", "currentPassword123"); | ||
|
|
||
| // when | ||
| Set<ConstraintViolation<PasswordUpdateRequest>> violations = validator.validate(request); | ||
|
|
||
| // then | ||
| assertThat(violations) | ||
| .isNotEmpty() | ||
| .extracting(MESSAGE) | ||
| .contains(PASSWORD_NOT_CHANGED.getMessage()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.