-
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.
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package site.timecapsulearchive.core.global.config.security; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
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 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; | ||
|
||
public static JwtDsl jwtDsl( | ||
AuthenticationConfiguration authenticationConfiguration, | ||
AuthenticationProvider authenticationProvider, | ||
AuthenticationFailureHandler authenticationEntryPoint | ||
) { | ||
return new JwtDsl( | ||
authenticationConfiguration, | ||
authenticationProvider, | ||
authenticationEntryPoint | ||
); | ||
} | ||
|
||
@Override | ||
public void init(HttpSecurity http) throws Exception { | ||
http | ||
.authenticationProvider(jwtAuthenticationProvider) | ||
.addFilterBefore( | ||
jwtAuthenticationFilter(), | ||
UsernamePasswordAuthenticationFilter.class | ||
); | ||
} | ||
|
||
private JwtAuthenticationFilter jwtAuthenticationFilter() throws Exception { | ||
return new JwtAuthenticationFilter( | ||
authenticationConfiguration.getAuthenticationManager(), | ||
authenticationFailureHandler | ||
); | ||
} | ||
} |