mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-05 18:22:26 +00:00
add hasAnyRole method in AuthorizePayloadsSpec.Access
This commit is contained in:
parent
7576dc44d7
commit
9926ad68b8
@ -104,6 +104,7 @@ import java.util.List;
|
|||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
* @author Manuel Tejeda
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
public class RSocketSecurity {
|
public class RSocketSecurity {
|
||||||
@ -315,6 +316,10 @@ public class RSocketSecurity {
|
|||||||
return access(AuthorityReactiveAuthorizationManager.hasRole(role));
|
return access(AuthorityReactiveAuthorizationManager.hasRole(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthorizePayloadsSpec hasAnyRole(String... roles) {
|
||||||
|
return access(AuthorityReactiveAuthorizationManager.hasAnyRole(roles));
|
||||||
|
}
|
||||||
|
|
||||||
public AuthorizePayloadsSpec permitAll() {
|
public AuthorizePayloadsSpec permitAll() {
|
||||||
return access((a, ctx) -> Mono
|
return access((a, ctx) -> Mono
|
||||||
.just(new AuthorizationDecision(true)));
|
.just(new AuthorizationDecision(true)));
|
||||||
|
@ -51,6 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
* @author Manuel Tejeda
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@ -167,6 +168,23 @@ public class RSocketMessageHandlerConnectionITests {
|
|||||||
// .isInstanceOf(RejectedSetupException.class);
|
// .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() {
|
private RSocketRequester.Builder requester() {
|
||||||
return RSocketRequester.builder()
|
return RSocketRequester.builder()
|
||||||
.rsocketStrategies(this.handler.getRSocketStrategies());
|
.rsocketStrategies(this.handler.getRSocketStrategies());
|
||||||
@ -225,6 +243,7 @@ public class RSocketMessageHandlerConnectionITests {
|
|||||||
.setup().hasRole("SETUP")
|
.setup().hasRole("SETUP")
|
||||||
.route("secure.admin.*").hasRole("ADMIN")
|
.route("secure.admin.*").hasRole("ADMIN")
|
||||||
.route("secure.**").hasRole("USER")
|
.route("secure.**").hasRole("USER")
|
||||||
|
.route("anyroute").hasAnyRole("USER")
|
||||||
.anyRequest().permitAll()
|
.anyRequest().permitAll()
|
||||||
)
|
)
|
||||||
.basicAuthentication(Customizer.withDefaults());
|
.basicAuthentication(Customizer.withDefaults());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user