Skip to content

Commit 3854afa

Browse files
committed
Merge Add denyAll method in AuthorizePayloadsSpec.Access
2 parents 03e2efa + daf6b53 commit 3854afa

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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
@@ -331,6 +331,11 @@ public AuthorizePayloadsSpec access(
331331
AuthorizePayloadsSpec.this.authzBuilder.add(new PayloadExchangeMatcherEntry<>(this.matcher, authorization));
332332
return AuthorizePayloadsSpec.this;
333333
}
334+
335+
public AuthorizePayloadsSpec denyAll() {
336+
return access((a, ctx) -> Mono
337+
.just(new AuthorizationDecision(false)));
338+
}
334339
}
335340
}
336341

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
/**
5353
* @author Rob Winch
5454
* @author Luis Felipe Vega
55+
* @author Jesús Ascama Arias
5556
*/
5657
@ContextConfiguration
5758
@RunWith(SpringRunner.class)
@@ -185,6 +186,21 @@ public void connectWhenNotAuthorized() {
185186
// .isInstanceOf(RejectedSetupException.class);
186187
}
187188

189+
@Test
190+
public void connectionDenied() {
191+
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
192+
this.requester = requester()
193+
.setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE)
194+
.connectTcp(this.server.address().getHostName(), this.server.address().getPort())
195+
.block();
196+
197+
assertThatCode(() -> this.requester.route("prohibit")
198+
.data("data")
199+
.retrieveMono(String.class)
200+
.block())
201+
.isInstanceOf(ApplicationErrorException.class);
202+
}
203+
188204
private RSocketRequester.Builder requester() {
189205
return RSocketRequester.builder()
190206
.rsocketStrategies(this.handler.getRSocketStrategies());
@@ -244,6 +260,7 @@ PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
244260
.route("secure.admin.*").hasRole("ADMIN")
245261
.route("secure.**").hasRole("USER")
246262
.route("secure.authority.*").hasAuthority("ROLE_USER")
263+
.route("prohibit").denyAll()
247264
.anyRequest().permitAll()
248265
)
249266
.basicAuthentication(Customizer.withDefaults());

0 commit comments

Comments
 (0)