Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
* }
* </pre>
* @author Rob Winch
* @author Ebert Toribio
* @since 5.2
*/
public class RSocketSecurity {
Expand Down Expand Up @@ -320,6 +321,10 @@ public AuthorizePayloadsSpec permitAll() {
.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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

/**
* @author Rob Winch
* @author Ebert Toribio
*/
@ContextConfiguration
@RunWith(SpringRunner.class)
Expand Down Expand Up @@ -167,6 +168,23 @@ public void connectWhenNotAuthorized() {
// .isInstanceOf(RejectedSetupException.class);
}

@Test
public void connectWithAnyAuthority() {
UsernamePasswordMetadata credentials =
new UsernamePasswordMetadata("ebert", "ebert");
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("ebert")
.retrieveMono(String.class)
.block();

assertThat(hiEbert).isEqualTo("Hi ebert");
}

private RSocketRequester.Builder requester() {
return RSocketRequester.builder()
.rsocketStrategies(this.handler.getRSocketStrategies());
Expand Down Expand Up @@ -208,13 +226,18 @@ MapReactiveUserDetailsService uds() {
.password("password")
.roles("USER", "SETUP")
.build();
UserDetails manager = User.withDefaultPasswordEncoder()
.username("ebert")
.password("ebert")
.roles("SETUP", "MANAGER")
.build();

UserDetails evil = User.withDefaultPasswordEncoder()
.username("evil")
.password("password")
.roles("EVIL")
.build();
return new MapReactiveUserDetailsService(admin, user, evil);
return new MapReactiveUserDetailsService(admin, user, manager, evil);
}

@Bean
Expand All @@ -225,6 +248,7 @@ PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
.setup().hasRole("SETUP")
.route("secure.admin.*").hasRole("ADMIN")
.route("secure.**").hasRole("USER")
.route("management.*").hasAnyAuthority("ROLE_MANAGER")
.anyRequest().permitAll()
)
.basicAuthentication(Customizer.withDefaults());
Expand Down