22
33import java .util .List ;
44
5+ import jakarta .annotation .PostConstruct ;
6+
57import org .springframework .beans .factory .annotation .Qualifier ;
68import org .springframework .beans .factory .annotation .Value ;
79import org .springframework .context .annotation .Bean ;
2830import com .example .ssccwebbe .global .security .jwt .filter .JwtFilter ;
2931import com .example .ssccwebbe .global .security .jwt .service .JwtService ;
3032
33+ import lombok .extern .slf4j .Slf4j ;
34+
35+ @ Slf4j
3136@ Configuration
3237@ EnableWebSecurity // 시큐리티 빈 설정 활성화
3338public class SecurityConfig {
@@ -42,6 +47,18 @@ public class SecurityConfig {
4247 @ Value ("${frontend.url}" )
4348 private String frontendUrl ;
4449
50+ @ Value ("${springdoc.swagger-ui.enabled:true}" )
51+ private boolean swaggerEnabled ;
52+
53+ @ Value ("${spring.profiles.active:default}" )
54+ private String activeProfile ;
55+
56+ @ PostConstruct
57+ public void checkConfig () {
58+ log .info ("Active profile: {}" , activeProfile );
59+ log .info ("Swagger UI enabled: {}" , swaggerEnabled );
60+ }
61+
4562 // LoginSuccessHandler 빈을 명확히 주입 받기 위해 Qualifier 설정 도입
4663 public SecurityConfig (
4764 @ Qualifier ("SocialSuccessHandler" ) AuthenticationSuccessHandler socialSuccessHandler ,
@@ -115,16 +132,19 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
115132
116133 // 인가
117134 http .authorizeHttpRequests (
118- auth ->
135+ auth -> {
136+ if (swaggerEnabled ) {
119137 auth .requestMatchers (
120138 "/swagger-ui/**" , "/v3/api-docs/**" , "/swagger-ui.html" )
121- .permitAll () // Swagger UI : 전체 허용
122- .requestMatchers ("/jwt/exchange" , "/jwt/refresh" )
123- .permitAll () // JWT 발급 경로 : 전체 허용
124- .requestMatchers ("/admin/**" )
125- .hasRole (UserRoleType .ADMIN .name ())
126- .anyRequest ()
127- .authenticated ());
139+ .permitAll (); // Swagger UI : 비 prod 환경에서만 허용
140+ }
141+ auth .requestMatchers ("/jwt/exchange" , "/jwt/refresh" )
142+ .permitAll () // JWT 발급 경로 : 전체 허용
143+ .requestMatchers ("/admin/**" )
144+ .hasRole (UserRoleType .ADMIN .name ())
145+ .anyRequest ()
146+ .authenticated ();
147+ });
128148
129149 // 예외 처리
130150 http .exceptionHandling (
0 commit comments