tomcat 中BASIC and FORM-based Authorization 配置

Tomcat中自身具有认证功能,配置也比较简单,步骤如下:
1、在所在web项目的web.xml文件添加如下配置代码:
<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/jsp/*</url-pattern>
<!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area -->
<role-name>gallop</role-name>
</auth-constraint>
</security-constraint>
<!-- Define the Login Configuration for this Application -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Tomcat Host Manager Application</realm-name>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
<role-name>gallop</role-name>
</security-role>
2、在tomcat的安装目录下的conf下,找到tomcat-users.xml文件,添加相关的用户名:
<role rolename="gallop"/>
<user username="gallop" password="123456" roles="gallop"/>
3、重新启动tomcat后,访问该项目jsp目录下的jsp页面时将弹出登入框,提示需要用户名、密码方可访问相关页面。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值