警告:JACC:对于URL模式xxx,除了以下方法之外的所有方法都被发现:POST,GET

Tin*_*iny 7 servlets jaas java-ee java-ee-7 servlet-3.1

javax.faces.webapp.FacesServlet文档中,提到了,

允许的HTTP方法

JSF规范只需要使用GET和POST http方法.如果您的Web应用程序不需要任何其他http方法,例如PUT和DELETE,请考虑使用<http-method><http-method-omission>元素限制允许的http方法.有关使用这些元素的更多信息,请参阅Java Servlet规范的安全性.


我的应用程序确实不依赖于其他HTTP方法(除了GETPOST).因此,我试图使用<http-method>(或<http-method-omission>)排除除GET和之外的所有方法POST.

在web.xml中,JAAS Servlet安全性约束配置如下.

<security-constraint>
    <display-name>AdminConstraint</display-name>
    <web-resource-collection>
        <web-resource-name>ROLE_ADMIN</web-resource-name>
        <description/>
        <url-pattern>/admin_side/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>ROLE_ADMIN</role-name>
    </auth-constraint>
    <user-data-constraint>
        <description/>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<security-constraint>
    <display-name>UserConstraint</display-name>
    <web-resource-collection>
        <web-resource-name>ROLE_USER</web-resource-name>
        <description/>
        <url-pattern>/user_side/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>ROLE_USER</role-name>
    </auth-constraint>
    <user-data-constraint>
        <description/>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

使用这些元素,

<http-method>GET</http-method>
<http-method>POST</http-method>
Run Code Online (Sandbox Code Playgroud)

我希望不允许所有其他HTTP方法.


但是,GlassFish Server 4.1在服务器终端上记录以下警告.

警告:JACC:对于URL模式/user_side/*,除了以下方法之外的所有方法都被发现:POST,GET

警告:JACC:对于URL模式/admin_side/*,除了以下方法之外的所有方法都被发现:POST,GET

这是什么意思?


此外,它不是在所有<security-constraint>元素中执行,而是可以全局配置,以便它可以应用于应用程序中的所有资源,GET并且POST可以省略所有except 和HTTP请求,即全局应用于应用程序 - 可能通过使用更通用的专用网址模式如何/*


有一个例子在这里.

<security-constraint>
    <display-name>WebConstraint</display-name>

    <web-resource-collection>
        <web-resource-name>test</web-resource-name>
        <description/>
        <url-pattern>/test.jsp</url-pattern>
        <http-method>POST</http-method>
        <http-method>HEAD</http-method>
        <http-method>PUT</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>TRACE</http-method>
        <http-method>DELETE</http-method>
    </web-resource-collection>

    <auth-constraint>
        <description/>
        <role-name>dev</role-name>
     </auth-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

上面的元素表示当由除GET之外的所有http方法访问时,url模式/test.jsp引用的资源应该被限制为仅由属于角色dev的经过身份验证的用户查看.请注意,安全性约束不适用于http方法GET,但仅适用于其他方法(POST,HEAD,PUT等).

我发现强文中的最后一句令人困惑.这是否意味着使用GET请求,匿名用户可以访问给定url-pattern中列出的资源,因为它意味着" 安全约束不适用于http-method GET "?

unw*_*ich 10

这是什么意思?

这意味着除了GET和POST之外的所有方法都被发现,意味着不受保护.每个人都可以使用/user_side/*PUT和HEAD等方法访问url模式而无需身份验证.

要保护其他方法,请添加以下内容:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>protected</web-resource-name>
        <url-pattern>/user_side/*</url-pattern>
        <http-method-omission>GET</http-method-omission>
        <http-method-omission>POST</http-method-omission>
    </web-resource-collection>
    <auth-constraint/>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

如果您使用的是Servlet 3.1,也可以使用较短的标签:

<deny-uncovered-http-methods/>
Run Code Online (Sandbox Code Playgroud)

此外,它不是在所有元素中执行,而是可以全局配置,以便它可以应用于应用程序中的所有资源,并且可以省略除GET和POST HTTP请求之外的所有资源,即全局应用于应用程序 - 可能通过使用更多广义url-pattern喜欢/*?

是的,这是可能的.您可以使用url-pattern /包含所有子文件夹.

我发现强文中的最后一句令人困惑.这是否意味着使用GET请求,匿名用户也可以访问给定url-pattern中列出的资源,因为它意味着"安全约束不适用于http-method GET"?

你是对的,这意味着匿名用户可以使用GET方法访问给定的url-pattern.所有其他方法都受到保护.

也可以看看: