Examples.apt.vm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ~~ Licensed under the Apache License, Version 2.0 (the "License");
  2. ~~ you may not use this file except in compliance with the License.
  3. ~~ You may obtain a copy of the License at
  4. ~~
  5. ~~ http://www.apache.org/licenses/LICENSE-2.0
  6. ~~
  7. ~~ Unless required by applicable law or agreed to in writing, software
  8. ~~ distributed under the License is distributed on an "AS IS" BASIS,
  9. ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. ~~ See the License for the specific language governing permissions and
  11. ~~ limitations under the License. See accompanying LICENSE file.
  12. ---
  13. Hadoop Auth, Java HTTP SPNEGO ${project.version} - Examples
  14. ---
  15. ---
  16. ${maven.build.timestamp}
  17. Hadoop Auth, Java HTTP SPNEGO ${project.version} - Examples
  18. * Accessing a Hadoop Auth protected URL Using a browser
  19. <<IMPORTANT:>> The browser must support HTTP Kerberos SPNEGO. For example,
  20. Firefox or Internet Explorer.
  21. For Firefox access the low level configuration page by loading the
  22. <<<about:config>>> page. Then go to the
  23. <<<network.negotiate-auth.trusted-uris>>> preference and add the hostname or
  24. the domain of the web server that is HTTP Kerberos SPNEGO protected (if using
  25. multiple domains and hostname use comma to separate them).
  26. * Accessing a Hadoop Auth protected URL Using <<<curl>>>
  27. <<IMPORTANT:>> The <<<curl>>> version must support GSS, run <<<curl -V>>>.
  28. +---+
  29. $ curl -V
  30. curl 7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
  31. Protocols: tftp ftp telnet dict ldap http file https ftps
  32. Features: GSS-Negotiate IPv6 Largefile NTLM SSL libz
  33. +---+
  34. Login to the KDC using <<kinit>> and then use <<<curl>>> to fetch protected
  35. URL:
  36. +---+
  37. $ kinit
  38. Please enter the password for tucu@LOCALHOST:
  39. $ curl --negotiate -u foo -b ~/cookiejar.txt -c ~/cookiejar.txt http://localhost:8080/hadoop-auth-examples/kerberos/who
  40. Enter host password for user 'tucu':
  41. Hello Hadoop Auth Examples!
  42. +---+
  43. * The <<<--negotiate>>> option enables SPNEGO in <<<curl>>>.
  44. * The <<<-u foo>>> option is required but the user ignored (the principal
  45. that has been kinit-ed is used).
  46. * The <<<-b>>> and <<<-c>>> are use to store and send HTTP Cookies.
  47. * Using the Java Client
  48. Use the <<<AuthenticatedURL>>> class to obtain an authenticated HTTP
  49. connection:
  50. +---+
  51. ...
  52. URL url = new URL("http://localhost:8080/hadoop-auth/kerberos/who");
  53. AuthenticatedURL.Token token = new AuthenticatedURL.Token();
  54. ...
  55. HttpURLConnection conn = new AuthenticatedURL(url, token).openConnection();
  56. ...
  57. conn = new AuthenticatedURL(url, token).openConnection();
  58. ...
  59. +---+
  60. * Building and Running the Examples
  61. Download Hadoop-Auth's source code, the examples are in the
  62. <<<src/main/examples>>> directory.
  63. ** Server Example:
  64. Edit the <<<hadoop-auth-examples/src/main/webapp/WEB-INF/web.xml>>> and set the
  65. right configuration init parameters for the <<<AuthenticationFilter>>>
  66. definition configured for Kerberos (the right Kerberos principal and keytab
  67. file must be specified). Refer to the {{{./Configuration.html}Configuration
  68. document}} for details.
  69. Create the web application WAR file by running the <<<mvn package>>> command.
  70. Deploy the WAR file in a servlet container. For example, if using Tomcat,
  71. copy the WAR file to Tomcat's <<<webapps/>>> directory.
  72. Start the servlet container.
  73. ** Accessing the server using <<<curl>>>
  74. Try accessing protected resources using <<<curl>>>. The protected resources
  75. are:
  76. +---+
  77. $ kinit
  78. Please enter the password for tucu@LOCALHOST:
  79. $ curl http://localhost:8080/hadoop-auth-examples/anonymous/who
  80. $ curl http://localhost:8080/hadoop-auth-examples/simple/who?user.name=foo
  81. $ curl --negotiate -u foo -b ~/cookiejar.txt -c ~/cookiejar.txt http://localhost:8080/hadoop-auth-examples/kerberos/who
  82. +---+
  83. ** Accessing the server using the Java client example
  84. +---+
  85. $ kinit
  86. Please enter the password for tucu@LOCALHOST:
  87. $ cd examples
  88. $ mvn exec:java -Durl=http://localhost:8080/hadoop-auth-examples/kerberos/who
  89. ....
  90. Token value: "u=tucu,p=tucu@LOCALHOST,t=kerberos,e=1295305313146,s=sVZ1mpSnC5TKhZQE3QLN5p2DWBo="
  91. Status code: 200 OK
  92. You are: user[tucu] principal[tucu@LOCALHOST]
  93. ....
  94. +---+