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();
}
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);
}
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
}
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");
}
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");
}
Aggregations