Skip to content

Commit

Permalink
♻️ :: authenticationEntryPoint 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jaemin05 committed Jul 11, 2023
1 parent 8f7793f commit 9cbac3c
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpStatus
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
import org.springframework.security.config.web.server.ServerHttpSecurity
import org.springframework.security.core.AuthenticationException
import org.springframework.security.web.server.SecurityWebFilterChain
import org.springframework.security.web.server.authentication.HttpStatusServerEntryPoint
import org.springframework.security.web.server.ServerAuthenticationEntryPoint
import org.springframework.stereotype.Component
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono

@Configuration
@EnableWebFluxSecurity
Expand All @@ -21,8 +25,16 @@ class SecurityConfiguration {
.anyExchange().authenticated()
.and()
.httpBasic()
.authenticationEntryPoint(HttpStatusServerEntryPoint(HttpStatus.UNAUTHORIZED))
.authenticationEntryPoint(CustomAuthenticationEntryPoint())
.and()
.build()
}
}

@Component
class CustomAuthenticationEntryPoint : ServerAuthenticationEntryPoint {
override fun commence(exchange: ServerWebExchange, ex: AuthenticationException): Mono<Void> {
exchange.response.statusCode = HttpStatus.UNAUTHORIZED
return exchange.response.setComplete()
}
}

0 comments on commit 9cbac3c

Please sign in to comment.