add hasAnyRole method in AuthorizePayloadsSpec.Access

This commit is contained in:
Manuel Tejeda 2019-09-18 07:59:20 -05:00
parent 7576dc44d7
commit 9926ad68b8
2 changed files with 24 additions and 0 deletions

View File

@ -104,6 +104,7 @@ import java.util.List;
* }
* </pre>
* @author Rob Winch
* @author Manuel Tejeda
* @since 5.2
*/
public class RSocketSecurity {
@ -315,6 +316,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)));

View File

@ -51,6 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
/**
* @author Rob Winch
* @author Manuel Tejeda
*/
@ContextConfiguration
@RunWith(SpringRunner.class)
@ -167,6 +168,23 @@ public class RSocketMessageHandlerConnectionITests {
// .isInstanceOf(RejectedSetupException.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());
@ -225,6 +243,7 @@ public class RSocketMessageHandlerConnectionITests {
.setup().hasRole("SETUP")
.route("secure.admin.*").hasRole("ADMIN")
.route("secure.**").hasRole("USER")
.route("anyroute").hasAnyRole("USER")
.anyRequest().permitAll()
)
.basicAuthentication(Customizer.withDefaults());