【问题标题】:Tomcat Protect filesTomcat 保护文件
【发布时间】:2010-07-28 16:30:27
【问题描述】:

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

或保护文件取决于其 IP 地址。

希望有人能帮助我吗?

推荐

【问题讨论】:

  • 我的回答对你有帮助吗? :) 如果是,请接受它作为答案。
  • 有没有办法使用 ip 地址来 preotec 应用程序

标签: apache tomcat webserver protection


【解决方案1】:

您可以在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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 2010-11-18
    • 1970-01-01
    • 2011-02-26
    • 2014-05-02
    相关资源
    最近更新 更多