|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2021 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2023 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -19,9 +19,7 @@ package org.springframework.security.access.prepost;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
|
|
|
-import kotlin.coroutines.Continuation;
|
|
|
|
import kotlinx.coroutines.reactive.ReactiveFlowKt;
|
|
import kotlinx.coroutines.reactive.ReactiveFlowKt;
|
|
-import kotlinx.coroutines.reactor.MonoKt;
|
|
|
|
import org.aopalliance.intercept.MethodInterceptor;
|
|
import org.aopalliance.intercept.MethodInterceptor;
|
|
import org.aopalliance.intercept.MethodInvocation;
|
|
import org.aopalliance.intercept.MethodInvocation;
|
|
import org.reactivestreams.Publisher;
|
|
import org.reactivestreams.Publisher;
|
|
@@ -29,7 +27,6 @@ import reactor.core.Exceptions;
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
-import org.springframework.core.CoroutinesUtils;
|
|
|
|
import org.springframework.core.KotlinDetector;
|
|
import org.springframework.core.KotlinDetector;
|
|
import org.springframework.core.MethodParameter;
|
|
import org.springframework.core.MethodParameter;
|
|
import org.springframework.core.ReactiveAdapter;
|
|
import org.springframework.core.ReactiveAdapter;
|
|
@@ -126,34 +123,23 @@ public class PrePostAdviceReactiveMethodInterceptor implements MethodInterceptor
|
|
.map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
.map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
}
|
|
}
|
|
if (hasFlowReturnType) {
|
|
if (hasFlowReturnType) {
|
|
- Flux<?> response;
|
|
|
|
if (isSuspendingFunction) {
|
|
if (isSuspendingFunction) {
|
|
- response = toInvoke.flatMapMany((auth) -> Flux
|
|
|
|
- .from(CoroutinesUtils.invokeSuspendingFunction(invocation.getMethod(), invocation.getThis(),
|
|
|
|
- invocation.getArguments()))
|
|
|
|
- .map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
|
|
|
|
+ return toInvoke
|
|
|
|
+ .flatMapMany((auth) -> Flux.from(PrePostAdviceReactiveMethodInterceptor.proceed(invocation))
|
|
|
|
+ .map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(returnType);
|
|
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(returnType);
|
|
Assert.state(adapter != null, () -> "The returnType " + returnType + " on " + method
|
|
Assert.state(adapter != null, () -> "The returnType " + returnType + " on " + method
|
|
+ " must have a org.springframework.core.ReactiveAdapter registered");
|
|
+ " must have a org.springframework.core.ReactiveAdapter registered");
|
|
- response = toInvoke.flatMapMany((auth) -> Flux
|
|
|
|
|
|
+ Flux<?> response = toInvoke.flatMapMany((auth) -> Flux
|
|
.from(adapter.toPublisher(PrePostAdviceReactiveMethodInterceptor.flowProceed(invocation)))
|
|
.from(adapter.toPublisher(PrePostAdviceReactiveMethodInterceptor.flowProceed(invocation)))
|
|
.map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
.map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
|
|
+ return KotlinDelegate.asFlow(response);
|
|
}
|
|
}
|
|
- return KotlinDelegate.asFlow(response);
|
|
|
|
- }
|
|
|
|
- if (isSuspendingFunction) {
|
|
|
|
- Mono<?> response = toInvoke.flatMap((auth) -> Mono
|
|
|
|
- .from(CoroutinesUtils.invokeSuspendingFunction(invocation.getMethod(), invocation.getThis(),
|
|
|
|
- invocation.getArguments()))
|
|
|
|
- .map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
|
|
- return KotlinDelegate.awaitSingleOrNull(response,
|
|
|
|
- invocation.getArguments()[invocation.getArguments().length - 1]);
|
|
|
|
}
|
|
}
|
|
- return toInvoke.flatMapMany(
|
|
|
|
- (auth) -> Flux.from(PrePostAdviceReactiveMethodInterceptor.<Publisher<?>>proceed(invocation))
|
|
|
|
- .map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
|
|
|
|
+ return toInvoke.flatMap((auth) -> Mono.from(PrePostAdviceReactiveMethodInterceptor.proceed(invocation))
|
|
|
|
+ .map((r) -> (attr != null) ? this.postAdvice.after(auth, invocation, attr, r) : r));
|
|
}
|
|
}
|
|
|
|
|
|
private static <T extends Publisher<?>> T proceed(final MethodInvocation invocation) {
|
|
private static <T extends Publisher<?>> T proceed(final MethodInvocation invocation) {
|
|
@@ -201,10 +187,6 @@ public class PrePostAdviceReactiveMethodInterceptor implements MethodInterceptor
|
|
return ReactiveFlowKt.asFlow(publisher);
|
|
return ReactiveFlowKt.asFlow(publisher);
|
|
}
|
|
}
|
|
|
|
|
|
- private static Object awaitSingleOrNull(Mono<?> publisher, Object continuation) {
|
|
|
|
- return MonoKt.awaitSingleOrNull(publisher, (Continuation<Object>) continuation);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|