@Test public void noClientsResultsInNoProfiles(final TestContext testContext) { final AsyncDirectClientAuthenticator<TestProfile, AsyncWebContext> authenticator = new AsyncDirectClientAuthenticator<>(AsyncProfileSave.SINGLE_PROFILE_SAVE, new AsyncSaveProfileToSessionDecision(true), new AsyncLoadProfileFromSessionDecision()); final AsyncWebContext webContext = webContextBuilder.build(); final Async async = testContext.async(); authenticator.authenticate(new ArrayList<>(), webContext, new AsyncProfileManager<>(webContext)) .thenAccept(profiles -> executionContext.runOnContext(() -> { assertThat(profiles, is(new ArrayList<>())); async.complete(); })); }
public final CompletableFuture<List<U>> authenticate(final List<AsyncClient<? extends Credentials, U>> currentClients, final C context, final AsyncProfileManager<U, C> manager) { final Stream<AsyncClient<? extends Credentials, U>> directClientsStream = currentClients.stream() .filter(c -> !c.isIndirect()); final List<CompletableFuture<Supplier<CompletableFuture<Boolean>>>> saveOperationList = directClientsStream .peek(c -> logger.debug("Performing authentication for direct client: {}", c)) .map(c -> { final CompletableFuture<Optional<U>> profileOptionFuture = perClientAuthenticator.authenticateFor(c, context); return profileOptionFuture.thenApply(profileOption -> { final U profile = profileOption.orElse(null); return (Supplier<CompletableFuture<Boolean>>) () -> saveStrategy.saveProfile(manager, ctx -> saveToSessionDecision.make(context, currentClients, c, profile), profile); }); }).collect(Collectors.toList()); return FutureUtils.combineFuturesToList(saveOperationList) .thenCompose(saveStrategy::combineResults) .thenCompose(b -> b ? manager.getAll(loadFromSessionDecision.make(context, currentClients)) : completedFuture(new LinkedList<>())); }
AsyncDirectClientAuthenticator { public final CompletableFuture<List<U>> authenticate(final List<AsyncClient<? extends Credentials, U>> currentClients, final C context, final AsyncProfileManager<U, C> manager) { final Stream<AsyncClient<? extends Credentials, U>> directClientsStream = currentClients.stream() .filter(c -> !c.isIndirect()); final List<CompletableFuture<Supplier<CompletableFuture<Boolean>>>> saveOperationList = directClientsStream .peek(c -> logger.debug("Performing authentication for direct client: {}", c)) .map(c -> { final CompletableFuture<Optional<U>> profileOptionFuture = perClientAuthenticator.authenticateFor(c, context); return profileOptionFuture.thenApply(profileOption -> { final U profile = profileOption.orElse(null); return (Supplier<CompletableFuture<Boolean>>) () -> saveStrategy.saveProfile(manager, ctx -> saveToSessionDecision.make(context, currentClients, c, profile), profile); }); }).collect(Collectors.toList()); return FutureUtils.combineFuturesToList(saveOperationList) .thenCompose(saveStrategy::combineResults) .thenCompose(b -> b ? manager.getAll(loadFromSessionDecision.make(context, currentClients)) : completedFuture(new LinkedList<>())); } }
AsyncDirectClientAuthenticator { public final CompletableFuture<List<U>> authenticate(final List<AsyncClient<? extends Credentials, U>> currentClients, final C context, final AsyncProfileManager<U, C> manager) { final Stream<AsyncClient<? extends Credentials, U>> directClientsStream = currentClients.stream() .filter(c -> !c.isIndirect()); final List<CompletableFuture<Supplier<CompletableFuture<Boolean>>>> saveOperationList = directClientsStream .peek(c -> logger.debug("Performing authentication for direct client: {}", c)) .map(c -> { final CompletableFuture<Optional<U>> profileOptionFuture = perClientAuthenticator.authenticateFor(c, context); return profileOptionFuture.thenApply(profileOption -> { final U profile = profileOption.orElse(null); return (Supplier<CompletableFuture<Boolean>>) () -> saveStrategy.saveProfile(manager, ctx -> saveToSessionDecision.make(context, currentClients, c, profile), profile); }); }).collect(Collectors.toList()); return FutureUtils.combineFuturesToList(saveOperationList) .thenCompose(saveStrategy::combineResults) .thenCompose(b -> b ? manager.getAll(loadFromSessionDecision.make(context, currentClients)) : completedFuture(new LinkedList<>())); } AsyncDirectClientAuthenticator(final AsyncProfileSaveStrategy saveStrategy, AsyncSaveProfileToSessionDecision saveToSessionDecision, AsyncLoadProfileFromSessionDecision loadFromSessionDecision); }
AsyncDirectClientAuthenticator { public final CompletableFuture<List<U>> authenticate(final List<AsyncClient<? extends Credentials, U>> currentClients, final C context, final AsyncProfileManager<U, C> manager) { final Stream<AsyncClient<? extends Credentials, U>> directClientsStream = currentClients.stream() .filter(c -> !c.isIndirect()); final List<CompletableFuture<Supplier<CompletableFuture<Boolean>>>> saveOperationList = directClientsStream .peek(c -> logger.debug("Performing authentication for direct client: {}", c)) .map(c -> { final CompletableFuture<Optional<U>> profileOptionFuture = perClientAuthenticator.authenticateFor(c, context); return profileOptionFuture.thenApply(profileOption -> { final U profile = profileOption.orElse(null); return (Supplier<CompletableFuture<Boolean>>) () -> saveStrategy.saveProfile(manager, ctx -> saveToSessionDecision.make(context, currentClients, c, profile), profile); }); }).collect(Collectors.toList()); return FutureUtils.combineFuturesToList(saveOperationList) .thenCompose(saveStrategy::combineResults) .thenCompose(b -> b ? manager.getAll(loadFromSessionDecision.make(context, currentClients)) : completedFuture(new LinkedList<>())); } AsyncDirectClientAuthenticator(final AsyncProfileSaveStrategy saveStrategy, AsyncSaveProfileToSessionDecision saveToSessionDecision, AsyncLoadProfileFromSessionDecision loadFromSessionDecision); final CompletableFuture<List<U>> authenticate(final List<AsyncClient<? extends Credentials, U>> currentClients,
                     final C context,
                     final AsyncProfileManager<U, C> manager); }
