|
@@ -17,6 +17,7 @@
|
|
|
package org.springframework.security.authorization.method;
|
|
|
|
|
|
import java.lang.reflect.Array;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.lang.reflect.Modifier;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
@@ -37,10 +38,13 @@ import java.util.TreeSet;
|
|
|
import java.util.function.Supplier;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+import org.aopalliance.aop.Advice;
|
|
|
+import org.aopalliance.intercept.MethodInvocation;
|
|
|
import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import org.springframework.aop.Advisor;
|
|
|
+import org.springframework.aop.Pointcut;
|
|
|
import org.springframework.aop.framework.AopInfrastructureBean;
|
|
|
import org.springframework.aop.framework.ProxyFactory;
|
|
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
|
@@ -168,9 +172,12 @@ public final class AuthorizationAdvisorProxyFactory
|
|
|
return proxied;
|
|
|
}
|
|
|
ProxyFactory factory = new ProxyFactory(target);
|
|
|
+ AuthorizationProxyMethodInterceptor unwrapper = new AuthorizationProxyMethodInterceptor();
|
|
|
+ factory.addAdvisors(unwrapper);
|
|
|
for (Advisor advisor : this.advisors) {
|
|
|
factory.addAdvisors(advisor);
|
|
|
}
|
|
|
+ factory.addInterface(AuthorizationProxy.class);
|
|
|
factory.setOpaque(true);
|
|
|
factory.setProxyTargetClass(!Modifier.isFinal(target.getClass().getModifiers()));
|
|
|
return factory.getProxy();
|
|
@@ -572,4 +579,34 @@ public final class AuthorizationAdvisorProxyFactory
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private static final class AuthorizationProxyMethodInterceptor implements AuthorizationAdvisor {
|
|
|
+
|
|
|
+ private static final Method GET_TARGET_METHOD = ClassUtils.getMethod(AuthorizationProxy.class,
|
|
|
+ "toAuthorizedTarget");
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object invoke(MethodInvocation invocation) throws Throwable {
|
|
|
+ if (invocation.getMethod().equals(GET_TARGET_METHOD)) {
|
|
|
+ return invocation.getThis();
|
|
|
+ }
|
|
|
+ return invocation.proceed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pointcut getPointcut() {
|
|
|
+ return Pointcut.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Advice getAdvice() {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getOrder() {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|