tomcat安全验证

来源:互联网 发布:淘宝商城衣服女装新款 编辑:程序博客网 时间:2024/05/18 02:00

使用basic方式验证,需要做一下修改

1.修改server.xml,打开需要使用的验证方式,我在这里用的是

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

2.修改tomcat-users.xml添加用户及规则名称

<role rolename="tomcat"/>

<user username="tomcat" password="tomcat" roles="tomcat,role1"/>//该用户可以匹配两个规则

3.修改web.xlm

<security-role>
   <role-name>tomcat</role-name> 此处指要应用到该项目的规则名称
</security-role>
  <security-constraint>
        <display-name>The Protected Area</display-name>  描述名称
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name> 描述名称
            <url-pattern>/*</url-pattern> 那些url需要验证权限
        </web-resource-collection>
        <auth-constraint>
            <role-name>tomcat</role-name> 此处指要应用到该项目的规则名称
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>使用的验证方式
        <realm-name>login</realm-name> 验证提示字符串
    </login-config>

原创粉丝点击