阻止用户访问资源文件夹中的文件.托管在Apache Tomcat上

Prevent User to access the file in the resource folder .. hosted on Apache Tomcat

本文关键字:Apache Tomcat 文件 用户 访问 资源 文件夹      更新时间:2023-09-26

你好,我的网站地址是

www.abcdef.com/context/index.html

但是用户也可以访问

www.abcdef/context/resources/somPngFile.png

我不想要

(这里的资源是我保存图像文件的文件夹)

此外,我在index.html中做所有的验证和会话检查。如果用户直接从url访问png文件,他就可以得到它。任何关于如何避免这种情况的建议都将不胜感激。我使用apachetomcat作为服务器,并在jquery中进行编码。

我把下面的代码放在web.xml中解决了这个问题。不过谢谢你的评论。。

<security-constraint>
      <web-resource-collection>
          <web-resource-name>HTTP-Protected-Resource-1</web-resource-name>
          <description>Description here</description>
          <url-pattern>/resources/*</url-pattern>
          <http-method>GET</http-method>
          <http-method>POST</http-method>
      </web-resource-collection>
      <auth-constraint>
          <role-name>NOSOUPFORYOU</role-name>
      </auth-constraint>
  </security-constraint>