Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle IllegalArgumentException in SecurityWebFilterChain bean #939

Open
hantsy opened this issue Oct 12, 2023 · 0 comments
Open

Handle IllegalArgumentException in SecurityWebFilterChain bean #939

hantsy opened this issue Oct 12, 2023 · 0 comments
Labels

Comments

@hantsy
Copy link

hantsy commented Oct 12, 2023

Description

@Configuration
@Import(SecurityProblemSupport::class)
class SecurityConfig{
    @Autowired
    lateinit var problemSupport: SecurityProblemSupport

    //...
    @Bean
    fun springWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain = http {
        //....
        exceptionHandling {
            authenticationEntryPoint = problemSupport
            accessDeniedHandler = problemSupport
        }
        authorizeExchange {
            // ignore all default static resources
            authorize(pathMatchers("/{id}/**"), customCheck())
           //...
        }
   }
   
   fun customCheck():ReactiveAuthenctionManager<AuthenticationContext>{
      // a runtime IllegalArgumentException was thrown here.
   }
}

I have created an exception handler for IllegalArgumentException, it is working well for handling the exceptions from controllers.

Expected Behavior

Handled IllegalArgumentException, return a 400 status.

Actual Behavior

But it throws a 500 internal error instead.

@hantsy hantsy added the Bug label Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant