2012-09-17 35 views
0

我有兩個頁面:如何獲得重定向頁面

@AuthorizeInstantiation(Roles.ADMIN) 
public class AdminPage extends BasePage { 
... 

@AuthorizeInstantiation(Roles.USER) 
public class UserPage extends BasePage { 
... 

時心不是登錄那麼他將被重定向到登錄頁面的任何用戶。有沒有一些選項如何獲得重定向頁面?所以如果用戶轉到管理頁面,然後登錄頁面println管理頁面。如果用戶到用戶頁面,然後登錄頁面的println用戶頁面,當用戶去只需登錄頁面,然後登錄頁面的println空

UPDATE:

策略,當你去保護的頁面

getApplicationSettings().setAccessDeniedPage(LoginPage.class); 

什麼心不是明白嗎?當用戶想要訪問UserPage或AdminPage時,他被重定向到LoginPage。我想在loginPage給println是

+1

你能不能改一下你的問題嗎?很難理解你想要解決什麼問題。 –

回答

0

OK我知道了:

創建unauthorizedComponentInstantiationListener:

getSecuritySettings().setUnauthorizedComponentInstantiationListener(
      new IUnauthorizedComponentInstantiationListener() { 
       public void onUnauthorizedInstantiation(final Component component) { 
        if (component instanceof Page) { 
         // Redirect to index 
         if (component instanceof AdminPage) { 
          redirectionPage = ((AdminPage) component); 
         } else if (component instanceof BalancerPage) { 
          redirectionPage = ((UserPage) component); 
         } 
         throw new RestartResponseAtInterceptPageException(LoginPage.class); 
         // Or you can just throw the original UnauthorizedInstantiationException 
        } else { 
         component.setVisible(false); 
        } 
       } 
      }); 

和appliaction設置變量。

然後,只需在登錄我打電話Application.getRedirectionPage()頁面,所以我知道這是哪個頁面

0

哪一頁,我不知道這是否是你在尋找什麼,但你可以看看

RestartResponseAtInterceptPageException.InterceptData.get(); 

InterceptData保存有關網頁的一些信息觸發重定向。

+0

hm我沒有看到這個建設在檢票口1.5+ – hudi

+0

是的!你是對的。此字段沒有外部可見性... –

0

你還沒有描述你如何做重定向到登錄頁面。我想你實現了一個IAuthorizationStrategy和IUnauthorizedComponentInstantiationListener?在你實現onUnauthorizedInstantiation()時,你可以檢查傳入的組件(也就是你的頁面)上的哪個註釋,並根據這個參數傳遞給登錄頁面。

+0

soryy更新了我通過getApplicationSettings()。setAccessDeniedPage(LoginPage.class); – hudi