【问题标题】:Security constraint in web.xml not getting applied to URL patterns having file extensionweb.xml 中的安全约束未应用于具有文件扩展名的 URL 模式
【发布时间】:2013-10-18 04:16:28
【问题描述】:

我在 web.xml 中输入了以下安全约束。我的目标是 XML 文件位于公共区域。这适用于 /images/* 文件夹。但是 url 模式 *.xml 似乎不起作用。有什么想法吗?

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Public Area</web-resource-name>
            <url-pattern>/xyz</url-pattern>
            <url-pattern>/images/*</url-pattern>
            <url-pattern>/yyz/*</url-pattern>
            <url-pattern>*.xml</url-pattern>
        </web-resource-collection>
    </security-constraint>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Super User Area</web-resource-name>
            <url-pattern>/test/list1</url-pattern>
            <url-pattern>/test/list2</url-pattern>
            <url-pattern>/test/list3</url-pattern>
            <url-pattern>/test/admin.html</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>SUPER_USER</role-name>
        </auth-constraint>
    </security-constraint>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>ADMIN</role-name>
            <role-name>END_USER</role-name>
        </auth-constraint>
    </security-constraint>


    <security-role>
        <description>Super User</description>
        <role-name>SUPER_USER</role-name>
    </security-role>
    <security-role>
        <description>Admin User</description>
        <role-name>ADMIN</role-name>
    </security-role>
    <security-role>
        <description>End User</description>
        <role-name>END_USER</role-name>
    </security-role>

【问题讨论】:

  • 如果您提供一个或两个无法按预期工作的 URL 示例,将会有所帮助。
  • 当我尝试 https:///testresource.xml 时,系统会重定向到认证页面。
  • 那么 Keerthi Ramanathan 已经给你答案了。
  • 我认为这不能回答问题。 xml 文件位于 web-app 根目录中。据我所知,我没有任何重叠的路径。
  • 是的,您确实有重叠模式。 /testresource.xml 匹配 /* 和 *./xml

标签: java servlets web.xml security-constraint


【解决方案1】:

您的其他 URL 模式之一与此 url-pattern - *.xml requestURI 匹配更多,这就是它不起作用的原因。例如,如果您有/test/list/user.xml,那么这将被视为超级用户区中的网络资源集合,因此SUPER_USER只能访问。因此,请确保 url-pattern 被声明为更特定于资源,以避免冲突和误解。谢谢

【讨论】:

  • 你能修复它吗?
【解决方案2】:

其实放的顺序是有问题的,首先安全约束应该是super_user,然后是公共区域安全约束。如果您放置的安全约束属于公共区域,它将被随后的安全约束覆盖。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多