-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/89 스웨거 API 테스트를 위한 봉사자 / 기관 토큰 발급 #91
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
881a3b0
feat(jwt): JwtAuthFilter 필터 로직 수정
leebs0521 0cff4f3
feat(swagger): 토큰 인증 추가
leebs0521 70723b6
feat(center): 이름 기반 조회 기능 추가
leebs0521 ffb719f
feat(security): 디버깅을 위한 기관 봉사 토큰 발급 기능
leebs0521 1333710
chore: 디버깅 env 추가
leebs0521 fbc9de7
chore: 불필요한 import 제거
leebs0521 e42e33a
Merge branch 'main' into feature/89-add-test-token-publish
leebs0521 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
99 changes: 99 additions & 0 deletions
99
src/main/java/com/somemore/auth/util/DevAccountSetUpConfig.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,99 @@ | ||
| package com.somemore.auth.util; | ||
|
|
||
| import static com.somemore.auth.oauth.OAuthProvider.NAVER; | ||
|
|
||
| import com.somemore.auth.jwt.domain.EncodedToken; | ||
| import com.somemore.auth.jwt.domain.TokenType; | ||
| import com.somemore.auth.jwt.domain.UserRole; | ||
| import com.somemore.auth.jwt.generator.JwtGenerator; | ||
| import com.somemore.auth.jwt.refresh.domain.RefreshToken; | ||
| import com.somemore.auth.jwt.refresh.manager.RefreshTokenManager; | ||
| import com.somemore.center.domain.Center; | ||
| import com.somemore.center.repository.CenterJpaRepository; | ||
| import com.somemore.volunteer.domain.Volunteer; | ||
| import com.somemore.volunteer.repository.VolunteerJpaRepository; | ||
| import jakarta.annotation.PostConstruct; | ||
| import jakarta.annotation.PreDestroy; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| @Component | ||
| public class DevAccountSetUpConfig { | ||
|
|
||
| private final VolunteerJpaRepository volunteerRepository; | ||
| private final CenterJpaRepository centerRepository; | ||
| private final JwtGenerator jwtGenerator; | ||
| private final RefreshTokenManager refreshTokenManager; | ||
|
|
||
| private Volunteer volunteer; | ||
| private Center center; | ||
|
|
||
| @Value("${app.develop.mode:false}") | ||
| private boolean developMode; | ||
|
|
||
| @PostConstruct | ||
| public void generateAccessTokenForDev() { | ||
| if (!developMode) { | ||
| return; // 개발 모드에서만 실행 | ||
| } | ||
|
|
||
| volunteer = Volunteer.createDefault(NAVER, "bongdari"); | ||
| center = Center.create( | ||
| "봉다리 자원봉사센터", | ||
| "02-1234-5678", | ||
| "", | ||
| "봉다리 기관 테스트 계정입니다.", | ||
| "https://somemore.bongdari.com", | ||
| "bongdari", | ||
| "1234" | ||
| ); | ||
|
|
||
| volunteer = volunteerRepository.findByOauthId(volunteer.getOauthId()) | ||
| .orElseGet(() -> volunteerRepository.save(volunteer)); | ||
|
|
||
| center = centerRepository.findByName(center.getName()) | ||
| .orElseGet(() -> centerRepository.save(center)); | ||
|
|
||
| EncodedToken volunteerToken = saveRefreshTokenAndReturnAccessToken(volunteer.getId(), | ||
| UserRole.VOLUNTEER); | ||
| EncodedToken centerToken = saveRefreshTokenAndReturnAccessToken(center.getId(), | ||
| UserRole.CENTER); | ||
|
|
||
| log.info("테스트용 봉사자 AccessToken: {}", volunteerToken.value()); | ||
| log.info("테스트용 기관 AccessToken: {}", centerToken.value()); | ||
| } | ||
|
|
||
| @PreDestroy | ||
| public void cleanup() { | ||
| if (volunteer != null) { | ||
| refreshTokenManager.removeRefreshToken(volunteer.getId().toString()); | ||
| log.info("테스트용 AccessToken 제거, 봉사자 ID: {}", volunteer.getId()); | ||
| } | ||
| if (center != null) { | ||
| refreshTokenManager.removeRefreshToken(center.getId().toString()); | ||
| log.info("테스트용 AccessToken 제거, 기관 ID: {}", center.getId()); | ||
| } | ||
| } | ||
|
|
||
| private EncodedToken saveRefreshTokenAndReturnAccessToken(UUID id, UserRole role) { | ||
| EncodedToken accessToken = generateToken(id, role, TokenType.ACCESS); | ||
| RefreshToken refreshToken = generateRefreshToken(id, role, accessToken); | ||
| refreshTokenManager.save(refreshToken); | ||
| return accessToken; | ||
| } | ||
|
|
||
| private EncodedToken generateToken(UUID id, UserRole role, TokenType tokenType) { | ||
| return jwtGenerator.generateToken(id.toString(), role.name(), tokenType); | ||
| } | ||
|
|
||
| private RefreshToken generateRefreshToken(UUID id, UserRole role, EncodedToken accessToken) { | ||
| return new RefreshToken(id.toString(), accessToken, | ||
| generateToken(id, role, TokenType.REFRESH)); | ||
| } | ||
| } | ||
|
|
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/somemore/global/configure/SwaggerConfig.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,36 @@ | ||
| package com.somemore.global.configure; | ||
|
|
||
| import io.swagger.v3.oas.models.Components; | ||
| import io.swagger.v3.oas.models.OpenAPI; | ||
| import io.swagger.v3.oas.models.info.Info; | ||
| import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
| import io.swagger.v3.oas.models.security.SecurityScheme; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class SwaggerConfig { | ||
|
|
||
| @Bean | ||
| public OpenAPI customOpenAPI() { | ||
| SecurityScheme securityScheme = new SecurityScheme() | ||
| .type(SecurityScheme.Type.HTTP) | ||
| .scheme("bearer") | ||
| .bearerFormat("JWT") | ||
| .description("JWT 토큰을 이용한 인증"); | ||
|
|
||
| SecurityRequirement securityRequirement = new SecurityRequirement() | ||
| .addList("AccessToken"); | ||
|
|
||
| return new OpenAPI() | ||
| .info(new Info() | ||
| .title("Somemore API") | ||
| .version("1.0") | ||
| .description("Somemore swagger-ui 화면입니다.") | ||
| ) | ||
| .components(new Components() | ||
| .addSecuritySchemes("AccessToken", securityScheme) | ||
| ) | ||
| .addSecurityItem(securityRequirement); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| app: | ||
| front-url: ${FRONT_URL} | ||
| back-url: ${BACK_URL} | ||
| develop: | ||
| mode: ${APP_DEVELOP_MODE} | ||
|
|
||
| # AWS S3 | ||
| cloud: | ||
|
|
||
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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| app: | ||
| front-url: "http://localhost:3000" | ||
| back-url: "http://localhost:8080" | ||
| develop: | ||
| mode: false | ||
|
|
||
| spring: | ||
| config: | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 제가 더 직관적으로 수정해보겠습니다! 그대로 올려주셔도 무방합니다.