配置摘要式身份验证

介绍

现成的geoserver rest和ogc服务支持通过 HTTP Basic authentication .基本认证的主要缺点之一是它以纯文本形式发送用户密码。 HTTP Digest authentication 提供了一种更安全的替代方法,即在通过网络发送密码之前对密码应用加密哈希函数。

本教程将介绍设置摘要式身份验证的过程。

先决条件

本教程使用 curl 实用程序发出测试身份验证的HTTP请求。继续之前安装curl。

备注

任何既支持基本身份验证又支持摘要式身份验证的实用程序都可以用来代替curl。大多数现代Web浏览器都支持这两种类型的身份验证。

配置摘要式身份验证筛选器

  1. 启动geoserver并以 admin 用户。

  2. 单击 Authentication 链接位于 Security 导航边栏的部分。

    ../../../_images/digest11.jpg
  3. 向下滚动到 Authentication Filters 面板并单击 Add new 链接。

    ../../../_images/digest21.jpg
  4. 单击 Digest 链接。

    ../../../_images/digest31.jpg
  5. 按如下方式填写设置表单的字段:

    • 集合 Name 到“摘要”

    • 集合 User group service 到“默认”

    ../../../_images/digest41.jpg
  6. 保存。

  7. 返回“身份验证”页,向下滚动到 Filter Chains 面板。

  8. 从中选择“默认” Request type 下拉。

  9. 取消选择 basic 筛选并选择 digest 过滤。定位 digest 过滤前 anonymous 过滤器。

    ../../../_images/digest51.jpg
  10. 保存。

安全OGC服务请求

为了测试上一节中配置的身份验证设置,必须首先保护服务或资源。这个 Default 过滤链是应用于所有OGC服务请求的链,因此必须配置服务安全规则。

  1. 从GeoServer主页单击 Services 链接位于 Security 导航边栏的部分。

    ../../../_images/digest6.jpg
  2. 在“服务安全”页上,单击 Add new rule 链接并添加一个catch all规则,用于保护所有需要 ROLE_ADMINISTRATOR 角色。

    ../../../_images/digest7.jpg
  3. 保存。

测试摘要式身份验证登录

  1. 确保禁用基本身份验证。执行以下curl命令::

    curl -v -u admin:geoserver -G "http://localhost:8080/geoserve/wfs?request=getcapabilities"
    

    结果应该是401响应,它发出需要身份验证的信号。输出应该如下所示:

    * About to connect() to localhost port 8080 (#0)
    *   Trying 127.0.0.1... connected
    * Connected to localhost (127.0.0.1) port 8080 (#0)
    * Server auth using Basic with user 'admin'
    > GET /geoserver/wfs?request=getcapabilities HTTP/1.1
    > Authorization: Basic YWRtaW46Z2Vvc2VydmVy
    > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3
    > Host: localhost:8080
    > Accept: */*
    >
    < HTTP/1.1 401 Full authentication is required to access this resource
    < Set-Cookie: JSESSIONID=1dn2bi8qqu5qc;Path=/geoserver
    < WWW-Authenticate: Digest realm="GeoServer Realm", qop="auth", nonce="MTMzMzQzMDkxMTU3MjphZGIwMWE4MTc1NmRiMzI3YmFiODhmY2NmZGQ2MzEwZg=="
    < Content-Type: text/html; charset=iso-8859-1
    < Content-Length: 1491
    < Server: Jetty(6.1.8)
    <
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    <title>Error 401 Full authentication is required to access this resource</title>
    </head>
    ...
    
  2. 执行相同的命令,但指定 --digest 告诉curl使用摘要式身份验证而不是基本身份验证的选项:

    curl --digest -v -u admin:geoserver -G "http://localhost:8080/geoserver/wfs?request=getcapabilities"
    

    结果应该是成功的身份验证,并包含正常的WFS功能响应。