请问 我要做摘要式认证 
我要在tomcat中如何配置?

解决方案 »

  1.   

    Tomcat 中可以处理 HTTP BASIC、HTTP DIGEST、FORM BASIC、HTTPS CLIENT-CERT 等四种认证方式。DIGEST 与 BASIC 认证类似,BASIC 浏览器搜集到的用户信息采用 Base64 编码后进行发送,
    而 DIGEST 认证时搜集到的信息浏览器会采用 MD5 进行信息摘要后再发送。具体的需要在 Web 应用的 web.xml 中配置:<security-constraint>
      <web-resource-collection>
        <web-resource-name>protected</web-resource-name>
        <description>用户登陆保护</description>
        <url-pattern>/resource/*</url-pattern>
        <url-pattern>/protected/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>DELETE</http-method>
      </web-resource-collection>
      
      <auth-constraint>
        <role-name>admin</role-name>
        <role-name>manager</role-name>
      </auth-constraint>
    </security-constraint>
      
    <login-config>
      <auth-method>DIGEST</auth-method>
      <realm-name>test digest</realm-name>
    </login-config>上面的配置表明采用 GET、POST 或者 DELETE 方式,如果没有 http-method 时对于所有的 HTTP 请求
    方式都采取验证并且验证用户拥有 admin 或 manager 权限才有权访问 /resource 或者 /protected 下
    的资源。具体的配置说明需要查看 Servlet 规范第 12 章的安全,在这个页面中可以下载到所有版本的 Servlet 规范:
    http://java.sun.com/products/servlet/download.html这样配置之后,在访问这些资源时浏览器会弹出用户凭证搜集框,用于输入用户名和密码,如果正确并且
    拥有适合的权限时可以正常访问,在错误三次之后显示错误!至于如何进行用户名和密码验证,在 Tomcat 5.5.x 中可以采用 6 种方式,最常见的方式是使用内存域,
    即用户信息配置在 tomcat 的 tomcat-users.xml 文件中,这个文件在 tomcat 的 conf 目录下。Tomcat 还提供了 JDBC 域、DataSource 域、JNDI 域、JAAS 域和用户数据库域,具体的可以启动 Tomcat
    后访问:http://localhost:8080/tomcat-docs/realm-howto.html