spring-boot-spring-security-jwt-authentication icon indicating copy to clipboard operation
spring-boot-spring-security-jwt-authentication copied to clipboard

getting org.springframework.security.authentication.InsufficientAuthenticationException error If I pass unknown api url or method

Open ambeathirumalesu opened this issue 2 years ago • 0 comments

Hi after implementing the spring security with jwt token it is working as expected with known API urls but when I hit with unknown URL, get 401 authorized error and if any exception is raised at runtime also gets 401 authorized because fo the below exception in Cansole. getting org. spring framework.security.authentication.InsufficientAuthenticationException

do I need to add any filter in AuthEntryPointJwt under the commence? I just wanted to ignore the authentication filter if there is any unknown API hit that came to the application and should throw the NoHandlerFoundException custom exception error with below handler. how can I do that?

@ExceptionHandler(NoHandlerFoundException.class) public ResponseEntity<APIError> handle(NoHandlerFoundException ex){ return new ResponseEntity<>(APIError.createInstance(HttpStatus.NOT_FOUND.toString(), List.of(new ErrorDetails(ex.getMessage(),null))), null, HttpStatus.NOT_FOUND); }

ambeathirumalesu avatar Sep 30 '23 08:09 ambeathirumalesu