diff --git a/config/src/main/java/org/springframework/security/config/annotation/rsocket/RSocketSecurity.java b/config/src/main/java/org/springframework/security/config/annotation/rsocket/RSocketSecurity.java index 6890412a1b..f63f6478ce 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/rsocket/RSocketSecurity.java +++ b/config/src/main/java/org/springframework/security/config/annotation/rsocket/RSocketSecurity.java @@ -104,8 +104,12 @@ import java.util.List; * } * * @author Rob Winch +<<<<<<< HEAD * @author Jesús Ascama Arias * @author Luis Felipe Vega +======= + * @author Manuel Tejeda +>>>>>>> 9926ad68b8f4e465f6c5243a8ff993fbf9d1b7a2 * @since 5.2 */ public class RSocketSecurity { @@ -321,6 +325,10 @@ public class RSocketSecurity { return access(AuthorityReactiveAuthorizationManager.hasRole(role)); } + public AuthorizePayloadsSpec hasAnyRole(String... roles) { + return access(AuthorityReactiveAuthorizationManager.hasAnyRole(roles)); + } + public AuthorizePayloadsSpec permitAll() { return access((a, ctx) -> Mono .just(new AuthorizationDecision(true))); diff --git a/config/src/test/java/org/springframework/security/config/annotation/rsocket/RSocketMessageHandlerConnectionITests.java b/config/src/test/java/org/springframework/security/config/annotation/rsocket/RSocketMessageHandlerConnectionITests.java index 52af25b6e0..9056a3acda 100644 --- a/config/src/test/java/org/springframework/security/config/annotation/rsocket/RSocketMessageHandlerConnectionITests.java +++ b/config/src/test/java/org/springframework/security/config/annotation/rsocket/RSocketMessageHandlerConnectionITests.java @@ -53,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThatCode; * @author Rob Winch * @author Luis Felipe Vega * @author Jesús Ascama Arias + * @author Manuel Tejeda */ @ContextConfiguration @RunWith(SpringRunner.class) @@ -201,6 +202,23 @@ public class RSocketMessageHandlerConnectionITests { .isInstanceOf(ApplicationErrorException.class); } + @Test + public void connectWithAnyRole() { + UsernamePasswordMetadata credentials = + new UsernamePasswordMetadata("user", "password"); + 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(); + + assertThat(hiRob).isEqualTo("Hi rob"); + } + private RSocketRequester.Builder requester() { return RSocketRequester.builder() .rsocketStrategies(this.handler.getRSocketStrategies());