use of org.springframework.security.rsocket.api.PayloadInterceptor in project spring-security by spring-projects.
the class PayloadSocketAcceptorTests method acceptWhenDelegateAcceptRequiresReactiveSecurityContext.
@Test
public // gh-8654
void acceptWhenDelegateAcceptRequiresReactiveSecurityContext() {
given(this.setupPayload.metadataMimeType()).willReturn(MediaType.TEXT_PLAIN_VALUE);
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
SecurityContext expectedSecurityContext = new SecurityContextImpl(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
CaptureSecurityContextSocketAcceptor captureSecurityContext = new CaptureSecurityContextSocketAcceptor(this.rSocket);
PayloadInterceptor authenticateInterceptor = (exchange, chain) -> {
Context withSecurityContext = ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedSecurityContext));
return chain.next(exchange).subscriberContext(withSecurityContext);
};
List<PayloadInterceptor> interceptors = Arrays.asList(authenticateInterceptor);
this.acceptor = new PayloadSocketAcceptor(captureSecurityContext, interceptors);
this.acceptor.accept(this.setupPayload, this.rSocket).block();
assertThat(captureSecurityContext.getSecurityContext()).isEqualTo(expectedSecurityContext);
}
Aggregations