2009-07-25 135 views
1

我有一個從網頁繼承和下方類保護的網頁上:當我進入該頁面它是確定,一切工作重定向問題

public final class WiaAuthorizationStrategy implements 
     IAuthorizationStrategy, 
     IUnauthorizedComponentInstantiationListener { 

    private RealmPolicy roleManager; 
    private static WiaAuthorizationStrategy instance; 

    private WiaAuthorizationStrategy() { 
     roleManager = RealmPolicy.getInstance(); 
    } 

    public static WiaAuthorizationStrategy getInstance() { 
     if(instance == null) 
      instance = new WiaAuthorizationStrategy(); 
     return instance; 
    } 

    public boolean isInstantiationAuthorized(Class componentClass) { 

     if (ProtectedPage.class.isAssignableFrom(componentClass)) { 
      if (WiaSession.get().getUser() == null) { 
       return false; 
      } 
      if(!roleManager.isAuthorized(WiaSession.get().getUser().getRole(), componentClass.getName()))//WiaSession.get().isAuthenticated(); 
      { 
       WiaSession.get().setAccess(false); 
       return false; 
      } 
      else 
       return true; 
     } 

     return true; 
    } 

    public void onUnauthorizedInstantiation(Component component) { 
     throw new RestartResponseAtInterceptPageException(
       Login.class); 
    } 

    public boolean isActionAuthorized(Component component, Action action) { 
     //System.out.println("Name:" + component.getClass().getName() + "\n Action:" + action.getName() + "\nUser:" + WiaSession.get().getUser()); 
     if (action.equals(Component.RENDER)) { 
      if (roleManager.containClass(component.getClass().getName())) 
      { 
       if (WiaSession.get().getUser() != null) { 
        if(!roleManager.isAuthorized(WiaSession.get().getUser().getRole(), component.getClass().getName())) 
        { 
         WiaSession.get().setAccess(false); 
         return false; 
        } 
        return true; 
       } 
       return false; 
      } 
     } 
     return true; 
    } 
} 

但是當我按下Ctrl + F5頁面重定向到登錄頁面,該頁面默認用於訪問受保護的頁面。 我試圖調試代碼,我發現ProtectedPage類中的super()函數執行此操作,並且在調試中我無法輸入這部分代碼。此類存在如下:

public abstract class ProtectedPage extends WebPage { 

    public ProtectedPage() { 

---- >>> super(); verifyAccess(); }

protected void verifyAccess() { 
// Redirect to Login page on invalid access. 
     if (!isUserLoggedIn()) { 
      throw new RestartResponseAtInterceptPageException(Login.class); 
     } 
    } 

    protected boolean isUserLoggedIn() { 
     return ((WiaSession) getSession()).isAuthenticated(); 
    } 
} 

我已經簽署了由---- >>>登錄的代碼。 任何人都可以幫我解決這個問題嗎?

回答

2

當您安裝了IAuthorizationStrategy時,不要使用類似verifyAccess的東西;後者應該爲你完成整個工作。

+0

很高興見到你在這裏Eelco,真的喜歡Wicket in Action! – Tim 2009-08-02 00:58:17

0

ctrl + F5應該做什麼?

你有一些鍵綁定問題嗎?

你不能做重定向嗎?你的問題到底是什麼?

+0

當我刷新我的網頁或做一些需要接觸到服務器頁面重定向到登錄頁面 – JGC 2009-07-25 06:12:46

0

WiaSession.isAuthenticated()的邏輯是什麼?

(沒有忽視Eelco的評論,只是爲了尋找根本原因)