@Test public void testLogoutWithDefaultUrl(final TestContext testContext) { final Map<String, TestProfile> profiles = new HashMap<>(); profiles.put(NAME, TestProfile.from(TEST_CREDENTIALS)); final Clients<AsyncClient<? extends Credentials, ? extends TestProfile>, AsyncAuthorizationGenerator<TestProfile>> clients = new Clients<>(); when(config.getClients()).thenReturn(clients); final Async async = testContext.async(); asyncLogoutLogic = new DefaultAsyncLogoutLogic<>(config, httpActionAdapter, CALLBACK_URL, null, true, false, false); final CompletableFuture<Object> resultFuture = addProfilesToContext(profiles) .thenCompose(v -> asyncLogoutLogic.perform(webContext)); assertSuccessfulEvaluation(assertProfilesCount(resultFuture, 0), o -> { assertThat(buffer.toString(), is("")); assertThat(status.get(), is(302)); assertThat(responseHeaders.get(HttpConstants.LOCATION_HEADER), is(CALLBACK_URL)); }, async); }
@Override public CompletableFuture<R> perform(WC context) { assertNotNull("context", context); final String url = context.getRequestParameter(Pac4jConstants.URL); final String redirectUrl = (url != null && Pattern.matches(logoutUrlPattern, url)) ? url : defaultUrl; logger.debug("redirectUrl: {}", redirectUrl); final AsyncProfileManager manager = getProfileManager(context, config); final CompletableFuture<List<? extends U>> loggedOutProfilesFuture = localLogoutStrategy.logout(manager, sessionDestructionStrategy, context); return loggedOutProfilesFuture.thenApply(profiles -> centralLogoutStrategy.getCentralLogoutAction(config.getClients(), profiles, redirectUrl, context)) .thenApply(o -> o.map(s -> s.get()) .orElseGet(() -> redirectUrl == null ? ok("ok", context) : redirect("redirect", context, redirectUrl))) .thenApply(action -> httpActionAdapter.adapt(action.getCode(), context)); }
DefaultAsyncLogoutLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncLogoutLogic<R, WC> { @Override public CompletableFuture<R> perform(WC context) { assertNotNull("context", context); final String url = context.getRequestParameter(Pac4jConstants.URL); final String redirectUrl = (url != null && Pattern.matches(logoutUrlPattern, url)) ? url : defaultUrl; logger.debug("redirectUrl: {}", redirectUrl); final AsyncProfileManager manager = getProfileManager(context, config); final CompletableFuture<List<? extends U>> loggedOutProfilesFuture = localLogoutStrategy.logout(manager, sessionDestructionStrategy, context); return loggedOutProfilesFuture.thenApply(profiles -> centralLogoutStrategy.getCentralLogoutAction(config.getClients(), profiles, redirectUrl, context)) .thenApply(o -> o.map(s -> s.get()) .orElseGet(() -> redirectUrl == null ? ok("ok", context) : redirect("redirect", context, redirectUrl))) .thenApply(action -> httpActionAdapter.adapt(action.getCode(), context)); } }
DefaultAsyncLogoutLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncLogoutLogic<R, WC> { @Override public CompletableFuture<R> perform(WC context) { assertNotNull("context", context); final String url = context.getRequestParameter(Pac4jConstants.URL); final String redirectUrl = (url != null && Pattern.matches(logoutUrlPattern, url)) ? url : defaultUrl; logger.debug("redirectUrl: {}", redirectUrl); final AsyncProfileManager manager = getProfileManager(context, config); final CompletableFuture<List<? extends U>> loggedOutProfilesFuture = localLogoutStrategy.logout(manager, sessionDestructionStrategy, context); return loggedOutProfilesFuture.thenApply(profiles -> centralLogoutStrategy.getCentralLogoutAction(config.getClients(), profiles, redirectUrl, context)) .thenApply(o -> o.map(s -> s.get()) .orElseGet(() -> redirectUrl == null ? ok("ok", context) : redirect("redirect", context, redirectUrl))) .thenApply(action -> httpActionAdapter.adapt(action.getCode(), context)); } DefaultAsyncLogoutLogic(final AsyncConfig<R, U, WC> config,
                                   final HttpActionAdapter<R, WC> httpActionAdapter,
                                   final String defaultUrl,
                                   final String logoutUrlPattern,
                                   boolean localLogout,
                                   boolean destroySession,
                                   boolean centralLogout); }
DefaultAsyncLogoutLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncLogoutLogic<R, WC> { @Override public CompletableFuture<R> perform(WC context) { assertNotNull("context", context); final String url = context.getRequestParameter(Pac4jConstants.URL); final String redirectUrl = (url != null && Pattern.matches(logoutUrlPattern, url)) ? url : defaultUrl; logger.debug("redirectUrl: {}", redirectUrl); final AsyncProfileManager manager = getProfileManager(context, config); final CompletableFuture<List<? extends U>> loggedOutProfilesFuture = localLogoutStrategy.logout(manager, sessionDestructionStrategy, context); return loggedOutProfilesFuture.thenApply(profiles -> centralLogoutStrategy.getCentralLogoutAction(config.getClients(), profiles, redirectUrl, context)) .thenApply(o -> o.map(s -> s.get()) .orElseGet(() -> redirectUrl == null ? ok("ok", context) : redirect("redirect", context, redirectUrl))) .thenApply(action -> httpActionAdapter.adapt(action.getCode(), context)); } DefaultAsyncLogoutLogic(final AsyncConfig<R, U, WC> config,
                                   final HttpActionAdapter<R, WC> httpActionAdapter,
                                   final String defaultUrl,
                                   final String logoutUrlPattern,
                                   boolean localLogout,
                                   boolean destroySession,
                                   boolean centralLogout); @Override CompletableFuture<R> perform(WC context); }
DefaultAsyncLogoutLogic extends ProfileManagerFactoryAware<WC, AsyncProfileManager<U, WC>, AsyncConfig<R, U, WC>> implements AsyncLogoutLogic<R, WC> { @Override public CompletableFuture<R> perform(WC context) { assertNotNull("context", context); final String url = context.getRequestParameter(Pac4jConstants.URL); final String redirectUrl = (url != null && Pattern.matches(logoutUrlPattern, url)) ? url : defaultUrl; logger.debug("redirectUrl: {}", redirectUrl); final AsyncProfileManager manager = getProfileManager(context, config); final CompletableFuture<List<? extends U>> loggedOutProfilesFuture = localLogoutStrategy.logout(manager, sessionDestructionStrategy, context); return loggedOutProfilesFuture.thenApply(profiles -> centralLogoutStrategy.getCentralLogoutAction(config.getClients(), profiles, redirectUrl, context)) .thenApply(o -> o.map(s -> s.get()) .orElseGet(() -> redirectUrl == null ? ok("ok", context) : redirect("redirect", context, redirectUrl))) .thenApply(action -> httpActionAdapter.adapt(action.getCode(), context)); } DefaultAsyncLogoutLogic(final AsyncConfig<R, U, WC> config,
                                   final HttpActionAdapter<R, WC> httpActionAdapter,
                                   final String defaultUrl,
                                   final String logoutUrlPattern,
                                   boolean localLogout,
                                   boolean destroySession,
                                   boolean centralLogout); @Override CompletableFuture<R> perform(WC context);  }