---
title: "tomcat虚拟主机配置双用户manager"
author: "hlbng"
date: "2009-08-03T15:33:31Z"
tags: []
slug: "tomcat-manager"
draft: false
lastmod: "2009-08-03T15:33:31Z"
id: 438573
url: "https://hlbng.iteye.com/blog/438573"
---

某个Tomcat有两个Host，一和hostA，一个hostB，都给他们了Manager程序，在tomcat-users.xml中写了两个具有manager角色的用户，一个是userA，给hostA使用，另一个是userB，给hostB使用，让他们可以分别登录各自的Manager程序，管理自己的应用。但是，经测试发现,hostB完全可以使用userB进入到hostA的Manager中，反过来也一样，解决方法如下：

```
〈!-- 在你的hostA里manager的web.xml，把your-role替换成你的tomcat-users.xml定义的用户就行了。 --〉

〈!-- Define a Security Constraint on this Application --〉
〈security-constraint〉
〈web-resource-collection〉
〈web-resource-name〉Entire Application〈/web-resource-name〉
〈url-pattern〉/manager/*〈/url-pattern〉
〈/web-resource-collection〉
〈auth-constraint〉
〈role-name〉your-role〈/role-name〉
〈/auth-constraint〉
〈/security-constraint〉

〈!-- Define the Login Configuration for this Application --〉
〈login-config〉
〈auth-method〉BASIC〈/auth-method〉
〈realm-name〉Application〈/realm-name〉
〈/login-config〉

〈!-- Security roles referenced by this web application --〉
〈security-role〉
〈description〉
The role that is required to log in to the Manager Application
〈/description〉
〈role-name〉your-role〈/role-name〉
〈/security-role〉

```