2017-12-24 15 views
4

스프링 webflux에서 앱을 만들고 있는데 스프링 보안 webflux (v.M5)가 예외 처리 기간에 스프링 4처럼 작동하지 않아 붙어 있습니다. 우리는 예외가 ServerSecurityContextRepository.load에서, 스프링 (500)이 예외를 조작하기 위해 내가 할 수있는 아무것도 HTTP 헤더를 업데이트한다고 가정 해 봅시다 던질 경우 Spring webflux custom authentication for API스프링 보안 Webflux/리 액티브 예외 처리

:

나는 봄 보안 webflux을 사용자 지정하는 방법에 대한 다음과 같은 글을 보았다.

그러나 컨트롤러에서 발생하는 모든 오류는 일반 @ControllerAdvice를 사용하여 처리 할 수 ​​있습니다.

스프링 webflux 보안에서 예외를 처리 할 여지가 있습니까?

답변

0

비슷한 문제가있는 수많은 문서를 보았습니다.

내 솔루션에서 ResponseStatusException을 사용하고있었습니다. Spring 보안의 AccessException이 이해되는 것 같습니다.

.doOnError(
      t -> AccessDeniedException.class.isAssignableFrom(t.getClass()), 
      t -> AUDIT.error("Error {} {}, tried to access {}", t.getMessage(), principal, exchange.getRequest().getURI())) // if an error happens in the stream, show its message 
.onErrorMap(
     SomeOtherException.class, 
     t -> { return new ResponseStatusException(HttpStatus.NOT_FOUND, "Collection not found");}) 
     ; 

이것이 올바른 방향으로가는 경우 조금 더 나은 샘플을 제공 할 수 있습니다.