use of org.springframework.security.rsocket.metadata.UsernamePasswordMetadata in project spring-security by spring-projects.
the class RSocketMessageHandlerConnectionITests method routeWhenNotAuthorized.
@Test
public void routeWhenNotAuthorized() {
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("secure.admin.retrieve-mono").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 connectWhenNotAuthorized.
@Test
public void connectWhenNotAuthorized() {
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("evil", "password");
// @formatter:off
this.requester = requester().setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).connectTcp(this.server.address().getHostName(), this.server.address().getPort()).block();
assertThatExceptionOfType(Exception.class).isThrownBy(() -> this.requester.route("retrieve-mono").data("data").retrieveMono(String.class).block()).matches((ex) -> ex instanceof RejectedSetupException || ex.getClass().toString().contains("ReactiveException"));
// @formatter:on
// FIXME: https://github.com/rsocket/rsocket-java/issues/686
}
use of org.springframework.security.rsocket.metadata.UsernamePasswordMetadata in project spring-security by spring-projects.
the class RSocketMessageHandlerConnectionITests method connectWithAnyAuthority.
@Test
public void connectWithAnyAuthority() {
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("admin", "password");
// @formatter:off
this.requester = requester().setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE).connectTcp(this.server.address().getHostName(), this.server.address().getPort()).block();
String hiEbert = this.requester.route("management.users").data("admin").retrieveMono(String.class).block();
// @formatter:on
assertThat(hiEbert).isEqualTo("Hi admin");
}
use of org.springframework.security.rsocket.metadata.UsernamePasswordMetadata in project spring-security by spring-projects.
the class SimpleAuthenticationITests method retrieveMonoWhenAuthorizedThenGranted.
@Test
public void retrieveMonoWhenAuthorizedThenGranted() {
MimeType authenticationMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString());
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("rob", "password");
// @formatter:off
this.requester = RSocketRequester.builder().setupMetadata(credentials, authenticationMimeType).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, authenticationMimeType).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 AuthenticationPayloadInterceptorTests method createRequestPayload.
private Payload createRequestPayload() {
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
BasicAuthenticationEncoder encoder = new BasicAuthenticationEncoder();
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
ResolvableType elementType = ResolvableType.forClass(UsernamePasswordMetadata.class);
MimeType mimeType = UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE;
Map<String, Object> hints = null;
DataBuffer dataBuffer = encoder.encodeValue(credentials, factory, elementType, mimeType, hints);
ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
CompositeByteBuf metadata = allocator.compositeBuffer();
CompositeMetadataCodec.encodeAndAddMetadata(metadata, allocator, mimeType.toString(), NettyDataBufferFactory.toByteBuf(dataBuffer));
return DefaultPayload.create(allocator.buffer(), metadata);
}
Aggregations