Skip to content

Commit

Permalink
feat: securityConfig JwtAuthenticationFilter 적용 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
choidongkuen committed Jan 6, 2024
1 parent 78ef69b commit e8e27c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/main/java/net/teumteum/core/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


import lombok.RequiredArgsConstructor;
import net.teumteum.core.property.JwtProperty;
import net.teumteum.core.security.filter.JwtAuthenticationFilter;
import net.teumteum.core.security.service.AuthService;
import net.teumteum.core.security.service.JwtService;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -10,6 +14,7 @@
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
Expand All @@ -21,8 +26,9 @@
@EnableWebSecurity
public class SecurityConfig {

// authentication 필요 없는 url 정보
// private final String[] allowedUrl = {"/auth/reissue", "/users/signup"};
private final JwtService jwtService;
private final AuthService authService;
private final JwtProperty jwtProperty;

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http, HandlerMappingIntrospector introspector) throws Exception {
Expand All @@ -34,6 +40,7 @@ SecurityFilterChain securityFilterChain(HttpSecurity http, HandlerMappingIntrosp
.requestMatchers(PathRequest.toH2Console()).permitAll())
.httpBasic(AbstractHttpConfigurer::disable)
.formLogin(AbstractHttpConfigurer::disable)
.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.sessionManagement(sessionManagement
-> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
Expand All @@ -55,4 +62,8 @@ public CorsConfigurationSource corsConfigurationSource() {
source.registerCorsConfiguration("/**", configuration);
return source;
}

private JwtAuthenticationFilter jwtAuthenticationFilter() {
return new JwtAuthenticationFilter(jwtService, authService, jwtProperty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
import net.teumteum.user.domain.User;
import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

@Component
@RequiredArgsConstructor
@Slf4j
public class JwtAuthenticationFilter extends OncePerRequestFilter {
Expand Down

0 comments on commit e8e27c8

Please sign in to comment.