@Test public void testBlankDefaultUrl() { final Clients<AsyncClient<? extends Credentials, ? extends TestProfile>, AsyncAuthorizationGenerator<TestProfile>> clients = clientsWithOneIndirectClient(); when(config.getClients()).thenReturn(clients); exception.expect(TechnicalException.class); exception.expectMessage("defaultUrl cannot be blank"); asyncCallbackLogic = new DefaultAsyncCallbackLogic<>(false, false, config, httpActionAdapter); asyncCallbackLogic.perform(webContext, ""); }
public CompletableFuture<R> perform(final WC context, final String inputDefaultUrl) { logger.debug("=== CALLBACK ==="); final String defaultUrl = Optional.ofNullable(inputDefaultUrl).orElse(Pac4jConstants.DEFAULT_URL_VALUE); assertNotNull("context", context); assertNotBlank(Pac4jConstants.DEFAULT_URL, defaultUrl); final Clients<AsyncClient<? extends Credentials, ? extends U>, AsyncAuthorizationGenerator<U>> clients = config.getClients(); final AsyncClient<? extends Credentials, ? extends U> client = clients.findClient(context); logger.debug("client: {}", client); assertNotNull("client", client); assertTrue(client.isIndirect(), "only indirect clients are allowed on the callback url"); final CompletableFuture<Void> sessionRenewalFuture = perClientAuthenticator.authenticateFor(client, context) .thenCompose(profileOption -> saveStrategy.saveProfile(getProfileManager(context, config), p -> true, profileOption.orElse(null))) .thenCompose(b -> { if (b) { return sessionRenewalStrategy.renewSession(context, config); } else { return CompletableFuture.completedFuture(null); } }); final CompletableFuture<HttpAction> actionFuture = sessionRenewalFuture.thenCompose(v -> indirectAuthenticationFlow.redirectToOriginallyRequestedUrl(context, defaultUrl)); return actionFuture.handle(ExceptionSoftener.softenBiFunction(AsyncExceptionHandler::extractAsyncHttpAction)) .handle(AsyncExceptionHandler::wrapUnexpectedException) .thenApply(a -> httpActionAdapter.adapt(a.getCode(), context)); }
DefaultAsyncCallbackLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncCallbackLogic<R, U, WC> { public CompletableFuture<R> perform(final WC context, final String inputDefaultUrl) { logger.debug("=== CALLBACK ==="); final String defaultUrl = Optional.ofNullable(inputDefaultUrl).orElse(Pac4jConstants.DEFAULT_URL_VALUE); assertNotNull("context", context); assertNotBlank(Pac4jConstants.DEFAULT_URL, defaultUrl); final Clients<AsyncClient<? extends Credentials, ? extends U>, AsyncAuthorizationGenerator<U>> clients = config.getClients(); final AsyncClient<? extends Credentials, ? extends U> client = clients.findClient(context); logger.debug("client: {}", client); assertNotNull("client", client); assertTrue(client.isIndirect(), "only indirect clients are allowed on the callback url"); final CompletableFuture<Void> sessionRenewalFuture = perClientAuthenticator.authenticateFor(client, context) .thenCompose(profileOption -> saveStrategy.saveProfile(getProfileManager(context, config), p -> true, profileOption.orElse(null))) .thenCompose(b -> { if (b) { return sessionRenewalStrategy.renewSession(context, config); } else { return CompletableFuture.completedFuture(null); } }); final CompletableFuture<HttpAction> actionFuture = sessionRenewalFuture.thenCompose(v -> indirectAuthenticationFlow.redirectToOriginallyRequestedUrl(context, defaultUrl)); return actionFuture.handle(ExceptionSoftener.softenBiFunction(AsyncExceptionHandler::extractAsyncHttpAction)) .handle(AsyncExceptionHandler::wrapUnexpectedException) .thenApply(a -> httpActionAdapter.adapt(a.getCode(), context)); } }
DefaultAsyncCallbackLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncCallbackLogic<R, U, WC> { public CompletableFuture<R> perform(final WC context, final String inputDefaultUrl) { logger.debug("=== CALLBACK ==="); final String defaultUrl = Optional.ofNullable(inputDefaultUrl).orElse(Pac4jConstants.DEFAULT_URL_VALUE); assertNotNull("context", context); assertNotBlank(Pac4jConstants.DEFAULT_URL, defaultUrl); final Clients<AsyncClient<? extends Credentials, ? extends U>, AsyncAuthorizationGenerator<U>> clients = config.getClients(); final AsyncClient<? extends Credentials, ? extends U> client = clients.findClient(context); logger.debug("client: {}", client); assertNotNull("client", client); assertTrue(client.isIndirect(), "only indirect clients are allowed on the callback url"); final CompletableFuture<Void> sessionRenewalFuture = perClientAuthenticator.authenticateFor(client, context) .thenCompose(profileOption -> saveStrategy.saveProfile(getProfileManager(context, config), p -> true, profileOption.orElse(null))) .thenCompose(b -> { if (b) { return sessionRenewalStrategy.renewSession(context, config); } else { return CompletableFuture.completedFuture(null); } }); final CompletableFuture<HttpAction> actionFuture = sessionRenewalFuture.thenCompose(v -> indirectAuthenticationFlow.redirectToOriginallyRequestedUrl(context, defaultUrl)); return actionFuture.handle(ExceptionSoftener.softenBiFunction(AsyncExceptionHandler::extractAsyncHttpAction)) .handle(AsyncExceptionHandler::wrapUnexpectedException) .thenApply(a -> httpActionAdapter.adapt(a.getCode(), context)); } DefaultAsyncCallbackLogic(final boolean multiProfile,
                                     final boolean renewSession,
                                     final AsyncConfig<R, U, WC> config,
                                     final HttpActionAdapter<R, WC> httpActionAdapter); }
DefaultAsyncCallbackLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncCallbackLogic<R, U, WC> { public CompletableFuture<R> perform(final WC context, final String inputDefaultUrl) { logger.debug("=== CALLBACK ==="); final String defaultUrl = Optional.ofNullable(inputDefaultUrl).orElse(Pac4jConstants.DEFAULT_URL_VALUE); assertNotNull("context", context); assertNotBlank(Pac4jConstants.DEFAULT_URL, defaultUrl); final Clients<AsyncClient<? extends Credentials, ? extends U>, AsyncAuthorizationGenerator<U>> clients = config.getClients(); final AsyncClient<? extends Credentials, ? extends U> client = clients.findClient(context); logger.debug("client: {}", client); assertNotNull("client", client); assertTrue(client.isIndirect(), "only indirect clients are allowed on the callback url"); final CompletableFuture<Void> sessionRenewalFuture = perClientAuthenticator.authenticateFor(client, context) .thenCompose(profileOption -> saveStrategy.saveProfile(getProfileManager(context, config), p -> true, profileOption.orElse(null))) .thenCompose(b -> { if (b) { return sessionRenewalStrategy.renewSession(context, config); } else { return CompletableFuture.completedFuture(null); } }); final CompletableFuture<HttpAction> actionFuture = sessionRenewalFuture.thenCompose(v -> indirectAuthenticationFlow.redirectToOriginallyRequestedUrl(context, defaultUrl)); return actionFuture.handle(ExceptionSoftener.softenBiFunction(AsyncExceptionHandler::extractAsyncHttpAction)) .handle(AsyncExceptionHandler::wrapUnexpectedException) .thenApply(a -> httpActionAdapter.adapt(a.getCode(), context)); } DefaultAsyncCallbackLogic(final boolean multiProfile,
                                     final boolean renewSession,
                                     final AsyncConfig<R, U, WC> config,
                                     final HttpActionAdapter<R, WC> httpActionAdapter); CompletableFuture<R> perform(final WC context,
                                        final String inputDefaultUrl); }
DefaultAsyncCallbackLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncCallbackLogic<R, U, WC> { public CompletableFuture<R> perform(final WC context, final String inputDefaultUrl) { logger.debug("=== CALLBACK ==="); final String defaultUrl = Optional.ofNullable(inputDefaultUrl).orElse(Pac4jConstants.DEFAULT_URL_VALUE); assertNotNull("context", context); assertNotBlank(Pac4jConstants.DEFAULT_URL, defaultUrl); final Clients<AsyncClient<? extends Credentials, ? extends U>, AsyncAuthorizationGenerator<U>> clients = config.getClients(); final AsyncClient<? extends Credentials, ? extends U> client = clients.findClient(context); logger.debug("client: {}", client); assertNotNull("client", client); assertTrue(client.isIndirect(), "only indirect clients are allowed on the callback url"); final CompletableFuture<Void> sessionRenewalFuture = perClientAuthenticator.authenticateFor(client, context) .thenCompose(profileOption -> saveStrategy.saveProfile(getProfileManager(context, config), p -> true, profileOption.orElse(null))) .thenCompose(b -> { if (b) { return sessionRenewalStrategy.renewSession(context, config); } else { return CompletableFuture.completedFuture(null); } }); final CompletableFuture<HttpAction> actionFuture = sessionRenewalFuture.thenCompose(v -> indirectAuthenticationFlow.redirectToOriginallyRequestedUrl(context, defaultUrl)); return actionFuture.handle(ExceptionSoftener.softenBiFunction(AsyncExceptionHandler::extractAsyncHttpAction)) .handle(AsyncExceptionHandler::wrapUnexpectedException) .thenApply(a -> httpActionAdapter.adapt(a.getCode(), context)); } DefaultAsyncCallbackLogic(final boolean multiProfile,
                                     final boolean renewSession,
                                     final AsyncConfig<R, U, WC> config,
                                     final HttpActionAdapter<R, WC> httpActionAdapter); CompletableFuture<R> perform(final WC context,
                                        final String inputDefaultUrl);  }