Skip to content

Commit 9926ad6

Browse files
committed
add hasAnyRole method in AuthorizePayloadsSpec.Access
1 parent 7576dc4 commit 9926ad6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

config/src/main/java/org/springframework/security/config/annotation/rsocket/RSocketSecurity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
* }
105105
* </pre>
106106
* @author Rob Winch
107+
* @author Manuel Tejeda
107108
* @since 5.2
108109
*/
109110
public class RSocketSecurity {
@@ -315,6 +316,10 @@ public AuthorizePayloadsSpec hasRole(String role) {
315316
return access(AuthorityReactiveAuthorizationManager.hasRole(role));
316317
}
317318

319+
public AuthorizePayloadsSpec hasAnyRole(String... roles) {
320+
return access(AuthorityReactiveAuthorizationManager.hasAnyRole(roles));
321+
}
322+
318323
public AuthorizePayloadsSpec permitAll() {
319324
return access((a, ctx) -> Mono
320325
.just(new AuthorizationDecision(true)));

config/src/test/java/org/springframework/security/config/annotation/rsocket/RSocketMessageHandlerConnectionITests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
/**
5353
* @author Rob Winch
54+
* @author Manuel Tejeda
5455
*/
5556
@ContextConfiguration
5657
@RunWith(SpringRunner.class)
@@ -167,6 +168,23 @@ public void connectWhenNotAuthorized() {
167168
// .isInstanceOf(RejectedSetupException.class);
168169
}
169170

171+
@Test
172+
public void connectWithAnyRole() {
173+
UsernamePasswordMetadata credentials =
174+
new UsernamePasswordMetadata("user", "password");
175+
this.requester = requester()
176+
.setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE)
177+
.connectTcp(this.server.address().getHostName(), this.server.address().getPort())
178+
.block();
179+
180+
String hiRob = this.requester.route("anyroute")
181+
.data("rob")
182+
.retrieveMono(String.class)
183+
.block();
184+
185+
assertThat(hiRob).isEqualTo("Hi rob");
186+
}
187+
170188
private RSocketRequester.Builder requester() {
171189
return RSocketRequester.builder()
172190
.rsocketStrategies(this.handler.getRSocketStrategies());
@@ -225,6 +243,7 @@ PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
225243
.setup().hasRole("SETUP")
226244
.route("secure.admin.*").hasRole("ADMIN")
227245
.route("secure.**").hasRole("USER")
246+
.route("anyroute").hasAnyRole("USER")
228247
.anyRequest().permitAll()
229248
)
230249
.basicAuthentication(Customizer.withDefaults());

0 commit comments

Comments
 (0)