Thursday, June 15, 2017

every one access tomcat web directory add authentication

i want to add xxx web directory in tomcat with specify user and password access.

webapps/xxx/WEB-INF/web.xml:
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>HTML Manager interface (for humans)</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>manager-my</role-name>
    </auth-constraint>
  </security-constraint> 
   <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Tomcat Manager Application</realm-name>
  </login-config>

conf/tomcat-users.xml:
  
<role rolename="manager-my">
  <user password="hx98.com.cn" roles="manager-my" username="hx98">
</user></role>

restart tomcat . ok!

No comments: