add hasAnyRole method in AuthorizePayloadsSpec.Access
This commit is contained in:
parent
7576dc44d7
commit
9926ad68b8
|
@ -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)));
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue