Skip to content

Commit

Permalink
add :: filterConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
meltapplee committed Sep 3, 2024
1 parent 30f8fce commit 2260584
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/main/kotlin/org/meogo/global/config/FilterConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.meogo.global.config

import com.fasterxml.jackson.databind.ObjectMapper
import org.meogo.global.error.GlobalExceptionFilter
import org.meogo.global.jwt.JwtTokenFilter
import org.meogo.global.jwt.JwtTokenProvider
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.SecurityConfigurerAdapter
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.web.DefaultSecurityFilterChain
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

@Configuration
class FilterConfig(
private val objectMapper: ObjectMapper,
private val jwtTokenProvider: JwtTokenProvider
) : SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity>() {

override fun configure(builder: HttpSecurity) {
builder.addFilterBefore(JwtTokenFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter::class.java)
builder.addFilterBefore(GlobalExceptionFilter(objectMapper), JwtTokenFilter::class.java)
}
}
11 changes: 10 additions & 1 deletion src/main/kotlin/org/meogo/global/config/SecurityConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.meogo.global.config

import com.fasterxml.jackson.databind.ObjectMapper
import org.meogo.global.jwt.JwtTokenProvider
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpStatus
Expand All @@ -10,10 +12,14 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.HttpStatusEntryPoint
import org.springframework.web.cors.CorsUtils
import javax.servlet.FilterConfig

@Configuration
@EnableWebSecurity
class SecurityConfig {
class SecurityConfig(
private val objectMapper: ObjectMapper,
private val jwtTokenProvider: JwtTokenProvider
) {

@Bean
protected fun filterChain(http: HttpSecurity): SecurityFilterChain {
Expand All @@ -33,6 +39,9 @@ class SecurityConfig {
.exceptionHandling()
.authenticationEntryPoint(HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))

http
.apply(FilterConfig(objectMapper, jwtTokenProvider))

return http.build()
}

Expand Down

0 comments on commit 2260584

Please sign in to comment.