2013-04-04 38 views
2

我試圖確保我的管理頁面在tomcat web.xmltomcat-users.xml但它不起作用。登錄表單顯示,但連接是不可能的如何配置tomcat-users.xml來保護tomcat中的頁面?

這裏是我的web/WEB_INF文件夾中的web.xml

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Admin</web-resource-name> 
     <url-pattern>/admin/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>admin</role-name> 
    </auth-constraint> 
</security-constraint> 
<login-config> 
    <auth-method>BASIC</auth-method> 
    <realm-name>Admin</realm-name> 
</login-config> 
在服務器/ tomcat的/ conf目錄/文件夾

而且tomcat-users.xml

<tomcat-users> 
    <role rolename="manager"/> 
    <role rolename="tomcat"/> 
    <role rolename="admin"/> 
    <role rolename="role1"/> 
    <user username="manager" password="manager" roles="manager"/> 
    <user username="both" password="tomcat" roles="tomcat,role1"/> 
    <user username="tomcat" password="tomcat" roles="tomcat"/> 
    <user username="role1" password="tomcat" roles="role1"/> 
    <user username="admin" password="admin" roles="admin"/> 
</tomcat-users> 

任何想法?

回答

9

可能來不及回答,但不管怎麼說 你缺少在你web.xml中的作用,也不要有提境界 因此你的web.xml應該像下面

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Admin</web-resource-name> 
     <url-pattern>/admin/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>admin</role-name> 
    </auth-constraint> 
</security-constraint> 
<login-config> 
     <auth-method>BASIC</auth-method> 
     <!-- Please note following line .. its commented --> 
     <!-- <realm-name>Admin</realm-name> --> 
</login-config> 
<!-- Following section was missing --> 
<security-role> 
    <role-name>admin</role-name> 
</security-role> 
+0

謝謝,這個問題有已經用類似的方法解決了。 – 2013-10-23 09:47:50