AsyncDirectClientAuthenticator { public final CompletableFuture<List<U>> authenticate(final List<AsyncClient<? extends Credentials, U>> currentClients, final C context, final AsyncProfileManager<U, C> manager) { final Stream<AsyncClient<? extends Credentials, U>> directClientsStream = currentClients.stream() .filter(c -> !c.isIndirect()); final List<CompletableFuture<Supplier<CompletableFuture<Boolean>>>> saveOperationList = directClientsStream .peek(c -> logger.debug("Performing authentication for direct client: {}", c)) .map(c -> { final CompletableFuture<Optional<U>> profileOptionFuture = perClientAuthenticator.authenticateFor(c, context); return profileOptionFuture.thenApply(profileOption -> { final U profile = profileOption.orElse(null); return (Supplier<CompletableFuture<Boolean>>) () -> saveStrategy.saveProfile(manager, ctx -> saveToSessionDecision.make(context, currentClients, c, profile), profile); }); }).collect(Collectors.toList()); return FutureUtils.combineFuturesToList(saveOperationList) .thenCompose(saveStrategy::combineResults) .thenCompose(b -> b ? manager.getAll(loadFromSessionDecision.make(context, currentClients)) : completedFuture(new LinkedList<>())); } AsyncDirectClientAuthenticator(final AsyncProfileSaveStrategy saveStrategy, AsyncSaveProfileToSessionDecision saveToSessionDecision, AsyncLoadProfileFromSessionDecision loadFromSessionDecision); final CompletableFuture<List<U>> authenticate(final List<AsyncClient<? extends Credentials, U>> currentClients,
                     final C context,
                     final AsyncProfileManager<U, C> manager);  }