Remove Deprecated AuthorizationDecision Elements
Closes gh-17299 Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
committed by
Josh Cummings
parent
448283b30c
commit
9312fb7004
-15
@@ -51,21 +51,6 @@ public final class PayloadExchangeMatcherReactiveAuthorizationManager
|
||||
this.mappings = mappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #authorize(Mono, PayloadExchange)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, PayloadExchange exchange) {
|
||||
return authorize(authentication, exchange).flatMap((result) -> {
|
||||
if (result instanceof AuthorizationDecision decision) {
|
||||
return Mono.just(decision);
|
||||
}
|
||||
return Mono.error(new IllegalArgumentException(
|
||||
"Please call #authorize or ensure that the returned result is of type Mono<AuthorizationDecision>"));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<AuthorizationResult> authorize(Mono<Authentication> authentication, PayloadExchange exchange) {
|
||||
return Flux.fromIterable(this.mappings)
|
||||
|
||||
+8
-12
@@ -52,51 +52,47 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
@Test
|
||||
public void checkWhenGrantedThenGranted() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(true);
|
||||
given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
|
||||
given(this.authz.authorize(any(), any())).willCallRealMethod();
|
||||
given(this.authz.authorize(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);
|
||||
assertThat(manager.authorize(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWhenDeniedThenDenied() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(false);
|
||||
given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
|
||||
given(this.authz.authorize(any(), any())).willCallRealMethod();
|
||||
given(this.authz.authorize(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);
|
||||
assertThat(manager.authorize(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWhenFirstMatchThenSecondUsed() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(true);
|
||||
given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
|
||||
given(this.authz.authorize(any(), any())).willCallRealMethod();
|
||||
given(this.authz.authorize(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);
|
||||
assertThat(manager.authorize(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWhenSecondMatchThenSecondUsed() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(true);
|
||||
given(this.authz2.check(any(), any())).willReturn(Mono.just(expected));
|
||||
given(this.authz2.authorize(any(), any())).willCallRealMethod();
|
||||
given(this.authz2.authorize(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);
|
||||
assertThat(manager.authorize(Mono.empty(), this.exchange).block()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user