2013-06-03 26 views
0

我有默認的歡迎文件爲所有用戶,但我需要每個歡迎文件爲每個組:如何爲每個組設置不同的歡迎文件?

<welcome-file-list> 
     <welcome-file>faces/index.xhtml</welcome-file> 
    </welcome-file-list> 
    <security-constraint> 
     <display-name>Constraint1</display-name> 
     <web-resource-collection> 
      <web-resource-name>EspaceAdmin</web-resource-name> 
      <description/> 
      <url-pattern>/faces/admin/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <description/> 
      <role-name>administrateur</role-name> 
     </auth-constraint> 
    </security-constraint> 
    <security-constraint> 
     <display-name>Constraint2</display-name> 
     <web-resource-collection> 
      <web-resource-name>EspaceDrapage</web-resource-name> 
      <description/> 
      <url-pattern>/faces/drapage/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <description/> 
      <role-name>chefdequipedrapage</role-name> 
     </auth-constraint> 

    </security-constraint> 

這裏我有2組如何可以爲每個組一個新的歡迎文件設置?

+0

我需要刪除默認的歡迎文件列表??? – marouanoviche

+0

您可以在* faces/index.xhtml *上使用過濾器,該過濾器將根據其角色重定向用戶。請注意,這是非常奇怪的,因爲如果沒有以前的身份驗證和驗證步驟,您將不知道用戶角色。 –

+0

我怎麼可以用戶重定向取決於用戶規則? – marouanoviche

回答

0

這是解決方案爲我:我創建了一個託管bean包含:

public String Login() { 
     try { 
      message=""; 
      HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); 
      request.login(username, password); 

      if(request.isUserInRole("administrateur")) 
      { setGroupname("administrateur"); 
       return "/admin/adminHome.xhtml";} 

      else if(request.isUserInRole("chefdtype1")) 
      {setGroupname("cheftype1"); 
       return "/type1/type1Home.xhtml";} 

      else if(request.isUserInRole("cheftype2")) 
      {setGroupname("cheftype2"); 
       return "/type2/type2Home.xhtml";} 

      else { 
       message= "Either Login or Password is wrong"; 
       return "/index.xhtml"; 
      } 

     } catch(Exception e) { 
      message= "Either Login or Password is wrong"; 
      FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Votre login ou votre mot de passe est incorrect.", "")); 
     } 
     return null; 
    } 
相關問題