Tomcat web.xml http basic auth

时间:2016-03-01 00:21:04

标签: http tomcat authentication web.xml

我只想要一些看似简单但对我不起作用的东西:

我在linux上使用tomcat 7。

我有/.../apache-tomcat-7.0.68/webapps/ROOT/admin/*.jsp

我只想用基本的http auth来保护该文件夹中的所有文件。我已尝试使用以下内容编辑/.../apache-tomcat-7.0.68/webapps/ROOT/WEB-INF/web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
 "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

<web-app>
  <security-constraint> 
   <!-- web resources that are protected -->
   <web-resource-collection>
     <web-resource-name>A Protected Page</web-resource-name>
     <url-pattern>/admin/*</url-pattern>
   </web-resource-collection>

   <auth-constraint>
     <!-- role-name indicates roles that are allowed
       to access the web resource specified above -->
     <role-name>tomcat</role-name>
     <role-name>role1</role-name>
   </auth-constraint>
  </security-constraint> 

  <login-config>
   <auth-method>BASIC</auth-method>
   <realm-name>Basic Authentication Example</realm-name>
  </login-config>
</web-app>

不起作用......你有什么想法吗?

0 个答案:

没有答案
相关问题