Merge Add hasAnyAuthority method in AuthorizePayloadsSpec.Access

This commit is contained in:
Rob Winch 2019-09-30 14:33:41 -05:00
commit 3051a79188
2 changed files with 24 additions and 3 deletions

View File

@ -104,12 +104,10 @@ import java.util.List;
* }
* </pre>
* @author Rob Winch
<<<<<<< HEAD
* @author Jesús Ascama Arias
* @author Luis Felipe Vega
=======
* @author Manuel Tejeda
>>>>>>> 9926ad68b8f4e465f6c5243a8ff993fbf9d1b7a2
* @author Ebert Toribio
* @since 5.2
*/
public class RSocketSecurity {
@ -334,6 +332,10 @@ public class RSocketSecurity {
.just(new AuthorizationDecision(true)));
}
public AuthorizePayloadsSpec hasAnyAuthority(String... authorities) {
return access(AuthorityReactiveAuthorizationManager.hasAnyAuthority(authorities));
}
public AuthorizePayloadsSpec access(
ReactiveAuthorizationManager<PayloadExchangeAuthorizationContext> authorization) {
AuthorizePayloadsSpec.this.authzBuilder.add(new PayloadExchangeMatcherEntry<>(this.matcher, authorization));

View File

@ -54,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
* @author Luis Felipe Vega
* @author Jesús Ascama Arias
* @author Manuel Tejeda
* @author Ebert Toribio
*/
@ContextConfiguration
@RunWith(SpringRunner.class)
@ -219,6 +220,23 @@ public class RSocketMessageHandlerConnectionITests {
assertThat(hiRob).isEqualTo("Hi rob");
}
@Test
public void connectWithAnyAuthority() {
UsernamePasswordMetadata credentials =
new UsernamePasswordMetadata("admin", "password");
this.requester = requester()
.setupMetadata(credentials, UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE)
.connectTcp(this.server.address().getHostName(), this.server.address().getPort())
.block();
String hiEbert = this.requester.route("management.users")
.data("admin")
.retrieveMono(String.class)
.block();
assertThat(hiEbert).isEqualTo("Hi admin");
}
private RSocketRequester.Builder requester() {
return RSocketRequester.builder()
.rsocketStrategies(this.handler.getRSocketStrategies());
@ -278,6 +296,7 @@ public class RSocketMessageHandlerConnectionITests {
.route("secure.admin.*").hasRole("ADMIN")
.route("secure.**").hasRole("USER")
.route("secure.authority.*").hasAuthority("ROLE_USER")
.route("management.*").hasAnyAuthority("ROLE_ADMIN")
.route("prohibit").denyAll()
.anyRequest().permitAll()
)