微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

静态资源的正确路径,以便从授权约束中省略它们

如何解决静态资源的正确路径,以便从授权约束中省略它们

我有一个使用 websphere 的 java ee-struts 应用程序,如果用户登录,一切都会受到限制。即使是 css 和图像之类的静态资源。我想对两件事不限制访问,style.cssblue_logo.gif 文件,以便它们无需注册即可使用。我发现这篇文章 here 显示了如何做到这一点,但我不知道如何编写确切的路径来指定我需要的 2 个资源中的每一个。有人可以根据以下内容为我提供确切的路径我提供的文件夹结构?谢谢

这是我拥有的代码,它限制了一切。这是来自位于我的模块的 WEB-INF 文件夹中的 web.xml 文件

<security-constraint>
   <display-name>ABC_Access<display-name>
   <web-resource-collection>
       <web-resource-name>All_resources</web-resource-name>
       <url-pattern>/*</url-pattern>
   <web-resource-collection>
   <auth-constraint>
       <description>all_authent</description>
       <role-name>all</role-name>
   </auth-constraint>
</security-constraint>

我的文件夹结构是:

src>main>webapp>WEB-INF>web.xml
               >css>style.css
               >images>blue_logo.gif

解决方法

您应该有这样的附加约束,没有 auth-constraint。检查这个 - “如果没有授权约束,容器必须接受请求而不需要用户身份验证。” Specifying an Authorization Constraint

<security-constraint>
   <display-name>Unprotected resources<display-name>
   <web-resource-collection>
       <web-resource-name>unprotected_resources</web-resource-name>
       <url-pattern>/images/*</url-pattern>
       <url-pattern>/css/*</url-pattern>
   <web-resource-collection>
    <!-- do not provide auth-constraint -->
</security-constraint>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。