com.stoxx.logout.post.action.LogoutPostAction.java Source code

Java tutorial

Introduction

Here is the source code for com.stoxx.logout.post.action.LogoutPostAction.java

Source

/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.stoxx.logout.post.action;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.struts.LastPath;
import com.liferay.portal.kernel.util.PrefsPropsUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.model.UserGroup;
import com.liferay.portal.service.UserGroupLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;

public class LogoutPostAction extends Action {

    @Override
    public void run(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = null;
        LastPath lastPathnew = null;
        try {
            session = request.getSession();
            String contextPath = "/web";
            lastPathnew = new LastPath(contextPath, "/stoxxcom/home");
            User _user = PortalUtil.getUser(request);
            if (Validator.isNotNull(_user)) {
                List<UserGroup> userGroups = UserGroupLocalServiceUtil.getUserUserGroups(_user.getUserId());
                _log.info(
                        ">>>>>>>>> logout url " + request.getRequestURL() + " user is " + _user.getEmailAddress());
                String lastPathAction = (String) request.getSession().getAttribute("lasPathString");
                _log.info("custom last path" + lastPathAction);
                Object lastPath = request.getSession().getAttribute("LAST_PATH");
                if (Validator.isNotNull(lastPath)) {
                    _log.info("The last path is " + lastPath.toString());
                } else {
                    _log.info("Last Path is null");
                }

                for (UserGroup userGroup : userGroups) {
                    _log.info("the usergroup names is " + userGroup.getName());
                    if (userGroup.getName()
                            .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.customer"))) {
                        lastPathnew = new LastPath(contextPath, "/stoxxcom/home");
                        break;
                    } else if (userGroup.getName()
                            .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.translator"))
                            || userGroup.getName()
                                    .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.staff.user"))) {
                        lastPathnew = new LastPath(contextPath, "/stoxxnet/login");
                        break;
                    } else if (userGroup.getName()
                            .equalsIgnoreCase(PrefsPropsUtil.getString("dax.usergroup.user"))) {
                        lastPathnew = new LastPath(contextPath, "/dax/login");
                        break;
                    } else {
                        lastPathnew = new LastPath(contextPath, "/stoxxcom/home");
                    }
                }
            }
            session.setAttribute(WebKeys.LAST_PATH, lastPathnew);
        } catch (Exception e) {
            _log.info(e.getMessage(), e);
        }
    }

    private static Log _log = LogFactoryUtil.getLog(LogoutPostAction.class);

}