diff --git a/src/main/java/com/example/ssccwebbe/global/config/SwaggerConfig.java b/src/main/java/com/example/ssccwebbe/global/config/SwaggerConfig.java index 3ea7626..feaa074 100644 --- a/src/main/java/com/example/ssccwebbe/global/config/SwaggerConfig.java +++ b/src/main/java/com/example/ssccwebbe/global/config/SwaggerConfig.java @@ -2,6 +2,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; @@ -20,6 +21,7 @@ import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; +@Profile("!prod") @Configuration public class SwaggerConfig { diff --git a/src/main/java/com/example/ssccwebbe/global/security/config/SecurityConfig.java b/src/main/java/com/example/ssccwebbe/global/security/config/SecurityConfig.java index ad63abb..a1e82ec 100644 --- a/src/main/java/com/example/ssccwebbe/global/security/config/SecurityConfig.java +++ b/src/main/java/com/example/ssccwebbe/global/security/config/SecurityConfig.java @@ -2,6 +2,8 @@ import java.util.List; +import jakarta.annotation.PostConstruct; + import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -28,6 +30,9 @@ import com.example.ssccwebbe.global.security.jwt.filter.JwtFilter; import com.example.ssccwebbe.global.security.jwt.service.JwtService; +import lombok.extern.slf4j.Slf4j; + +@Slf4j @Configuration @EnableWebSecurity // 시큐리티 빈 설정 활성화 public class SecurityConfig { @@ -42,6 +47,18 @@ public class SecurityConfig { @Value("${frontend.url}") private String frontendUrl; + @Value("${springdoc.swagger-ui.enabled:true}") + private boolean swaggerEnabled; + + @Value("${spring.profiles.active:default}") + private String activeProfile; + + @PostConstruct + public void checkConfig() { + log.info("Active profile: {}", activeProfile); + log.info("Swagger UI enabled: {}", swaggerEnabled); + } + // LoginSuccessHandler 빈을 명확히 주입 받기 위해 Qualifier 설정 도입 public SecurityConfig( @Qualifier("SocialSuccessHandler") AuthenticationSuccessHandler socialSuccessHandler, @@ -115,16 +132,19 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti // 인가 http.authorizeHttpRequests( - auth -> + auth -> { + if (swaggerEnabled) { auth.requestMatchers( "/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html") - .permitAll() // Swagger UI : 전체 허용 - .requestMatchers("/jwt/exchange", "/jwt/refresh") - .permitAll() // JWT 발급 경로 : 전체 허용 - .requestMatchers("/admin/**") - .hasRole(UserRoleType.ADMIN.name()) - .anyRequest() - .authenticated()); + .permitAll(); // Swagger UI : 비 prod 환경에서만 허용 + } + auth.requestMatchers("/jwt/exchange", "/jwt/refresh") + .permitAll() // JWT 발급 경로 : 전체 허용 + .requestMatchers("/admin/**") + .hasRole(UserRoleType.ADMIN.name()) + .anyRequest() + .authenticated(); + }); // 예외 처리 http.exceptionHandling( diff --git a/src/main/resources/application-prod.yaml b/src/main/resources/application-prod.yaml index a962c50..7df8dcd 100644 --- a/src/main/resources/application-prod.yaml +++ b/src/main/resources/application-prod.yaml @@ -29,6 +29,12 @@ spring: - profile - email +springdoc: + api-docs: + enabled: false # /v3/api-docs API + swagger-ui: + enabled: false # /swagger-ui.html + # JWT Configuration (production uses environment variables) jwt: secret-key: ${PROD_JWT_SECRET_KEY}