Skip to content

Commit

Permalink
fix: permit Get posts, emojis without jwt token
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisWooyeol authored and yangchanhk98 committed Dec 3, 2023
1 parent 25fc0ca commit 89520a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.springframework.web.filter.OncePerRequestFilter

class JwtFilter(private val jwtTokenProvider: JwtTokenProvider) : OncePerRequestFilter() {

private val EXCLUDE_URLS: List<String> = listOf("/api/user/signup", "/api/user/login")

@Throws(IOException::class, ServletException::class)
override fun doFilterInternal(
Expand All @@ -19,21 +18,15 @@ class JwtFilter(private val jwtTokenProvider: JwtTokenProvider) : OncePerRequest
filterChain: FilterChain
) {
try {
if (!shouldExclude(request)) {
val authToken: String = jwtTokenProvider.resolveToken(request)
if (jwtTokenProvider.validateToken(authToken)) {
val authentication = jwtTokenProvider.getAuthentication(authToken)
SecurityContextHolder.getContext().authentication = authentication
}
val authToken: String = jwtTokenProvider.resolveToken(request)
if (jwtTokenProvider.validateToken(authToken)) {
val authentication = jwtTokenProvider.getAuthentication(authToken)
SecurityContextHolder.getContext().authentication = authentication
}
} catch (e: Exception) {
request.setAttribute("exception", e)
throw e
}
filterChain.doFilter(request, response)
}

private fun shouldExclude(request: HttpServletRequest): Boolean {
return EXCLUDE_URLS.stream().anyMatch { url -> request.requestURI.contains(url) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ class SecurityConfig(
private val jwtTokenProvider: JwtTokenProvider,
) {
private val POST_WHITELIST = arrayOf("/api/user/signup", "/api/user/login")
private val GET_WHITELIST = arrayOf("/api/emoji", "/api/post")

@Bean
fun ignoringCustomizer(): WebSecurityCustomizer {
return WebSecurityCustomizer { web: WebSecurity ->
web.ignoring().requestMatchers(HttpMethod.POST, *POST_WHITELIST)
web.ignoring().requestMatchers(HttpMethod.GET, *GET_WHITELIST)
}
}

Expand Down

0 comments on commit 89520a8

Please sign in to comment.