配置摘要式身份验证¶
介绍¶
现成的geoserver rest和ogc服务支持通过 HTTP Basic authentication .基本认证的主要缺点之一是它以纯文本形式发送用户密码。 HTTP Digest authentication 提供了一种更安全的替代方法,即在通过网络发送密码之前对密码应用加密哈希函数。
本教程将介绍设置摘要式身份验证的过程。
先决条件¶
本教程使用 curl 实用程序发出测试身份验证的HTTP请求。继续之前安装curl。
备注
任何既支持基本身份验证又支持摘要式身份验证的实用程序都可以用来代替curl。大多数现代Web浏览器都支持这两种类型的身份验证。
配置摘要式身份验证筛选器¶
启动geoserver并以
admin用户。单击
Authentication链接位于Security导航边栏的部分。
向下滚动到
Authentication Filters面板并单击Add new链接。
单击
Digest链接。
按如下方式填写设置表单的字段:
集合
Name到“摘要”集合
User group service到“默认”
保存。
返回“身份验证”页,向下滚动到
Filter Chains面板。从中选择“默认”
Request type下拉。取消选择
basic筛选并选择digest过滤。定位digest过滤前anonymous过滤器。
保存。
安全OGC服务请求¶
为了测试上一节中配置的身份验证设置,必须首先保护服务或资源。这个 Default 过滤链是应用于所有OGC服务请求的链,因此必须配置服务安全规则。
从GeoServer主页单击
Services链接位于Security导航边栏的部分。
在“服务安全”页上,单击
Add new rule链接并添加一个catch all规则,用于保护所有需要ROLE_ADMINISTRATOR角色。
保存。
测试摘要式身份验证登录¶
确保禁用基本身份验证。执行以下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> ...
执行相同的命令,但指定
--digest告诉curl使用摘要式身份验证而不是基本身份验证的选项:curl --digest -v -u admin:geoserver -G "http://localhost:8080/geoserver/wfs?request=getcapabilities"
结果应该是成功的身份验证,并包含正常的WFS功能响应。