1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public class RedirectionLogin implements javax.faces.event.PhaseListener {
/**
* Redirection si l'utilisateur n'est pas authentifié
* Voir lifecycle dans faces-config
* @param e
*/
public void afterPhase(javax.faces.event.PhaseEvent e) {
FacesContext context = e.getFacesContext();
ApplicationBean1 app = (ApplicationBean1) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("ApplicationBean1");
if(app == null){
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("ApplicationBean1", new ApplicationBean1());
}
SessionBean1 sessionBean = (SessionBean1) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("SessionBean1");
try {
String viewId = context.getViewRoot().getViewId();
if((sessionBean!=null) && (!sessionBean.getLog()) && !("/Login.jsp".equals(viewId))){
FacesContext.getCurrentInstance().getExternalContext().redirect("Login.jsp");
}
if((sessionBean==null) && !("/Login.jsp".equals(viewId))){
FacesContext.getCurrentInstance().getExternalContext().redirect("Login.jsp");
}
} catch (IOException e1) {}
}
public void beforePhase(javax.faces.event.PhaseEvent e) {
}
public javax.faces.event.PhaseId getPhaseId() {
return javax.faces.event.PhaseId.ANY_PHASE;
} |