Search in sources :

Example 11 with UsernamePasswordMetadata

use of org.springframework.security.rsocket.metadata.UsernamePasswordMetadata in project spring-security by spring-projects.

the class RSocketMessageHandlerConnectionITests method routeWhenStreamCredentialsHaveAuthority.

@Test
public void routeWhenStreamCredentialsHaveAuthority() {
    UsernamePasswordMetadata connectCredentials = new UsernamePasswordMetadata("user", "password");
    // @formatter:off
    this.requester = requester().setupMetadata(connectCredentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).connectTcp(this.server.address().getHostName(), this.server.address().getPort()).block();
    String hiUser = this.requester.route("secure.authority.retrieve-mono").metadata(new UsernamePasswordMetadata("admin", "password"), UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).data("Felipe").retrieveMono(String.class).block();
    // @formatter:on
    assertThat(hiUser).isEqualTo("Hi Felipe");
}
Also used : UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) Test(org.junit.jupiter.api.Test)

Example 12 with UsernamePasswordMetadata

use of org.springframework.security.rsocket.metadata.UsernamePasswordMetadata in project spring-security by spring-projects.

the class RSocketMessageHandlerConnectionITests method connectWithAnyRole.

@Test
public void connectWithAnyRole() {
    UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
    // @formatter:off
    this.requester = requester().setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).connectTcp(this.server.address().getHostName(), this.server.address().getPort()).block();
    String hiRob = this.requester.route("anyroute").data("rob").retrieveMono(String.class).block();
    // @formatter:on
    assertThat(hiRob).isEqualTo("Hi rob");
}
Also used : UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) Test(org.junit.jupiter.api.Test)

Example 13 with UsernamePasswordMetadata

use of org.springframework.security.rsocket.metadata.UsernamePasswordMetadata in project spring-security by spring-projects.

the class RSocketMessageHandlerITests method retrieveMonoWhenAuthenticationFailedThenException.

@Test
public void retrieveMonoWhenAuthenticationFailedThenException() throws Exception {
    String data = "rob";
    UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("invalid", "password");
    // @formatter:off
    assertThatExceptionOfType(ApplicationErrorException.class).isThrownBy(() -> this.requester.route("secure.retrieve-mono").metadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).data(data).retrieveMono(String.class).block()).withMessageContaining("Invalid Credentials");
    // @formatter:on
    assertThat(this.controller.payloads).isEmpty();
}
Also used : UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) Test(org.junit.jupiter.api.Test)

Example 14 with UsernamePasswordMetadata

use of org.springframework.security.rsocket.metadata.UsernamePasswordMetadata in project spring-security by spring-projects.

the class RSocketMessageHandlerITests method retrieveMonoWhenAuthorizedThenGranted.

@Test
public void retrieveMonoWhenAuthorizedThenGranted() throws Exception {
    String data = "rob";
    UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("rob", "password");
    // @formatter:off
    String hiRob = this.requester.route("secure.retrieve-mono").metadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).data(data).retrieveMono(String.class).block();
    // @formatter:on
    assertThat(hiRob).isEqualTo("Hi rob");
    assertThat(this.controller.payloads).containsOnly(data);
}
Also used : UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

UsernamePasswordMetadata (org.springframework.security.rsocket.metadata.UsernamePasswordMetadata)14 Test (org.junit.jupiter.api.Test)13 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)3 ApplicationErrorException (io.rsocket.exceptions.ApplicationErrorException)2 MimeType (org.springframework.util.MimeType)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 RejectedSetupException (io.rsocket.exceptions.RejectedSetupException)1 Assertions (org.assertj.core.api.Assertions)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 LocalRSocketServerPort (org.springframework.boot.rsocket.context.LocalRSocketServerPort)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ResolvableType (org.springframework.core.ResolvableType)1 DataBuffer (org.springframework.core.io.buffer.DataBuffer)1 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)1 RSocketRequester (org.springframework.messaging.rsocket.RSocketRequester)1 BasicAuthenticationEncoder (org.springframework.security.rsocket.metadata.BasicAuthenticationEncoder)1 SimpleAuthenticationEncoder (org.springframework.security.rsocket.metadata.SimpleAuthenticationEncoder)1 MimeTypeUtils (org.springframework.util.MimeTypeUtils)1 Mono (reactor.core.publisher.Mono)1