如何为每个组设置不同的欢迎文件?

时间:2013-06-03 13:38:52

标签: jsf

我有所有用户的默认欢迎文件,但我需要每个组的每个欢迎文件:

<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>

这里我有两组我如何为每个组设置一个新的欢迎文件??

1 个答案:

答案 0 :(得分: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;
    }