Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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}")
Comment thread
bell-person-ii marked this conversation as resolved.
private String activeProfile;
Comment thread
bell-person-ii marked this conversation as resolved.

@PostConstruct
public void checkConfig() {
log.info("Active profile: {}", activeProfile);
log.info("Swagger UI enabled: {}", swaggerEnabled);
}

// LoginSuccessHandler λΉˆμ„ λͺ…ν™•νžˆ μ£Όμž… λ°›κΈ° μœ„ν•΄ Qualifier μ„€μ • λ„μž…
public SecurityConfig(
@Qualifier("SocialSuccessHandler") AuthenticationSuccessHandler socialSuccessHandler,
Expand Down Expand Up @@ -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();
Comment thread
bell-person-ii marked this conversation as resolved.
});

// μ˜ˆμ™Έ 처리
http.exceptionHandling(
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading