Featured image of post tomcat配置basic_auth控制应用权限

tomcat配置basic_auth控制应用权限

${tomcat_webapps}/${APP}/WEB-INF/web.xml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="WebApp_ID" version="3.0">
        <!-- 省略 -->

        <security-constraint>
                <web-resource-collection>
                        <web-resource-name>Entire Application</web-resource-name> <!-- 起标识作用,自己取-->
                        <url-pattern>/*</url-pattern> <!-- 可以自己定义类型 -->
                </web-resource-collection>
                <auth-constraint>
                        <role-name>manager</role-name>
                </auth-constraint>
        </security-constraint>

        <login-config>
                <auth-method>BASIC</auth-method>
                <realm-name>GeoSmarter DUP Application</realm-name> <!-- 起标识作用,自己取-->
        </login-config>

        <security-role>
                <role-name>manager</role-name>
        </security-role>

        <!-- 后面是welcome-file-list-->
</web-app>

${tomcat_home}/conf/tomcat_user.xml:

1
2
3
4
5
6
7
8
<tomcat-users xmlns="http://tomcat.apache.org/xml"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
        version="1.0">
        <!-- 省略 -->
        <role rolename="manager" />
        <user username="你的用户名" password="你的密码" roles="manager" />
</tomcat-users>