Search in sources :

Example 1 with PayloadExchangeMatcherEntry

use of org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry in project spring-security by spring-projects.

the class PayloadExchangeMatcherReactiveAuthorizationManagerTests method checkWhenGrantedThenGranted.

@Test
public void checkWhenGrantedThenGranted() {
    AuthorizationDecision expected = new AuthorizationDecision(true);
    given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
    PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz)).build();
    assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
}
Also used : AuthorizationDecision(org.springframework.security.authorization.AuthorizationDecision) PayloadExchangeMatcherEntry(org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry) Test(org.junit.jupiter.api.Test)

Example 2 with PayloadExchangeMatcherEntry

use of org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry in project spring-security by spring-projects.

the class PayloadExchangeMatcherReactiveAuthorizationManagerTests method checkWhenDeniedThenDenied.

@Test
public void checkWhenDeniedThenDenied() {
    AuthorizationDecision expected = new AuthorizationDecision(false);
    given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
    PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz)).build();
    assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
}
Also used : AuthorizationDecision(org.springframework.security.authorization.AuthorizationDecision) PayloadExchangeMatcherEntry(org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry) Test(org.junit.jupiter.api.Test)

Example 3 with PayloadExchangeMatcherEntry

use of org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry in project spring-security by spring-projects.

the class PayloadExchangeMatcherReactiveAuthorizationManagerTests method checkWhenFirstMatchThenSecondUsed.

@Test
public void checkWhenFirstMatchThenSecondUsed() {
    AuthorizationDecision expected = new AuthorizationDecision(true);
    given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
    PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz)).add(new PayloadExchangeMatcherEntry<>((e) -> PayloadExchangeMatcher.MatchResult.notMatch(), this.authz2)).build();
    assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
}
Also used : AuthorizationDecision(org.springframework.security.authorization.AuthorizationDecision) PayloadExchangeMatcherEntry(org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry) Test(org.junit.jupiter.api.Test)

Example 4 with PayloadExchangeMatcherEntry

use of org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry in project spring-security by spring-projects.

the class PayloadExchangeMatcherReactiveAuthorizationManagerTests method checkWhenSecondMatchThenSecondUsed.

@Test
public void checkWhenSecondMatchThenSecondUsed() {
    AuthorizationDecision expected = new AuthorizationDecision(true);
    given(this.authz2.check(any(), any())).willReturn(Mono.just(expected));
    PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager.builder().add(new PayloadExchangeMatcherEntry<>((e) -> PayloadExchangeMatcher.MatchResult.notMatch(), this.authz)).add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz2)).build();
    assertThat(manager.check(Mono.empty(), this.exchange).block()).isEqualTo(expected);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) PayloadExchangeMatchers(org.springframework.security.rsocket.util.matcher.PayloadExchangeMatchers) PayloadExchangeAuthorizationContext(org.springframework.security.rsocket.util.matcher.PayloadExchangeAuthorizationContext) AuthorizationDecision(org.springframework.security.authorization.AuthorizationDecision) Test(org.junit.jupiter.api.Test) PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ReactiveAuthorizationManager(org.springframework.security.authorization.ReactiveAuthorizationManager) BDDMockito.given(org.mockito.BDDMockito.given) PayloadExchangeMatcher(org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcher) PayloadExchangeMatcherEntry(org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry) AuthorizationDecision(org.springframework.security.authorization.AuthorizationDecision) PayloadExchangeMatcherEntry(org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 AuthorizationDecision (org.springframework.security.authorization.AuthorizationDecision)4 PayloadExchangeMatcherEntry (org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 BDDMockito.given (org.mockito.BDDMockito.given)1 Mock (org.mockito.Mock)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1 ReactiveAuthorizationManager (org.springframework.security.authorization.ReactiveAuthorizationManager)1 PayloadExchange (org.springframework.security.rsocket.api.PayloadExchange)1 PayloadExchangeAuthorizationContext (org.springframework.security.rsocket.util.matcher.PayloadExchangeAuthorizationContext)1 PayloadExchangeMatcher (org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcher)1 PayloadExchangeMatchers (org.springframework.security.rsocket.util.matcher.PayloadExchangeMatchers)1 Mono (reactor.core.publisher.Mono)1