Search in sources :

Example 6 with UsernamePasswordMetadata

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

the class SampleRSocketApplicationTests method rSocketEndpoint.

@Test
void rSocketEndpoint() {
    RSocketRequester requester = this.builder.rsocketStrategies((builder) -> builder.encoder(new SimpleAuthenticationEncoder())).setupMetadata(new UsernamePasswordMetadata("user", "password"), MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString())).tcp("localhost", this.port);
    Mono<Project> result = requester.route("find.project.spring-boot").retrieveMono(Project.class);
    StepVerifier.create(result).assertNext((project) -> Assertions.assertThat(project.getName()).isEqualTo("spring-boot")).verifyComplete();
}
Also used : Test(org.junit.jupiter.api.Test) RSocketRequester(org.springframework.messaging.rsocket.RSocketRequester) UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) StepVerifier(reactor.test.StepVerifier) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SimpleAuthenticationEncoder(org.springframework.security.rsocket.metadata.SimpleAuthenticationEncoder) Assertions(org.assertj.core.api.Assertions) Autowired(org.springframework.beans.factory.annotation.Autowired) Mono(reactor.core.publisher.Mono) LocalRSocketServerPort(org.springframework.boot.rsocket.context.LocalRSocketServerPort) MimeTypeUtils(org.springframework.util.MimeTypeUtils) UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) RSocketRequester(org.springframework.messaging.rsocket.RSocketRequester) SimpleAuthenticationEncoder(org.springframework.security.rsocket.metadata.SimpleAuthenticationEncoder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with UsernamePasswordMetadata

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

the class HelloRSocketITests method retrieveMonoWhenAuthorizedThenGranted.

@Test
public void retrieveMonoWhenAuthorizedThenGranted() throws Exception {
    UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("rob", "password");
    // @formatter:off
    this.requester = RSocketRequester.builder().setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).rsocketStrategies(this.handler.getRSocketStrategies()).connectTcp("localhost", this.server.address().getPort()).block();
    // @formatter:on
    String data = "rob";
    // @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)

Example 8 with UsernamePasswordMetadata

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

the class RSocketMessageHandlerConnectionITests method connectionDenied.

@Test
public void connectionDenied() {
    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();
    assertThatExceptionOfType(ApplicationErrorException.class).isThrownBy(() -> this.requester.route("prohibit").data("data").retrieveMono(String.class).block());
// @formatter:on
}
Also used : UsernamePasswordMetadata(org.springframework.security.rsocket.metadata.UsernamePasswordMetadata) ApplicationErrorException(io.rsocket.exceptions.ApplicationErrorException) Test(org.junit.jupiter.api.Test)

Example 9 with UsernamePasswordMetadata

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

the class RSocketMessageHandlerConnectionITests method routeWhenStreamCredentialsAuthorized.

@Test
public void routeWhenStreamCredentialsAuthorized() {
    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 hiRob = this.requester.route("secure.admin.retrieve-mono").metadata(new UsernamePasswordMetadata("admin", "password"), UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).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 10 with UsernamePasswordMetadata

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

the class RSocketMessageHandlerConnectionITests method routeWhenAuthorized.

@Test
public void routeWhenAuthorized() {
    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("secure.retrieve-mono").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)

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