Last active
January 1, 2016 23:49
-
-
Save edubriguenti/8218946 to your computer and use it in GitHub Desktop.
JSF redirectListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RedirectLoginListener implements PhaseListener { | |
public static final LogManager LOGGER = LogManager.getLog(RedirectLoginListener.class); | |
private final Properties properties = PropertiesLoader.loadProperties(PropertiesConstants.PROPERTIES_PATH); | |
public PhaseId getPhaseId() { | |
return PhaseId.RESTORE_VIEW; | |
} | |
public void beforePhase(final PhaseEvent event) { | |
} | |
public void afterPhase(final PhaseEvent event) { | |
final DadosSessao dadosSessao = SessaoUtil.getInstance().getDadosSessao(FacesContextUtils.getRequest()); | |
if (dadosSessao == null || dadosSessao.getDataValidade() == null) { | |
this.redirectToLoginPage(); | |
} else { | |
final Calendar calendarCookie = dadosSessao.getDataValidade(); | |
if (!calendarCookie.after(Calendar.getInstance())) { | |
this.redirectToLoginPage(); | |
} | |
} | |
} | |
/** | |
* Método para redirecionar a sessão expirada para a página de login. | |
*/ | |
private void redirectToLoginPage() { | |
try { | |
final String portalURL = "url"; | |
SessaoUtil.getInstance().invalidarSessao(FacesContextUtils.getRequest(), FacesContextUtils.getResponse()); | |
final ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); | |
externalContext.redirect(portalURL); | |
} catch (final IOException e) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment