http.exceptionHandler() deprecated and removed in spring 6.2
Asked Answered
P

2

8

I am trying to set up HttpSecurity in Spring 6.1.2 and I need to add jwtEntrypoint to it but I discovered

protected void configure(HttpSecurity http) throws Exception {
    http.cors().and().csrf().disable();
    http.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint);has been removed

I tried http.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint); as seen in some answers but it still doesnt work

Pindling answered 2/8, 2023 at 22:37 Comment(0)
P
16

I found the solution. Apparently spring has removed http.exceptionHandling() in spring 6.1 so to solve the problem I did

  http.exceptionHandling((exception)-> exception.authenticationEntryPoint(jwtAuthenticationEntryPoint).accessDeniedPage("/error/accedd-denied"));
Pindling answered 2/8, 2023 at 22:44 Comment(2)
Thanks @Obj (+1). Its absolutely bananas to me that the Spring Security team hasn't attempted to explain this in any public facing docs and that I have to go to SO for the authoritative answer!Intolerant
@Pindling what i should do if we have .and() .sessionManagement() and .authorizedRequests()Implode
B
0

If in Kotlin

.exceptionHandling {
     it.authenticationEntryPoint(jwtAuthenticationEntryPoint)
}
Bibber answered 15/7, 2024 at 19:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.