Skip to content

Commit

Permalink
Add Supplier Support
Browse files Browse the repository at this point in the history
Issue gh-14597
  • Loading branch information
jzheaux committed Mar 21, 2024
1 parent 8088f3e commit 7db844d
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.Supplier;
import java.util.stream.Stream;

import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -90,7 +91,7 @@ public final class AuthorizationAdvisorProxyFactory
/**
* The default {@link TargetVisitor}, which will proxy {@link Class} instances as well
* as instances contained in reactive types (if reactor is present), collection types,
* and other container types like {@link Optional}
* and other container types like {@link Optional} and {@link Supplier}
*/
public static final TargetVisitor DEFAULT_VISITOR = isReactivePresent
? new DelegateVisitor(new ClassVisitor(), new ReactiveTypeVisitor(), new ContainerTypeVisitor())
Expand Down Expand Up @@ -328,6 +329,9 @@ public Object visit(AuthorizationAdvisorProxyFactory proxyFactory, Object target
if (target instanceof Optional<?> optional) {
return proxyOptional(proxyFactory, optional);
}
if (target instanceof Supplier<?> supplier) {
return proxySupplier(proxyFactory, supplier);
}
return null;
}

Expand Down Expand Up @@ -460,6 +464,10 @@ private Optional<?> proxyOptional(AuthorizationProxyFactory proxyFactory, Option
return optional.map(proxyFactory::proxy);
}

private Supplier<?> proxySupplier(AuthorizationProxyFactory proxyFactory, Supplier<?> supplier) {
return () -> proxyFactory.proxy(supplier.get());
}

}

private static class ReactiveTypeVisitor implements TargetVisitor {
Expand Down

0 comments on commit 7db844d

Please sign in to comment.