0
我有一個PhaseListener來控制用戶訪問某些頁面,如果用戶沒有登錄,他會被重定向到登錄頁面。handleNavigation不能在PhaseListener中工作
問題是我的方法handleNavigation沒有重定向用戶。 它運行但不重定向用戶。
當用戶鍵入一個不應該具有訪問權的url時,該方法會運行,但是他打開的頁面不會重定向到登錄頁面。
出了什麼問題?
public class AuthorizationListener implements PhaseListener {
public void afterPhase(PhaseEvent event) {
FacesContext facesContext = event.getFacesContext();
String currentPage = facesContext.getViewRoot().getViewId();
boolean isLoginPage = (currentPage.lastIndexOf("login.xhtml") > -1);
if(isLoginPage)
return;
if(currentPage.indexOf("/rws/") != -1)
{
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
Object currentUser = session.getAttribute("usuario");
if (!isLoginPage && currentUser == null) {
NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
nh.handleNavigation(facesContext, null, "loginPage");
}
}
}
public void beforePhase(PhaseEvent event) {
System.out.println("Hellow World");
}
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
}
我的臉,配置
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>loginPage</from-outcome>
<to-view-id>/login.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<lifecycle>
<phase-listener>br.com.testes.filter.AuthorizationListener</phase-listener>
</lifecycle>
我只是看着你的[博客](http://balusc.blogspot.com/2013/01/apache-shiro-is-it-ready-for-java-ee-6.html),在這裏你是 ! – Apurv 2013-04-24 12:33:07
@Apurv:謝謝你的Shiro提示。請注意,Shiro也使用servlet過濾器;) – BalusC 2013-04-24 12:33:45
謝謝,我現在看到錯誤。如果我使用beforePhase方法正常工作。 – user1352652 2013-04-24 12:41:51