今天主要练习了tomcat下访问认证的设置,也更深入一点的了解了tomcat-user.xml
首先在$CATALINA_HOME/conf/tomcat-users.xml中添加用来登陆指定webapps的用户,如下
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="manager"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="manager" password="manager" roles="manager"/>
</tomcat-users>
之后在需要添加登陆认证的webapps下修改其web.xml文件,这里以tomcat自带的examples为例,修改$CATALINA_HOME/webapps/examples/WEB-INF/web.xml,添加(修改)security-constraint字段,如下
<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST<