apache - Tomcat保护文件

标签 apache tomcat webserver protection

有谁知道tomcat是否能够用密码保护文件(例如apache .htaccess)?
我的意思是,当用户从tomcat webapp请求文件时,它会提示对话框输入用户名和密码,并使用配置进行设置。

还是根据文件的IP地址来保护文件。

希望可以有人帮帮我 ?

饭团

最佳答案

您可以在tomcat中设置基本身份验证。

将您的用户添加到tomcat-users.xml。就像是 :

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="myname" password="mypassword" roles="tomcat"/>
  <user username="test" password="test"/>
</tomcat-users>


并将配置添加到您的应用程序web.xml。喜欢:

<!-- Define a Security Constraint on this Application -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Entire Application</web-resource-name>
      <url-pattern>/references/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>your-role</role-name>
    </auth-constraint>
  </security-constraint>

  <!-- Define the Login Configuration for this Application -->
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Application</realm-name>
  </login-config>

  <!-- Security roles referenced by this web application -->
  <security-role>
    <description>
      The role that is required to log in to the Manager Application
    </description>
    <role-name>your-role</role-name>
  </security-role>


链接以了解更多信息:

http://www.avajava.com/tutorials/lessons/how-do-i-use-basic-authentication-with-tomcat.html

关于apache - Tomcat保护文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3355121/

相关文章:

PHP代码没有被执行,但是代码显示在浏览器源代码中

apache - 阻止 mp3 文件在浏览器中流式传输

html - 为什么这个 http 对话有 10 秒的延迟?

javascript - 使用 Apache 的 mod_proxy_wstunnel 连接到 PHP,而不使用第 3 方 API

linux - grepping 数据 Apache access.log

tomcat - 具有多个域的 Spring MVC

shell - Jenkins war 部署

tomcat - 当 TomEE 从他们的启动脚本启动但从 IntelliJ 失败时可以找到资源(图像)

apache - 如何从网络服务器调用本地 shell 脚本?

linux - 如何监控和记录 mt apache 网络服务器的 session