Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf HTTP状态403-已拒绝访问请求的资源(CSS阻止?)_Jsf - Fatal编程技术网

Jsf HTTP状态403-已拒绝访问请求的资源(CSS阻止?)

Jsf HTTP状态403-已拒绝访问请求的资源(CSS阻止?),jsf,Jsf,我一直在努力确保我的项目安全。我有一个使用LDAP服务器进行身份验证的登录页面,如果不正确,它会弹出一个错误页面等。我现在刚刚添加了 <auth-constraint> <!-- Currently causing a 403, looks like stoping .css files --> <role-name>*</role-name> </auth-constraint> 出现此错误时: HTTP状态403-已

我一直在努力确保我的项目安全。我有一个使用LDAP服务器进行身份验证的登录页面,如果不正确,它会弹出一个错误页面等。我现在刚刚添加了

<auth-constraint> <!-- Currently causing a 403, looks like stoping .css files --> 
    <role-name>*</role-name>
</auth-constraint>


出现此错误时:

HTTP状态403-已拒绝访问请求的资源


类型状态报告

消息对请求的资源的访问被拒绝

说明禁止访问指定资源(拒绝访问请求的资源)


GlassFish服务器开源版本3.1.2.2

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>Upload Filter</filter-name>
        <filter-class>richard.fileupload.UploadFilter</filter-class>
        <init-param>
            <param-name>sizeThreshold</param-name>
            <param-value>1024</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Upload Filter</filter-name>
        <url-pattern>/upload/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/corejsf.taglib.xml</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>LDAP</realm-name>
        <form-login-config>
            <form-login-page>/login.xhtml</form-login-page>
            <form-error-page>/login-failed.xhtml</form-error-page>
        </form-login-config>
    </login-config>
    <security-role>
        <role-name>user</role-name>
    </security-role>
    <security-constraint> 
        <web-resource-collection>
            <web-resource-name>Allowed resources</web-resource-name>
            <url-pattern>/javax.faces.resources/*</url-pattern>
        </web-resource-collection>   
        <!-- web resources that are protected -->
        <web-resource-collection>
            <web-resource-name>All Resources</web-resource-name>
            <url-pattern>/*</url-pattern>
            <!-- this is currently causing a 404 -->
            <http-method>GETLIB</http-method>
            <http-method>COPY</http-method>
            <http-method>MOVE</http-method>
            <http-method>DELETE</http-method>
            <http-method>PROPFIND</http-method>
            <http-method>GET</http-method>
            <http-method>HEAD</http-method>
            <http-method>PUT</http-method>
            <http-method>MKCOL</http-method>
            <http-method>PROPPATCH</http-method>
            <http-method>LOCK</http-method>
            <http-method>UNLOCK</http-method>
            <http-method>VERSION-CONTROL</http-method>
            <http-method>CHECKIN</http-method>
            <http-method>CHECKOUT</http-method>
            <http-method>UNCHECKOUT</http-method>
            <http-method>REPORT</http-method>
            <http-method>UPDATE</http-method>
            <http-method>CANCELUPLOAD</http-method>
        </web-resource-collection>
        <auth-constraint> <!-- Currently causing a 403, looks like stoping .css files --> 
            <role-name>*</role-name>
        </auth-constraint>
    </security-constraint>
</web-app>

上传过滤器
richard.fileupload.UploadFilter
sizeThreshold
1024
上传过滤器
/上传/*
Facesservlet
javax.faces.webapp.FacesServlet
Facesservlet
*.xhtml
index.xhtml
javax.faces.PROJECT_阶段
发展
facelets.LIBRARIES
/WEB-INF/corejsf.taglib.xml
javax.faces.explait_EMPTY_STRING_SUBMITTED_VALUES_为_NULL
真的
形式
LDAP
/login.xhtml
/login-failed.xhtml
用户
允许的资源
/javax.faces.resources/*
所有资源
/*
GETLIB
复制
移动
删除
PROPFIND
得到
头
放
MKCOL
支撑块
锁
解锁
版本控制
签到
结账
取消勾选
报告
更新
取消上载
*

基本上,是什么阻止了我的css文件以及我如何允许它?

您的安全约束也阻止了对css文件的请求(基本上,它阻止了所有与指定登录页面的
/*
的指定URL模式相匹配的内容)。您需要添加另一个安全约束,该约束应允许对JSF资源的请求。关键是省略auth约束,使每个人都可以访问这些资源

<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 Contraint! -->
</security-constraint>

允许的资源
/javax.faces.resource/*

您的.css也需要保护吗?最简单的解决办法是把它放在“公共”场所。不确定这是否可行-但很快。不,css可以公开,但是,如果不知道你的目录结构,我就不能对它进行评论,但是如果你有你网站的根目录,你可以有一个目录,
/protectedDir
,敏感代码所在的位置,以及css所在的另一个位置,
/css
。然后您在源代码中将css文件引用为
。/css/myfile.css
,它的访问应该没有问题。非常感谢,我添加了上述代码,并按照您的示例介绍了如何构建我的项目,我已将css文件放在参考资料/css中,并更新了上面的web.xml,但是它仍然阻止了我的css:S有什么想法吗?你需要将允许资源的
移动到限制资源的
下方。谢谢,你有没有一个例子来说明除了css文件之外,我如何在任何页面上要求身份验证?对不起,听起来很难听,但这部分我真的很困惑@Namphibian:如果出于某种原因,您仍然使用旧的JSF1.0样式
/faces/*
模式,那么确实需要这样做。当前问题的提问者正确地使用了JSF2.0的
*.xhtml
模式,因此我的回答是绝对有效的。@Namphibian:目前对我来说只有19:52。