我正在使用(JSP Servlet)开发Web应用程序,并且我使用Tomcat 7.0.33作为Web容器.
所以我的要求是tomcat中的每个应用程序都将受到密码保护,就像tomcat中的管理器应用程序受到保护一样.
到目前为止,我做了以下事情:
server.xml中
<Realm className="org.apache.catalina.realm.MemoryRealm" />
的tomcat-users.xml中
<tomcat-users> <role rolename="tomcat"/> <role rolename="manager-gui"/> <role rolename="role1" /> <user username="tomcat" password="tomcat" roles="role1,tomcat,manager-gui"/> <user username="role1" password="tomcat" roles="role1"/> </tomcat-users>
web.xml中
<security-role> <role-name>role1</role-name> </security-role> <security-role> <role-name>tomcat</role-name> </security-role> <security-constraint> <web-resource-collection> <web-resource-name>webappname</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>role1</role-name> <role-name>tomcat</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>webappname</realm-name> </login-config>
当任何人通过应用程序路径打开应用程序时它工作正常(它要求输入用户名和密码,并且应用程序接受role1或tomcat进行身份验证).
但问题是假设我以具有所有角色的用户tomcat身份登录,并且当显示管理器屏幕列出了服务器上部署的所有应用程序时,如果我尝试打开mywebapplication,那么它再次要求输入用户名和密码.
我的问题是,如果我已将所有角色分配给用户tomcat,那么如果我以tomcat身份登录,为什么要求输入密码?有什么方法可以避免这种情况吗?
提前致谢.