All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.inverno.mod.security.http.token.CookieTokenLogoutSuccessHandler Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2022 Jeremy Kuhn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.inverno.mod.security.http.token;

import io.inverno.mod.http.server.Exchange;
import io.inverno.mod.security.accesscontrol.AccessController;
import io.inverno.mod.security.authentication.Authentication;
import io.inverno.mod.security.http.login.LogoutSuccessHandler;
import io.inverno.mod.security.http.context.SecurityContext;
import io.inverno.mod.security.identity.Identity;
import reactor.core.publisher.Mono;

/**
 * 

* A logout success handler that removes the token cookie. *

* * @author Jeremy Kuhn * @since 1.5 * * @param the authentication type * @param the identity type * @param the access controller type * @param the security context type * @param the exchange type */ public class CookieTokenLogoutSuccessHandler, E extends Exchange> implements LogoutSuccessHandler { /** * The token cookie path. */ private final String path; /** * The token cookie name. */ private final String tokenCookie; /** *

* Creates a cookie token logout success handler with default path and token cookie name. *

*/ public CookieTokenLogoutSuccessHandler() { this(CookieTokenLoginSuccessHandler.DEFAULT_PATH, CookieTokenCredentialsExtractor.DEFAULT_COOKIE_NAME); } /** *

* Creates a cookie token logout success handler with the specified path and the default token cookie name. *

* * @param path the token cookie path */ public CookieTokenLogoutSuccessHandler(String path) { this(path, CookieTokenCredentialsExtractor.DEFAULT_COOKIE_NAME); } /** *

* Creates a cookie token logout success handler with specified path and token cookie name. *

* * @param path the token cookie path * @param tokenCookie the token cookie name */ public CookieTokenLogoutSuccessHandler(String path, String tokenCookie) { this.path = path; this.tokenCookie = tokenCookie; } /** *

* Returns the token cookie path. *

* * @return the token cookie path */ public String getPath() { return path; } /** *

* Returns the token cookie name. *

* * @return the token cookie name */ public String getTokenCookie() { return tokenCookie; } @Override public Mono handleLogoutSuccess(E exchange, A authentication) { return Mono.fromRunnable(() -> exchange.response().headers(headers-> headers.cookies(cookies -> cookies .addCookie(cookie -> cookie .path(this.path) .name(this.tokenCookie) .value("") .maxAge(0) ) ))); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy