Perhaps, with PhaseListener:
public class AuthenticationPhaseListener implements PhaseListener {
/** Creates a new instance of AuthenticationPhaseListener */
public AuthenticationPhaseListener() {
}
public void afterPhase(PhaseEvent phaseEvent) {
FacesContext context = phaseEvent.getFacesContext();
if(userLoged(context))
return;
String path=context.getViewRoot().getViewId();
if(!"/login.xhtml".equals(path)){
context.responseComplete();
context.getApplication().getNavigationHandler().handleNavigation(context,null,navigate_to_login_screen);
}
}
public void beforePhase(PhaseEvent phaseEvent) {
}
public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
}
private boolean userLoged(FacesContext context) {
if(context.getExternalContext().getSessionMap().get("logedUser")!=null)
return true;
else
return false;
}
}
ignicolist wrote:
Hi, i need some help, i have a aplication in jsf, with a sql database using
hibernate, and i want implement a login and logout, but i dont know how, i
google much, but all the solutions are so complicated. so i have a example
with a filter, and a put that filter block the pages for non log users, but
i dont know the sufs about sessions and so on... anyone have some example
working for i use in my aplication?
I just want a simple login logout example, using a filter for sessions.
Tks for all the help...