gpt4 book ai didi

apache - Tomcat保护文件

转载 作者:行者123 更新时间:2023-11-28 22:07:14 25 4
gpt4 key购买 nike

有谁知道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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com