33import lombok .RequiredArgsConstructor ;
44import lombok .extern .slf4j .Slf4j ;
55import org .myteam .server .auth .repository .RefreshJpaRepository ;
6+ import org .myteam .server .global .config .WebConfig ;
67import org .myteam .server .global .security .filter .AuthenticationEntryPointHandler ;
78import org .myteam .server .global .security .filter .CustomAccessDeniedHandler ;
89import org .myteam .server .global .security .handler .LogoutSuccessHandler ;
4546@ RequiredArgsConstructor
4647public class SecurityConfig {
4748
49+ /* 권한 제외 대상 */
50+ private static final String [] permitAllUrl = new String []{
51+ /** @brief test */ "/test/exception-test" ,
52+ /** @brief Swagger Docs */ "/v3/api-docs/**" , "/swagger-ui/**" ,
53+ /** @brief database url */ "/h2-console" ,
54+ /** @brief about login */ "/auth/**" ,
55+ };
56+ /* Admin 접근 권한 */
57+ private static final String [] permitAdminUrl = new String []{
58+ /** @brief Check Access Admin */ "/test/manager-access-test/**" ,
59+ };
60+ /* member 접근 권한 */
61+ private static final String [] permitMemberUrl = new String []{
62+ "/test/user-access-test/**" ,
63+ };
64+
4865 @ Value ("${FRONT_URL:http://localhost:3000}" )
4966 private String frontUrl ;
5067 private final JwtProvider jwtProvider ;
68+ private final WebConfig webConfig ;
5169 private final CustomUserDetailsService customUserDetailsService ;
5270 private final CustomOAuth2UserService customOAuth2UserService ;
5371 private final CustomOauth2SuccessHandler customOauth2SuccessHandler ;
@@ -104,10 +122,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
104122 new JwtAuthenticationFilter (authenticationManager (), jwtProvider , refreshJpaRepository ),
105123 UsernamePasswordAuthenticationFilter .class
106124 ) // 로그인 인증 필터
107- .addFilterAfter (
108- new TokenAuthenticationFilter (jwtProvider ),
109- JwtAuthenticationFilter .class
110- ); // JWT 토큰 검증 필터
125+ .addFilterAfter (new TokenAuthenticationFilter (jwtProvider ), JwtAuthenticationFilter .class )
126+ .addFilter (webConfig .corsFilter ()); // JWT 토큰 검증 필터
111127
112128 // cors 설정
113129 http
@@ -118,7 +134,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
118134 .authorizeHttpRequests (authorizeRequests ->
119135 authorizeRequests
120136 .requestMatchers ("/upload/**" ).permitAll () // 정적 자원 접근 허용
121- .requestMatchers ("/v3/api-docs/**" , "/swagger-ui/**" , "/swagger-resources/**" ).permitAll ()
137+ .requestMatchers (permitAllUrl ).permitAll ()
138+ .requestMatchers (permitAdminUrl ).hasRole ("ADMIN" )
122139
123140 .requestMatchers ("/h2-console" ).permitAll () // H2 콘솔 접근 허용
124141 .requestMatchers ("/api/members/get-token/**" ).permitAll () // 테스트용 토큰 발급용
0 commit comments