|
|
将webapps\ROOT\WEB-INF目录下的web.xml文件复制到要做BasicAuth认证应用的 WEB-INF目录中(例:webapps\designer\WEB-INF)
在web.xml文件中将以下代码放置在web-app标签内
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>protected Resource</web-resource-name>
- <url-pattern>/designer/*</url-pattern>
- </web-resource-collection>
-
- <auth-constraint>
- <role-name>test</role-name>
- </auth-constraint>
- </security-constraint>
-
- <login-config>
- <auth-method>BASIC</auth-method>
- <realm-name>Default</realm-name>
- </login-config>
复制代码
web-resource-name 是与受保护资源相关联的名称。
url-pattern 是要是受保护资源的路径
role-name 是指定可以访问该资源集合的用户角色。
在tomcat\conf\tomcat-users.xml文件中将内容放置在tomcat-users标签内
- <role rolename="test"/>
- <user username="账号" password="密码" roles="test"/>
复制代码
Rolename,roles是对应web.xml中的(role-name)角色
账号,密码自行设置
以上配置完成后,重启tomcat
|
|