如何配置Tomcat-users.xml中在Tomcat中,以确保一个页面?(How to conf

2019-08-19 14:02发布

我想,以确保在我的tomcat的管理页面与web.xmltomcat-users.xml ,但它不工作。 登录表单显示,但连接是不可能的

下面是web.xml在我的web / WEB_INF文件夹:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Admin</web-resource-name>
        <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Admin</realm-name>
</login-config>

tomcat-users.xml的服务器/ tomcat的/ conf目录/文件夹:

<tomcat-users>
   <role rolename="manager"/>
   <role rolename="tomcat"/>
   <role rolename="admin"/>
   <role rolename="role1"/>
   <user username="manager" password="manager" roles="manager"/>
   <user username="both" password="tomcat" roles="tomcat,role1"/>
   <user username="tomcat" password="tomcat" roles="tomcat"/>
   <user username="role1" password="tomcat" roles="role1"/>
   <user username="admin" password="admin" roles="admin"/>
</tomcat-users>

任何的想法 ?

Answer 1:

也许来不及回答,但反正你是在你的web.xml缺少的角色,也不要不得不提的境界,因此你的web.xml看起来应该像如下

<security-constraint>
   <web-resource-collection>
      <web-resource-name>Admin</web-resource-name>
      <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>admin</role-name>
    </auth-constraint>
 </security-constraint>
 <login-config>
       <auth-method>BASIC</auth-method>
      <!-- Please note following line .. its commented -->
      <!-- <realm-name>Admin</realm-name> -->
 </login-config>
 <!-- Following section was missing -->
 <security-role>
     <role-name>admin</role-name>
</security-role>


文章来源: How to configure tomcat-users.xml to secure a page in tomcat?