Configuração do Landing Page no Liferay

Como customizar o redirecionamento da página de login do usuário no Liferay:

Quando um usuário loga no sistema do Liferay, ele é automaticamente redirecionado para a página inicial da comunidade Guest.

Se deseja que ele seja redirecionado para por exemplo a página inicial de uma organização ou uma comunidade é necessário criar essa modificação utilizando o ambiente de extensão do liferay.

A classe que necessita ser modificada para que o usuário tenha esse redirecionamento é a CustomLandingPage.

Essa classe está localizada no diretório com\liferay\portal\events.

Para criar a modificação você deve estar com o ambiente de extensão configurado, se ainda não está, clique aqui antes de prosseguir.

Com o ambiente configurado, crie uma classe java no seguinte diretório: {dirExtLiferay}\ext-impl\src\com\liferay\portal\events com o nome de CustomLandingPages e insira o seguinte código:

/**
 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.liferay.portal.events;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.util.WebKeys;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.struts.LastPath;

import com.liferay.portal.util.PropsKeys;
import com.liferay.portal.util.PropsValues;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * <a href="CustomLandingPageAction.java.html"><b><i>View Source</i></b></a>
 *
 * @author of modification Lucas Thomaz
 *
 */
public class CustomLandingPageAction extends Action {
    public void run(HttpServletRequest request, HttpServletResponse response) {

        String path = PropsValues.DEFAULT_LANDING_PAGE_PATH;

        if (_log.isInfoEnabled()) {
            _log.info(
                    PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
        }

        String userId = request.getRemoteUser();
        String forwardUrl = "/web/guest";
        User user = null;
        String orgname = null;

        try {
            user = UserLocalServiceUtil.getUserById(Long.parseLong(userId));
        } catch (PortalException ex) {
            Logger.getLogger(CustomLandingPageAction.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SystemException ex) {
            Logger.getLogger(CustomLandingPageAction.class.getName()).log(Level.SEVERE, null, ex);
        }

        List organizations = null;
        try {
            organizations = OrganizationLocalServiceUtil.getUserOrganizations(Long.parseLong(userId));
        } catch (Exception ex) {
            Logger.getLogger(CustomLandingPageAction.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (organizations != null && organizations.size() != 0) {
            Organization organization = (Organization) organizations.get(0);

            Group group = organization.getGroup();
            if(group.hasPrivateLayouts()) {
            	forwardUrl = "/group" + group.getFriendlyURL().toString();
            }
            if(group.hasPublicLayouts()) {
            	forwardUrl = "/web" + group.getFriendlyURL().toString();
            }

            Logger.getLogger(CustomLandingPageAction.class.getName()).info("Organization URL " + forwardUrl);
        }

        Map<String, String[]> params = new HashMap<String, String[]>();
        LastPath lastPath = new LastPath(StringPool.BLANK, forwardUrl, params);
        HttpSession session = request.getSession();
        session.setAttribute(WebKeys.LAST_PATH, lastPath);

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

Altere o arquivo ext-impl/src/portal-ext.properties e insira os comandos abaixo:

#redirecionar login
default.landing.page.path=/web/guest/home
default.logout.page.path=/
login.events.post=com.liferay.portal.events.LoginPostAction,com.liferay.portal.events.CustomLandingPageAction

Execute o ANT de deploy e pronto, quando o usuário logar no seu sistema ele automaticamente será redirecionado pra uma organização a que ele pertença.

Esse código está livre para que possa fazer qualquer modificação e adapta-lo melhor a sua necessidade, no entanto me notifique sobre.

Deixe um comentário

Observação: O seu comentário pode demorar algumas horas para aparecer.