-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from tukcomCD2024/ARCH-114-fix/jwt
fix: jwt 인증 필터
- Loading branch information
Showing
22 changed files
with
315 additions
and
252 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
2 changes: 1 addition & 1 deletion
2
...ava/site/timecapsulearchive/core/domain/auth/exception/AlreadyReIssuedTokenException.java
This file contains 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 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 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 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 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
25 changes: 25 additions & 0 deletions
25
backend/core/src/main/java/site/timecapsulearchive/core/global/common/response/ApiSpec.java
This file contains 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,25 @@ | ||
package site.timecapsulearchive.core.global.common.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@Schema(description = "api 공통 응답 ") | ||
public record ApiSpec<T>( | ||
|
||
@Schema(description = "응답 코드") | ||
String code, | ||
|
||
@Schema(description = "응답 메시지") | ||
String message, | ||
|
||
@Schema(description = "응답 데이터") | ||
T result | ||
) { | ||
|
||
public static <T> ApiSpec<T> empty(SuccessCode code) { | ||
return new ApiSpec<>(code.getMessage(), code.getCode(), null); | ||
} | ||
|
||
public static <T> ApiSpec<T> success(SuccessCode code, T result) { | ||
return new ApiSpec<>(code.getCode(), code.getMessage(), result); | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
...end/core/src/main/java/site/timecapsulearchive/core/global/common/response/ErrorCode.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...d/core/src/main/java/site/timecapsulearchive/core/global/common/response/SuccessCode.java
This file contains 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,14 @@ | ||
package site.timecapsulearchive.core.global.common.response; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum SuccessCode { | ||
//success handle | ||
SUCCESS("00", "요청 처리에 성공했습니다."); | ||
|
||
private final String code; | ||
private final String message; | ||
} |
29 changes: 16 additions & 13 deletions
29
backend/core/src/main/java/site/timecapsulearchive/core/global/config/security/JwtDsl.java
This file contains 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,47 +1,50 @@ | ||
package site.timecapsulearchive.core.global.config.security; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.authentication.AuthenticationProvider; | ||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.web.authentication.AuthenticationFailureHandler; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
import site.timecapsulearchive.core.global.security.jwt.JwtAuthenticationFilter; | ||
|
||
@RequiredArgsConstructor | ||
public class JwtDsl extends AbstractHttpConfigurer<JwtDsl, HttpSecurity> { | ||
|
||
private final AuthenticationConfiguration authenticationConfiguration; | ||
private final AuthenticationProvider jwtAuthenticationProvider; | ||
private final AuthenticationFailureHandler authenticationFailureHandler; | ||
private final ObjectMapper objectMapper; | ||
private final RequestMatcher notRequireAuthenticationMatcher; | ||
|
||
public static JwtDsl jwtDsl( | ||
AuthenticationConfiguration authenticationConfiguration, | ||
AuthenticationProvider authenticationProvider, | ||
AuthenticationFailureHandler authenticationEntryPoint | ||
ObjectMapper objectMapper, | ||
RequestMatcher requestMatcher | ||
) { | ||
return new JwtDsl( | ||
authenticationConfiguration, | ||
authenticationProvider, | ||
authenticationEntryPoint | ||
objectMapper, | ||
requestMatcher | ||
); | ||
} | ||
|
||
@Override | ||
public void init(HttpSecurity http) throws Exception { | ||
public void configure(HttpSecurity http) { | ||
http | ||
.authenticationProvider(jwtAuthenticationProvider) | ||
.addFilterBefore( | ||
jwtAuthenticationFilter(), | ||
jwtAuthenticationFilter(http.getSharedObject(AuthenticationManager.class)), | ||
UsernamePasswordAuthenticationFilter.class | ||
); | ||
} | ||
|
||
private JwtAuthenticationFilter jwtAuthenticationFilter() throws Exception { | ||
private JwtAuthenticationFilter jwtAuthenticationFilter( | ||
AuthenticationManager authenticationManager) { | ||
return new JwtAuthenticationFilter( | ||
authenticationConfiguration.getAuthenticationManager(), | ||
authenticationFailureHandler | ||
authenticationManager, | ||
objectMapper, | ||
notRequireAuthenticationMatcher | ||
); | ||
} | ||
} |
Oops, something went wrong.