Skip to content

Commit 7065e59

Browse files
Merge pull request #60 from SoongSilComputingClub/main
[Hot-Fix] sync with main branch
2 parents 07ef3d3 + 51ab176 commit 7065e59

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

src/main/java/com/example/ssccwebbe/global/config/SwaggerConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.Profile;
56

67
import io.swagger.v3.oas.models.Components;
78
import io.swagger.v3.oas.models.OpenAPI;
@@ -20,6 +21,7 @@
2021
import io.swagger.v3.oas.models.security.SecurityScheme;
2122
import io.swagger.v3.oas.models.servers.Server;
2223

24+
@Profile("!prod")
2325
@Configuration
2426
public class SwaggerConfig {
2527

src/main/java/com/example/ssccwebbe/global/security/config/SecurityConfig.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.List;
44

5+
import jakarta.annotation.PostConstruct;
6+
57
import org.springframework.beans.factory.annotation.Qualifier;
68
import org.springframework.beans.factory.annotation.Value;
79
import org.springframework.context.annotation.Bean;
@@ -28,6 +30,9 @@
2830
import com.example.ssccwebbe.global.security.jwt.filter.JwtFilter;
2931
import com.example.ssccwebbe.global.security.jwt.service.JwtService;
3032

33+
import lombok.extern.slf4j.Slf4j;
34+
35+
@Slf4j
3136
@Configuration
3237
@EnableWebSecurity // 시큐리티 빈 설정 활성화
3338
public 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(

src/main/resources/application-prod.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ spring:
2929
- profile
3030
- email
3131

32+
springdoc:
33+
api-docs:
34+
enabled: false # /v3/api-docs API
35+
swagger-ui:
36+
enabled: false # /swagger-ui.html
37+
3238
# JWT Configuration (production uses environment variables)
3339
jwt:
3440
secret-key: ${PROD_JWT_SECRET_KEY}

0 commit comments

Comments
 (0)