We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I would like to override the default validation errors, but when I create a basic ControllerAdvice the handler does not get called. My handler:
@ControllerAdvice public class DefaultExceptionHandler implements ProblemHandling { @Override @ExceptionHandler(value = { ConstraintViolationException.class }) public ResponseEntity<Problem> handleConstraintViolation(ConstraintViolationException exception, NativeWebRequest request) { return null; } }
My endpoint:
@PostMapping(value = "/login", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<JwtResponse> login(@Valid @RequestBody LoginRequest loginRequest) { return authService.login(loginRequest); }
My security handler advice:
@ControllerAdvice public class SecurityExceptionHandler implements SecurityAdviceTrait { }
My websecurity config:
@Configuration @EnableMethodSecurity @Import(SecurityProblemSupport.class) public class WebSecurityConfig { @Autowired private SecurityProblemSupport problemSupport; .... @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.cors(cors -> cors.configurationSource(corsConfigurationSource())) .csrf(AbstractHttpConfigurer::disable) .exceptionHandling(exception -> exception.authenticationEntryPoint(problemSupport) .accessDeniedHandler(problemSupport)) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .authorizeHttpRequests(auth -> auth.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() .requestMatchers("/api/auth/**").permitAll().anyRequest().authenticated()); http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class); return http.build(); } }
What am I doing wrong?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I would like to override the default validation errors, but when I create a basic ControllerAdvice the handler does not get called.
My handler:
My endpoint:
My security handler advice:
My websecurity config:
What am I doing wrong?
The text was updated successfully, but these errors were encountered: