Search in sources :

Example 1 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class PayloadSocketAcceptorTests method captureExchange.

private PayloadExchange captureExchange() {
    given(this.delegate.accept(any(), any())).willReturn(Mono.just(this.rSocket));
    given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
    RSocket result = this.acceptor.accept(this.setupPayload, this.rSocket).block();
    assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
    given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
    result.fireAndForget(this.payload).block();
    ArgumentCaptor<PayloadExchange> exchangeArg = ArgumentCaptor.forClass(PayloadExchange.class);
    verify(this.interceptor, times(2)).intercept(exchangeArg.capture(), any());
    return exchangeArg.getValue();
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) RSocket(io.rsocket.RSocket)

Example 2 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class PayloadSocketAcceptorTests method acceptWhenDefaultMetadataMimeTypeThenDefaulted.

@Test
public void acceptWhenDefaultMetadataMimeTypeThenDefaulted() {
    given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
    PayloadExchange exchange = captureExchange();
    assertThat(exchange.getMetadataMimeType().toString()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
    assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) Test(org.junit.jupiter.api.Test)

Example 3 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class AuthenticationPayloadInterceptorTests method interceptWhenBasicCredentialsThenAuthenticates.

@Test
public void interceptWhenBasicCredentialsThenAuthenticates() {
    AuthenticationPayloadInterceptor interceptor = new AuthenticationPayloadInterceptor(this.authenticationManager);
    PayloadExchange exchange = createExchange();
    TestingAuthenticationToken expectedAuthentication = new TestingAuthenticationToken("user", "password");
    given(this.authenticationManager.authenticate(any())).willReturn(Mono.just(expectedAuthentication));
    AuthenticationPayloadInterceptorChain authenticationPayloadChain = new AuthenticationPayloadInterceptorChain();
    interceptor.intercept(exchange, authenticationPayloadChain).block();
    Authentication authentication = authenticationPayloadChain.getAuthentication();
    verify(this.authenticationManager).authenticate(this.authenticationArg.capture());
    assertThat(this.authenticationArg.getValue()).isEqualToComparingFieldByField(new UsernamePasswordAuthenticationToken("user", "password"));
    assertThat(authentication).isEqualTo(expectedAuthentication);
}
Also used : DefaultPayloadExchange(org.springframework.security.rsocket.core.DefaultPayloadExchange) PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 4 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class PayloadSocketAcceptorInterceptorTests method acceptWhenDefaultDataMimeTypeThenDefaulted.

@Test
public void acceptWhenDefaultDataMimeTypeThenDefaulted() {
    this.acceptorInterceptor.setDefaultDataMimeType(MediaType.APPLICATION_JSON);
    PayloadExchange exchange = captureExchange();
    assertThat(exchange.getMetadataMimeType().toString()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
    assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) Test(org.junit.jupiter.api.Test)

Example 5 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class PayloadSocketAcceptorInterceptorTests method applyWhenDefaultMetadataMimeTypeThenDefaulted.

@Test
public void applyWhenDefaultMetadataMimeTypeThenDefaulted() {
    given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
    PayloadExchange exchange = captureExchange();
    assertThat(exchange.getMetadataMimeType().toString()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
    assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) Test(org.junit.jupiter.api.Test)

Aggregations

PayloadExchange (org.springframework.security.rsocket.api.PayloadExchange)11 Test (org.junit.jupiter.api.Test)9 RSocket (io.rsocket.RSocket)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 DefaultPayloadExchange (org.springframework.security.rsocket.core.DefaultPayloadExchange)2 SocketAcceptor (io.rsocket.SocketAcceptor)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 PayloadInterceptorChain (org.springframework.security.rsocket.api.PayloadInterceptorChain)1