Skip to content

Commit a0b14e5

Browse files
authored
Merge pull request #32 from MT-TEAM-Org/feat/PH-84
[refactor] Security Config 파일 내용 수정
2 parents 1a6ca18 + 4aeff5e commit a0b14e5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/main/java/org/myteam/server/global/security/config/SecurityConfig.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.RequiredArgsConstructor;
44
import lombok.extern.slf4j.Slf4j;
55
import org.myteam.server.auth.repository.RefreshJpaRepository;
6+
import org.myteam.server.global.config.WebConfig;
67
import org.myteam.server.global.security.filter.AuthenticationEntryPointHandler;
78
import org.myteam.server.global.security.filter.CustomAccessDeniedHandler;
89
import org.myteam.server.global.security.handler.LogoutSuccessHandler;
@@ -45,9 +46,26 @@
4546
@RequiredArgsConstructor
4647
public 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

Comments
 (0)