Skip to content

Commit

Permalink
Feature: (BRD-74) 스프링 시큐리티 필터체인 기본 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
ttasjwi committed Nov 15, 2024
1 parent bf84cd6 commit cf8761f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
4 changes: 2 additions & 2 deletions board-system-external/external-security/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
implementation(Dependencies.SPRING_BOOT_STARTER.fullName)
implementation(Dependencies.SPRING_SECURITY_CRYPTO.fullName)
implementation(Dependencies.SPRING_BOOT_SECURITY.fullName)
implementation(Dependencies.SPRING_BOOT_WEB.fullName)
implementation(Dependencies.SPRING_SECURITY_JOSE.fullName)
implementation(project(":board-system-domain:domain-core"))
implementation(project(":board-system-domain:domain-member"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.ttasjwi.board.system.core.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.annotation.Order
import org.springframework.http.HttpMethod
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.config.annotation.web.invoke
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.web.savedrequest.NullRequestCache

@Configuration
class FilterChainConfig {

@Bean
@Order(0)
fun apiSecurityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
securityMatcher("/api/**")
authorizeHttpRequests {
authorize(HttpMethod.GET, "/api/v1/deploy/health-check", permitAll)

authorize(HttpMethod.GET, "/api/v1/members/email-available", permitAll)
authorize(HttpMethod.GET, "/api/v1/members/username-available", permitAll)
authorize(HttpMethod.GET, "/api/v1/members/nickname-available", permitAll)

authorize(HttpMethod.POST, "/api/v1/members/email-verification/start", permitAll)
authorize(HttpMethod.POST, "/api/v1/members/email-verification", permitAll)
authorize(HttpMethod.POST, "/api/v1/members", permitAll)

authorize(HttpMethod.POST, "/api/v1/auth/login", permitAll)

authorize(anyRequest, authenticated)
}

csrf { disable() }

sessionManagement {
sessionCreationPolicy = SessionCreationPolicy.STATELESS
}

requestCache {
requestCache = NullRequestCache()
}
}
return http.build()
}

@Bean
@Order(1)
fun staticResourceSecurityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
authorizeHttpRequests {
authorize(anyRequest, permitAll)
}
}
return http.build()
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ enum class Dependencies(
SPRING_BOOT_WEB(groupId = "org.springframework.boot", artifactId = "spring-boot-starter-web"),
SPRING_BOOT_DATA_JPA(groupId = "org.springframework.boot", artifactId = "spring-boot-starter-data-jpa"),
SPRING_BOOT_DATA_REDIS(groupId = "org.springframework.boot", artifactId = "spring-boot-starter-data-redis"),
SPRING_BOOT_SECURITY(groupId = "org.springframework.boot", artifactId = "spring-boot-starter-security"),
SPRING_BOOT_MAIL(groupId = "org.springframework.boot", artifactId = "spring-boot-starter-mail"),
SPRING_BOOT_TEST(groupId = "org.springframework.boot", artifactId = "spring-boot-starter-test"),
SPRING_SECURITY_CRYPTO(groupId = "org.springframework.security", artifactId = "spring-security-crypto"),
SPRING_SECURITY_JOSE(groupId = "org.springframework.security", artifactId = "spring-security-oauth2-jose"),

// jackson date time
Expand Down

0 comments on commit cf8761f

Please sign in to comment.