Class: WebHDFS::Kerberos
- Inherits:
-
Object
- Object
- WebHDFS::Kerberos
- Defined in:
- lib/webhdfs/kerberos.rb
Overview
Kerberos class for http requests
Instance Method Summary collapse
-
#autorization(header) ⇒ Object
Set the token to header authorization.
- #check_response(response) ⇒ Object
-
#initialize(host, keytab) ⇒ Kerberos
constructor
Constructor.
Constructor Details
#initialize(host, keytab) ⇒ Kerberos
Constructor
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/webhdfs/kerberos.rb', line 12 def initialize(host, keytab) @host = host @keytab = keytab @gsscli = GSSAPI::Simple.new(@host, 'HTTP', @kerberos_keytab) @token = nil begin @token = @gsscli.init_context rescue => token_error raise WebHDFS::KerberosError, token_error. end end |
Instance Method Details
#autorization(header) ⇒ Object
Set the token to header authorization
26 27 28 29 30 31 32 33 34 |
# File 'lib/webhdfs/kerberos.rb', line 26 def autorization(header) encoded_token = Base64.strict_encode64(@token) if header header['Authorization'] = "Negotiate #{encoded_token}" else header = { 'Authorization' => "Negotiate #{encoded_token}" } end header end |
#check_response(response) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/webhdfs/kerberos.rb', line 36 def check_response(response) if @kerberos && response.code == '307' itok = (response.header.get_fields('WWW-Authenticate') || ['']).pop.split(/\s+/).last unless itok raise WebHDFS::KerberosError, 'Server does not return ' \ 'WWW-Authenticate header' end begin @gsscli.init_context(Base64.strict_decode64(itok)) rescue => e raise WebHDFS::KerberosError, e. end end end |