2009-07-25 128 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的评论,只是为了寻找根本原因)