星期二, 十月 12, 2004

Tomcat 的 Basic 认证设置

在WebApp的web.xml中的合适的位置,加上以下一段文字。

<security-constraint>
 <web-resource-collection>
  <web-resource-name>Member Secret Area</web-resource-name>
  <url-pattern>/secret/*</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>UserDatabaseRealm</realm-name>
</login-config>

URL文字符合 /secret/* 模式的JSP或Servlet的网页打开前,就会弹出 Basic 认证的用户名和密码输入窗口。UserDatabaseRealm定义在Tomcat的conf/server.xml中,可以发现用户角色admin实际是定义在conf/tomcat-users.xml中的。

0 Comments:

发表评论

Links to this post:

创建链接

<< Home