如何配置 tomcat web.xml 和 tomcat-users.xml 以保护 tomcat 页面



我想用web保护我的管理页面.xml但 tomcat-users.xml.It 不起作用。

这是我的雄猫用户的内容.xml

 <?xml version='1.0' encoding='utf-8'?>
 <tomcat-users>
 <role rolename="webadmin"/>
 <user username="kumar" password="kumar" roles="manager"/>
 </tomcat-users> 

以及WEB-INF/web的内容.xml

    <resource-env-ref>
    <description>abc.com/</description>
    <resource-env-ref-name>player</resource-env-ref-name>
    <resource-env-ref-type>org.apache.catalina.UserDatabase</resource-env-ref-type>
     </resource-env-ref>

     <security-constraint>
     <display-name>player</display-name>
     <web-resource-collection>
     <web-resource-name>personal</web-resource-name>
     <!-- Define the context-relative URL(s) to be protected -->

     <url-pattern>abc.com</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>webadmin</role-name>
  </auth-constraint>
</security-constraint>
<!-- Default login configuration uses form-based authentication -->
<login-config>
     </form-login-config>-->
  <auth-method>BASIC</auth-method>
  <realm-name>player</realm-name>
</login-config>
<!-- Security roles referenced by this web application -->
 <security-role>
<role-name>webadmin</role-name>
 </security-role>

请让我知道这些 XML 中需要添加什么。

就对

tomcat管理器GUI的访问而言,在tomcat-users.xml中没有"管理器"的角色。

您必须指定这些角色之一。

您可以在管理器 Web 应用程序的 web.xml 文件中找到角色名称。可用角色包括:•manager-gui — 访问 HTML 界面。•管理员状态 — 仅访问"服务器状态"页面。•管理器脚本 - 访问本文档中描述的工具友好型纯文本界面以及"服务器状态"页面。•manager-jmx — 访问JMX代理界面和"服务器状态"页面。

查看此链接以获取更多信息,http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

我希望它有所帮助,谢谢。

最新更新