Examples.apt.vm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. \[ {{{./index.html}Go Back}} \]
  19. * Accessing a Hadoop Auth protected URL Using a browser
  20. <<IMPORTANT:>> The browser must support HTTP Kerberos SPNEGO. For example,
  21. Firefox or Internet Explorer.
  22. For Firefox access the low level configuration page by loading the
  23. <<<about:config>>> page. Then go to the
  24. <<<network.negotiate-auth.trusted-uris>>> preference and add the hostname or
  25. the domain of the web server that is HTTP Kerberos SPNEGO protected (if using
  26. multiple domains and hostname use comma to separate them).
  27. * Accessing a Hadoop Auth protected URL Using <<<curl>>>
  28. <<IMPORTANT:>> The <<<curl>>> version must support GSS, run <<<curl -V>>>.
  29. +---+
  30. $ curl -V
  31. curl 7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
  32. Protocols: tftp ftp telnet dict ldap http file https ftps
  33. Features: GSS-Negotiate IPv6 Largefile NTLM SSL libz
  34. +---+
  35. Login to the KDC using <<kinit>> and then use <<<curl>>> to fetch protected
  36. URL:
  37. +---+
  38. $ kinit
  39. Please enter the password for tucu@LOCALHOST:
  40. $ curl --negotiate -u foo -b ~/cookiejar.txt -c ~/cookiejar.txt http://localhost:8080/hadoop-auth-examples/kerberos/who
  41. Enter host password for user 'tucu':
  42. Hello Hadoop Auth Examples!
  43. +---+
  44. * The <<<--negotiate>>> option enables SPNEGO in <<<curl>>>.
  45. * The <<<-u foo>>> option is required but the user ignored (the principal
  46. that has been kinit-ed is used).
  47. * The <<<-b>>> and <<<-c>>> are use to store and send HTTP Cookies.
  48. * Using the Java Client
  49. Use the <<<AuthenticatedURL>>> class to obtain an authenticated HTTP
  50. connection:
  51. +---+
  52. ...
  53. URL url = new URL("http://localhost:8080/hadoop-auth/kerberos/who");
  54. AuthenticatedURL.Token token = new AuthenticatedURL.Token();
  55. ...
  56. HttpURLConnection conn = new AuthenticatedURL(url, token).openConnection();
  57. ...
  58. conn = new AuthenticatedURL(url, token).openConnection();
  59. ...
  60. +---+
  61. * Building and Running the Examples
  62. Download Hadoop-Auth's source code, the examples are in the
  63. <<<src/main/examples>>> directory.
  64. ** Server Example:
  65. Edit the <<<hadoop-auth-examples/src/main/webapp/WEB-INF/web.xml>>> and set the
  66. right configuration init parameters for the <<<AuthenticationFilter>>>
  67. definition configured for Kerberos (the right Kerberos principal and keytab
  68. file must be specified). Refer to the {{{./Configuration.html}Configuration
  69. document}} for details.
  70. Create the web application WAR file by running the <<<mvn package>>> command.
  71. Deploy the WAR file in a servlet container. For example, if using Tomcat,
  72. copy the WAR file to Tomcat's <<<webapps/>>> directory.
  73. Start the servlet container.
  74. ** Accessing the server using <<<curl>>>
  75. Try accessing protected resources using <<<curl>>>. The protected resources
  76. are:
  77. +---+
  78. $ kinit
  79. Please enter the password for tucu@LOCALHOST:
  80. $ curl http://localhost:8080/hadoop-auth-examples/anonymous/who
  81. $ curl http://localhost:8080/hadoop-auth-examples/simple/who?user.name=foo
  82. $ curl --negotiate -u foo -b ~/cookiejar.txt -c ~/cookiejar.txt http://localhost:8080/hadoop-auth-examples/kerberos/who
  83. +---+
  84. ** Accessing the server using the Java client example
  85. +---+
  86. $ kinit
  87. Please enter the password for tucu@LOCALHOST:
  88. $ cd examples
  89. $ mvn exec:java -Durl=http://localhost:8080/hadoop-auth-examples/kerberos/who
  90. ....
  91. Token value: "u=tucu,p=tucu@LOCALHOST,t=kerberos,e=1295305313146,s=sVZ1mpSnC5TKhZQE3QLN5p2DWBo="
  92. Status code: 200 OK
  93. You are: user[tucu] principal[tucu@LOCALHOST]
  94. ....
  95. +---+
  96. \[ {{{./index.html}Go Back}} \]