Merge Add hasAnyRole method in AuthorizePayloadsSpec.Access

This commit is contained in:
Rob Winch 2019-09-30 14:14:59 -05:00
commit a911f3d52f
2 changed files with 26 additions and 0 deletions

View File

@ -104,8 +104,12 @@ import java.util.List;
* }
* </pre>
* @author Rob Winch
<<<<<<< HEAD
* @author Jesús Ascama Arias
* @author Luis Felipe Vega
=======
* @author Manuel Tejeda
>>>>>>> 9926ad68b8f4e465f6c5243a8ff993fbf9d1b7a2
* @since 5.2
*/
public class RSocketSecurity {
@ -321,6 +325,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

@ -53,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
* @author Rob Winch
* @author Luis Felipe Vega
* @author Jesús Ascama Arias
* @author Manuel Tejeda
*/
@ContextConfiguration
@RunWith(SpringRunner.class)
@ -201,6 +202,23 @@ public class RSocketMessageHandlerConnectionITests {
.isInstanceOf(ApplicationErrorException.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());