@Test public void unauthenticated() { SecurityContext expectedContext = new SecurityContextImpl(); ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)); Mono<XsuaaToken> tokenMono = ReactiveSecurityContext.getToken(); StepVerifier.create(tokenMono) .expectError(AccessDeniedException.class) .verify(); }
static public Mono<XsuaaToken> getToken() { return ReactiveSecurityContextHolder.getContext() .switchIfEmpty(Mono.error(new AccessDeniedException("Access forbidden: not authenticated"))) .map(SecurityContext::getAuthentication) .map(Authentication::getCredentials) .map(credentials -> new XsuaaToken((Jwt) credentials)) .doOnSuccess(token -> logger.info("Got Jwt token: {}", token)) .doOnError(throwable -> logger.error("ERROR to getToken", throwable)); }
ReactiveSecurityContext { static public Mono<XsuaaToken> getToken() { return ReactiveSecurityContextHolder.getContext() .switchIfEmpty(Mono.error(new AccessDeniedException("Access forbidden: not authenticated"))) .map(SecurityContext::getAuthentication) .map(Authentication::getCredentials) .map(credentials -> new XsuaaToken((Jwt) credentials)) .doOnSuccess(token -> logger.info("Got Jwt token: {}", token)) .doOnError(throwable -> logger.error("ERROR to getToken", throwable)); } }
ReactiveSecurityContext { static public Mono<XsuaaToken> getToken() { return ReactiveSecurityContextHolder.getContext() .switchIfEmpty(Mono.error(new AccessDeniedException("Access forbidden: not authenticated"))) .map(SecurityContext::getAuthentication) .map(Authentication::getCredentials) .map(credentials -> new XsuaaToken((Jwt) credentials)) .doOnSuccess(token -> logger.info("Got Jwt token: {}", token)) .doOnError(throwable -> logger.error("ERROR to getToken", throwable)); } private  ReactiveSecurityContext(); }
ReactiveSecurityContext { static public Mono<XsuaaToken> getToken() { return ReactiveSecurityContextHolder.getContext() .switchIfEmpty(Mono.error(new AccessDeniedException("Access forbidden: not authenticated"))) .map(SecurityContext::getAuthentication) .map(Authentication::getCredentials) .map(credentials -> new XsuaaToken((Jwt) credentials)) .doOnSuccess(token -> logger.info("Got Jwt token: {}", token)) .doOnError(throwable -> logger.error("ERROR to getToken", throwable)); } private  ReactiveSecurityContext(); static Mono<XsuaaToken> getToken(); }
ReactiveSecurityContext { static public Mono<XsuaaToken> getToken() { return ReactiveSecurityContextHolder.getContext() .switchIfEmpty(Mono.error(new AccessDeniedException("Access forbidden: not authenticated"))) .map(SecurityContext::getAuthentication) .map(Authentication::getCredentials) .map(credentials -> new XsuaaToken((Jwt) credentials)) .doOnSuccess(token -> logger.info("Got Jwt token: {}", token)) .doOnError(throwable -> logger.error("ERROR to getToken", throwable)); } private  ReactiveSecurityContext(); static Mono<XsuaaToken> getToken();  }