public void beforePhase(PhaseEvent event) {
FacesContext ctx = event.getFacesContext();
HttpSession session = ((HttpSession) ctx.getExternalContext().getSession(true));
LoginBean login = BeanInject.lookup(LoginBean.class);
Page page = nav.lookup(event.getFacesContext().getViewRoot().getViewId());
if (page.isRequiresLogin() && !login.isLoggedIn()) {
if (nav.shouldRedirectToLogin()) {
redirectToLogin(ctx, session, nav, page);
} else {
nav.responseForbidden(ctx);
}
} else if (login.isLoggedIn() && session.getAttribute(PREVIOUS_VIEW) != null) {
redirectToPreviousView(ctx, session);
} else if (page.getSecurityEL() != null && page.getSecurityEL().length() > 0) {
evaluateSecurityExpression(ctx, page);
}
}