默認tomcat-user.xml中的角色和用戶配置示例如下:
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
<user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
<user username="role1" password="<must-be-changed>" roles="role1"/>
-->
如果僅把上述內容去掉並修改密碼,重啟tomcat后訪問http://localhost:8081/manager/html,會報403 Access Denied無法登錄管理界面。
正確的配置如下:
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="111111" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
原因是tomcat8中定義了以下4種角色,所以配置文件中的角色名稱是不能任意填寫的。
- manager-gui - allows access to the HTML GUI and the status pages
- manager-script - allows access to the text interface and the status pages
- manager-jmx - allows access to the JMX proxy and the status pages
- manager-status - allows access to the status pages only