zhouhao преди 3 години
родител
ревизия
377c480e9e

+ 11 - 8
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationHolder.java

@@ -51,14 +51,17 @@ public final class AuthenticationHolder {
     private static final ReadWriteLock lock = new ReentrantReadWriteLock();
 
     private static Optional<Authentication> get(Function<AuthenticationSupplier, Optional<Authentication>> function) {
-
-        return Flux.fromStream(suppliers.stream().map(function))
-                .filter(Optional::isPresent)
-                .map(Optional::get)
-                .reduceWith(SimpleAuthentication::new, SimpleAuthentication::merge)
-                .filter(auth->auth.getUser()!=null)
-                .map(Authentication.class::cast)
-                .blockOptional();
+        if (suppliers.size() == 1) {
+            return suppliers.get(0).get();
+        }
+        SimpleAuthentication merge = new SimpleAuthentication();
+        for (AuthenticationSupplier supplier : suppliers) {
+            supplier.get().ifPresent(merge::merge);
+        }
+        if (merge.getUser() == null) {
+            return Optional.empty();
+        }
+        return Optional.of(merge);
     }
 
     /**