Autoconfigure RSocket Security
Closes gh-18356
This commit is contained in:
@@ -36,6 +36,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-rsocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-rsocket</artifactId>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
spring.rsocket.server.port=0
|
||||
spring.security.user.password=password
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.rsocket.context.LocalRSocketServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.messaging.rsocket.RSocketRequester;
|
||||
import org.springframework.security.rsocket.metadata.BasicAuthenticationEncoder;
|
||||
import org.springframework.security.rsocket.metadata.UsernamePasswordMetadata;
|
||||
|
||||
@SpringBootTest(properties = "spring.rsocket.server.port=0")
|
||||
public class SampleRSocketApplicationTests {
|
||||
@@ -38,9 +40,20 @@ public class SampleRSocketApplicationTests {
|
||||
private RSocketRequester.Builder builder;
|
||||
|
||||
@Test
|
||||
void testRSocketEndpoint() {
|
||||
void unauthenticatedAccessToRSocketEndpoint() {
|
||||
RSocketRequester requester = this.builder.connectTcp("localhost", this.port).block(Duration.ofSeconds(5));
|
||||
Mono<Project> result = requester.route("find.project.spring-boot").retrieveMono(Project.class);
|
||||
StepVerifier.create(result).expectErrorMessage("Access Denied").verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void rSocketEndpoint() {
|
||||
RSocketRequester requester = this.builder
|
||||
.rsocketStrategies((builder) -> builder.encoder(new BasicAuthenticationEncoder()))
|
||||
.setupMetadata(new UsernamePasswordMetadata("user", "password"),
|
||||
UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE)
|
||||
.connectTcp("localhost", this.port).block(Duration.ofSeconds(5));
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user