1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.web.logout;
17
18 import org.codelibs.core.lang.StringUtil;
19 import org.codelibs.fess.app.web.base.FessSearchAction;
20 import org.codelibs.fess.app.web.login.LoginAction;
21 import org.codelibs.fess.mylasta.action.FessUserBean;
22 import org.codelibs.fess.util.ComponentUtil;
23 import org.dbflute.optional.OptionalThing;
24 import org.lastaflute.web.Execute;
25 import org.lastaflute.web.response.HtmlResponse;
26
27 /**
28 * The logout action.
29 */
30 public class LogoutAction extends FessSearchAction {
31
32 /**
33 * Default constructor.
34 */
35 public LogoutAction() {
36 super();
37 }
38
39 // ===================================================================================
40 // Constant
41 //
42
43 // ===================================================================================
44 // Attribute
45 //
46
47 // ===================================================================================
48 // Hook
49 // ======
50
51 // ===================================================================================
52 // Search Execute
53 // ==============
54
55 /**
56 * Handles user logout and redirects to the login page.
57 *
58 * @return the HTML response after logout
59 */
60 @Execute
61 public HtmlResponse index() {
62 final OptionalThing<FessUserBean> userBean = getUserBean();
63 activityHelper.logout(userBean);
64 final String redirectUrl = userBean.map(user -> ComponentUtil.getSsoManager().logout(user)).orElse(null);
65 fessLoginAssist.logout();
66 userInfoHelper.deleteUserCodeFromCookie(request);
67 if (StringUtil.isNotBlank(redirectUrl)) {
68 return HtmlResponse.fromRedirectPathAsIs(redirectUrl);
69 }
70 return redirect(LoginAction.class);
71 }
72
73 }