Skip to content

Commit daf6b53

Browse files
jascamaeddumelendez
andcommitted
Add denyAll method in AuthorizePayloadsSpec.Access
See gh-7437 Co-authored-by: Eddú Meléndez <eddu.melendez@gmail.com>
1 parent 338b637 commit daf6b53

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
* }
105105
* </pre>
106106
* @author Rob Winch
107+
* @author Jesús Ascama Arias
107108
* @since 5.2
108109
*/
109110
public class RSocketSecurity {
@@ -325,6 +326,11 @@ public AuthorizePayloadsSpec access(
325326
AuthorizePayloadsSpec.this.authzBuilder.add(new PayloadExchangeMatcherEntry<>(this.matcher, authorization));
326327
return AuthorizePayloadsSpec.this;
327328
}
329+
330+
public AuthorizePayloadsSpec denyAll() {
331+
return access((a, ctx) -> Mono
332+
.just(new AuthorizationDecision(false)));
333+
}
328334
}
329335
}
330336

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
@@ -51,6 +51,7 @@
5151

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

171+
@Test
172+
public void connectionDenied() {
173+
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
174+
this.requester = requester()
175+
.setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE)
176+
.connectTcp(this.server.address().getHostName(), this.server.address().getPort())
177+
.block();
178+
179+
assertThatCode(() -> this.requester.route("prohibit")
180+
.data("data")
181+
.retrieveMono(String.class)
182+
.block())
183+
.isInstanceOf(ApplicationErrorException.class);
184+
}
185+
170186
private RSocketRequester.Builder requester() {
171187
return RSocketRequester.builder()
172188
.rsocketStrategies(this.handler.getRSocketStrategies());
@@ -225,6 +241,7 @@ PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
225241
.setup().hasRole("SETUP")
226242
.route("secure.admin.*").hasRole("ADMIN")
227243
.route("secure.**").hasRole("USER")
244+
.route("prohibit").denyAll()
228245
.anyRequest().permitAll()
229246
)
230247
.basicAuthentication(Customizer.withDefaults());

0 commit comments

Comments
 (0)