重要提示:浏览器必须支持HTTP Kerberos SPNEGO协议,例如Firefox或Internet Explorer。
对于Firefox浏览器,通过加载about:config
页面访问底层配置页。然后找到network.negotiate-auth.trusted-uris
首选项,添加受HTTP Kerberos SPNEGO保护的Web服务器主机名或域名(若使用多个域名和主机名,请用逗号分隔)。
curl
访问受Hadoop Auth保护的URL重要提示: curl
版本必须支持 GSS,请运行 curl -V
。
$ curl -V curl 7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3 Protocols: tftp ftp telnet dict ldap http file https ftps Features: GSS-Negotiate IPv6 Largefile NTLM SSL libz
使用 kinit 登录 KDC,然后使用 curl
获取受保护的 URL:
$ kinit Please enter the password for tucu@LOCALHOST: $ curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://$(hostname -f):8080/hadoop-auth-examples/kerberos/who Enter host password for user 'tucu': Hello Hadoop Auth Examples!
--negotiate
选项可在 curl
中启用 SPNEGO 功能。
-u :
选项是必需的,但用户忽略了(将使用已通过kinit认证的主体)。
参数 -b
和 -c
用于存储和发送HTTP Cookies。
使用AuthenticatedURL
类获取经过身份验证的HTTP连接:
... URL url = new URL("http://localhost:8080/hadoop-auth/kerberos/who"); AuthenticatedURL.Token token = new AuthenticatedURL.Token(); ... HttpURLConnection conn = new AuthenticatedURL().openConnection(url, token); ... conn = new AuthenticatedURL().openConnection(url, token); ...
下载Hadoop-Auth的源代码,示例位于src/main/examples
目录中。
编辑hadoop-auth-examples/src/main/webapp/WEB-INF/web.xml
文件,并为配置为Kerberos的AuthenticationFilter
定义设置正确的配置初始化参数(必须指定正确的Kerberos主体和keytab文件)。详情请参阅配置文档。
通过运行mvn package
命令创建web应用程序WAR文件。
将WAR文件部署到servlet容器中。例如,如果使用Tomcat,将WAR文件复制到Tomcat的webapps/
目录。
启动servlet容器。
curl
访问服务器尝试使用curl
访问受保护资源。受保护的资源包括:
$ kinit Please enter the password for tucu@LOCALHOST: $ curl http://localhost:8080/hadoop-auth-examples/anonymous/who $ curl http://localhost:8080/hadoop-auth-examples/simple/who?user.name=foo $ curl --negotiate -u : -b ~/cookiejar.txt -c ~/cookiejar.txt http://$(hostname -f):8080/hadoop-auth-examples/kerberos/who
$ kinit Please enter the password for tucu@LOCALHOST: $ cd examples $ mvn exec:java -Durl=http://localhost:8080/hadoop-auth-examples/kerberos/who .... Token value: "u=tucu,p=tucu@LOCALHOST,t=kerberos,e=1295305313146,s=sVZ1mpSnC5TKhZQE3QLN5p2DWBo=" Status code: 200 OK You are: user[tucu] principal[tucu@LOCALHOST] ....