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

br.com.jarch.faces.controller.LogoutController Maven / Gradle / Ivy

package br.com.jarch.faces.controller;

import br.com.jarch.core.annotation.JArchEventLogoutAfter;
import br.com.jarch.core.annotation.JArchViewScoped;
import br.com.jarch.core.cdi.GlobalInformation;
import br.com.jarch.faces.util.JsfUtils;
import br.com.jarch.core.model.MultiTenant;
import br.com.jarch.util.LogUtils;
import br.com.jarch.util.StringUtils;

import javax.annotation.PostConstruct;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.Serializable;

@JArchViewScoped
public class LogoutController implements Serializable {

    @Inject
    @JArchEventLogoutAfter
    private Event eventLogoutAfter;

    @PostConstruct
    private void init() {
        redirectLogin();
    }

    public void redirectLogin() {
        long tenantId = MultiTenant.getInstance().exists() ? MultiTenant.getInstance().get() : 0;

        eventLogoutAfter.fire(JsfUtils.getRequest());

//        JsfUtils.getSession().invalidate();

        try {
            String result;

            if (StringUtils.isNullOrEmpty(JsfUtils.getRedirectLogout())) {
                result = "/paginas/login/login.jsf";

                if (tenantId > 0) {
                    if (result.contains("?"))
                        result += "&";
                    else
                        result += "?";

                    result += "multiTenantId=" + tenantId;
                }
            } else
                result = JsfUtils.getRedirectLogout();

            GlobalInformation.getInstance().clear();

            JsfUtils.getResponse().sendRedirect(JsfUtils.getContextPath() + result);
            JsfUtils.responseComplete();
        } catch (IOException e) {
            LogUtils.generate(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy