Skip to content

Commit 3051a79

Browse files
committed
Merge Add hasAnyAuthority method in AuthorizePayloadsSpec.Access
2 parents a911f3d + 3a66191 commit 3051a79

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@
104104
* }
105105
* </pre>
106106
* @author Rob Winch
107-
<<<<<<< HEAD
108107
* @author Jesús Ascama Arias
109108
* @author Luis Felipe Vega
110-
=======
111109
* @author Manuel Tejeda
112-
>>>>>>> 9926ad68b8f4e465f6c5243a8ff993fbf9d1b7a2
110+
* @author Ebert Toribio
113111
* @since 5.2
114112
*/
115113
public class RSocketSecurity {
@@ -334,6 +332,10 @@ public AuthorizePayloadsSpec permitAll() {
334332
.just(new AuthorizationDecision(true)));
335333
}
336334

335+
public AuthorizePayloadsSpec hasAnyAuthority(String... authorities) {
336+
return access(AuthorityReactiveAuthorizationManager.hasAnyAuthority(authorities));
337+
}
338+
337339
public AuthorizePayloadsSpec access(
338340
ReactiveAuthorizationManager<PayloadExchangeAuthorizationContext> authorization) {
339341
AuthorizePayloadsSpec.this.authzBuilder.add(new PayloadExchangeMatcherEntry<>(this.matcher, authorization));

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
@@ -54,6 +54,7 @@
5454
* @author Luis Felipe Vega
5555
* @author Jesús Ascama Arias
5656
* @author Manuel Tejeda
57+
* @author Ebert Toribio
5758
*/
5859
@ContextConfiguration
5960
@RunWith(SpringRunner.class)
@@ -219,6 +220,23 @@ public void connectWithAnyRole() {
219220
assertThat(hiRob).isEqualTo("Hi rob");
220221
}
221222

223+
@Test
224+
public void connectWithAnyAuthority() {
225+
UsernamePasswordMetadata credentials =
226+
new UsernamePasswordMetadata("admin", "password");
227+
this.requester = requester()
228+
.setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE)
229+
.connectTcp(this.server.address().getHostName(), this.server.address().getPort())
230+
.block();
231+
232+
String hiEbert = this.requester.route("management.users")
233+
.data("admin")
234+
.retrieveMono(String.class)
235+
.block();
236+
237+
assertThat(hiEbert).isEqualTo("Hi admin");
238+
}
239+
222240
private RSocketRequester.Builder requester() {
223241
return RSocketRequester.builder()
224242
.rsocketStrategies(this.handler.getRSocketStrategies());
@@ -278,6 +296,7 @@ PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
278296
.route("secure.admin.*").hasRole("ADMIN")
279297
.route("secure.**").hasRole("USER")
280298
.route("secure.authority.*").hasAuthority("ROLE_USER")
299+
.route("management.*").hasAnyAuthority("ROLE_ADMIN")
281300
.route("prohibit").denyAll()
282301
.anyRequest().permitAll()
283302
)

0 commit comments

Comments
 (0)