Merge Add denyAll method in AuthorizePayloadsSpec.Access

This commit is contained in:
Rob Winch 2019-09-30 14:05:32 -05:00
commit 3854afad61
2 changed files with 22 additions and 0 deletions

View File

@ -331,6 +331,11 @@ public class RSocketSecurity {
AuthorizePayloadsSpec.this.authzBuilder.add(new PayloadExchangeMatcherEntry<>(this.matcher, authorization)); AuthorizePayloadsSpec.this.authzBuilder.add(new PayloadExchangeMatcherEntry<>(this.matcher, authorization));
return AuthorizePayloadsSpec.this; return AuthorizePayloadsSpec.this;
} }
public AuthorizePayloadsSpec denyAll() {
return access((a, ctx) -> Mono
.just(new AuthorizationDecision(false)));
}
} }
} }

View File

@ -52,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
/** /**
* @author Rob Winch * @author Rob Winch
* @author Luis Felipe Vega * @author Luis Felipe Vega
* @author Jesús Ascama Arias
*/ */
@ContextConfiguration @ContextConfiguration
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ -185,6 +186,21 @@ public class RSocketMessageHandlerConnectionITests {
// .isInstanceOf(RejectedSetupException.class); // .isInstanceOf(RejectedSetupException.class);
} }
@Test
public void connectionDenied() {
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();
assertThatCode(() -> this.requester.route("prohibit")
.data("data")
.retrieveMono(String.class)
.block())
.isInstanceOf(ApplicationErrorException.class);
}
private RSocketRequester.Builder requester() { private RSocketRequester.Builder requester() {
return RSocketRequester.builder() return RSocketRequester.builder()
.rsocketStrategies(this.handler.getRSocketStrategies()); .rsocketStrategies(this.handler.getRSocketStrategies());
@ -244,6 +260,7 @@ public class RSocketMessageHandlerConnectionITests {
.route("secure.admin.*").hasRole("ADMIN") .route("secure.admin.*").hasRole("ADMIN")
.route("secure.**").hasRole("USER") .route("secure.**").hasRole("USER")
.route("secure.authority.*").hasAuthority("ROLE_USER") .route("secure.authority.*").hasAuthority("ROLE_USER")
.route("prohibit").denyAll()
.anyRequest().permitAll() .anyRequest().permitAll()
) )
.basicAuthentication(Customizer.withDefaults()); .basicAuthentication(Customizer.withDefaults());