首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当返回'403禁止‘时,如何处理本地js/css文件的web.xml授权?

当返回'403禁止‘时,如何处理本地js/css文件的web.xml授权?
EN

Stack Overflow用户
提问于 2016-11-01 09:00:32
回答 1查看 758关注 0票数 0

我有一个网站,只有获得授权的人才能进入。如果有人没有授权,我的web.xml将他们重定向到一个403个错误页面。

但是,我的应用程序和错误页面都使用一些外部js和css文件(例如引导)。从逻辑上讲,403错误页不能访问这些js/css文件,因为除了错误页html之外,所有内容都禁止使用权限。

我该如何巧妙地解决这个问题呢?我应该公开我的库文件夹吗?如果是这样,我如何才能覆盖特定文件夹的安全规则?

我浏览了一下这里的文件,但是我没有看到提到过这个场景。我认为我必须在"/libraries“中添加一个安全约束,并以某种方式覆盖HTTP所需的角色?

我的web.xml的潜在相关部分:

代码语言:javascript
复制
    <error-page>
        <error-code>403</error-code>
        <location>/errorPages/forbidden.jsp</location>
    </error-page>

  <security-role>
    <role-name>myRole</role-name>
  </security-role>

  <security-constraint>
    <display-name>MySecurityConstraint</display-name>
    <web-resource-collection>
      <web-resource-name>WebResource</web-resource-name>
      <url-pattern>/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>DELETE</http-method>
      <http-method>PUT</http-method>
      <http-method>HEAD</http-method>
      <http-method>OPTIONS</http-method>
      <http-method>POST</http-method>     
    </web-resource-collection>
    <auth-constraint>
      <role-name>myRole</role-name>
    </auth-constraint>
    <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-01 14:46:37

您可以简单地添加一个额外的安全约束,其中包含详细的路径,并且不需要auth约束。

代码语言:javascript
复制
<security-constraint>
    <display-name>NoSecurityConstraint</display-name>
    <web-resource-collection>
      <web-resource-name>WebResource</web-resource-name>
      <url-pattern>/library/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>DELETE</http-method>
      <http-method>PUT</http-method>
      <http-method>HEAD</http-method>
      <http-method>OPTIONS</http-method>
      <http-method>POST</http-method>     
    </web-resource-collection>
  </security-constraint>

我希望这能解决你的问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40356851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档