1

我从 web.xml 中的 login-config 组件调用的 login.xhtml 页面有问题:

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>file</realm-name>
    <form-login-config>
        <form-login-page>/faces/Login/login.xhtml</form-login-page>
        <form-error-page>/faces/Login/error.xhtml</form-error-page>
    </form-login-config>
</login-config>

login.xhtml 使用 loginTemplate.xhtml 中定义的模板:

<ui:composition template="./loginTemplate.xhtml">

登录模板包含:

<p:layout fullPage="true">  
        <p:layoutUnit position="west" resizable="false" size="245">
            <ui:insert name="left" >
                Login
            </ui:insert>
        </p:layoutUnit>  

        <p:layoutUnit position="center" resizable="false"> 
            <ui:insert name="content">
                Abstract
            </ui:insert>
        </p:layoutUnit>  
</p:layout>

login.xhtml 页面包含一个表单,在“左侧”部分带有一个 and 字段。

页面以意想不到的方式呈现,并且 inputText 和 password 字段不接受任何值!

我在这里做错了什么?

问候

4

1 回答 1

3

很可能浏览器对 CSS/JS/image 资源的请求也包含在安全约束中,因此浏览器检索登录页面而不是具体的 CSS/JS/image 资源,导致渲染没有任何 CSS/JS/图片。如果您已经密切关注 HTTP 流量监控器(在 Chrome/Firefox>=23/IE>=9 中按 F12 并检查“网络(工作)”选项卡),那么您应该通过判断那些 HTTP 响应来注意到它资源。

在您的特殊情况下,当使用容器管理的安全性时,这很可能是由安全约束上的过度通用 URL 模式引起的,例如/*. 如果不能将受保护的页面移动到通用文件夹,/app这样您就可以将安全约束放在/app/*URL 模式上,那么您应该添加另一个安全约束,使 JSF 资源显式公开可用。您可以通过在预定义的 URL 模式上创建安全约束/javax.faces.resource/*以及完全不存在<auth-constraint>标记来做到这一点:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Allowed resources</web-resource-name>
        <url-pattern>/javax.faces.resource/*</url-pattern>
    </web-resource-collection>
    <!-- No auth-constraint tag! -->
</security-constraint>
于 2013-11-04T12:44:34.710 回答