Skip to content

Commit

Permalink
feat : security jwt 설정 추가
Browse files Browse the repository at this point in the history
- security에 jwt 관련 설정 추가
Open #12
  • Loading branch information
seokho-1116 committed Jan 8, 2024
1 parent ab4a486 commit 4429b99
Showing 1 changed file with 47 additions and 0 deletions.
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
);
}
}

0 comments on commit 4429b99

Please sign in to comment.