Class: HTTPClient::NegotiateAuth
- Inherits:
-
Object
- Object
- HTTPClient::NegotiateAuth
- Defined in:
- lib/httpclient.rb
Overview
HTTPClient::NegotiateAuth
Instance Attribute Summary collapse
-
#ntlm_opt ⇒ Object
readonly
Returns the value of attribute ntlm_opt.
-
#scheme ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #challenge(uri, param_str) ⇒ Object
- #get(req) ⇒ Object
-
#initialize ⇒ NegotiateAuth
constructor
A new instance of NegotiateAuth.
- #reset_challenge ⇒ Object
- #set(uri, user, passwd) ⇒ Object
Constructor Details
#initialize ⇒ NegotiateAuth
Returns a new instance of NegotiateAuth.
529 530 531 532 533 534 535 536 537 |
# File 'lib/httpclient.rb', line 529 def initialize @auth = {} @auth_default = nil @challenge = {} @scheme = "Negotiate" @ntlm_opt = { :ntlmv2 => true } end |
Instance Attribute Details
#ntlm_opt ⇒ Object (readonly)
Returns the value of attribute ntlm_opt.
527 528 529 |
# File 'lib/httpclient.rb', line 527 def ntlm_opt @ntlm_opt end |
#scheme ⇒ Object (readonly)
:nodoc:
526 527 528 |
# File 'lib/httpclient.rb', line 526 def scheme @scheme end |
Instance Method Details
#challenge(uri, param_str) ⇒ Object
580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/httpclient.rb', line 580 def challenge(uri, param_str) return false unless NTLMEnabled if param_str.nil? or @challenge[uri].nil? c = @challenge[uri] = {} c[:state] = :init c[:authphrase] = "" else c = @challenge[uri] c[:state] = :response c[:authphrase] = param_str end true end |
#get(req) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/httpclient.rb', line 552 def get(req) return nil unless NTLMEnabled target_uri = req.header.request_uri param = Util.hash_find_value(@challenge) { |uri, param| Util.uri_part_of(target_uri, uri) } return nil unless param user, passwd = Util.hash_find_value(@auth) { |uri, auth_data| Util.uri_part_of(target_uri, uri) } unless user user, passwd = @auth_default end return nil unless user state = param[:state] authphrase = param[:authphrase] case state when :init t1 = Net::NTLM::Message::Type1.new return t1.encode64 when :response t2 = Net::NTLM::Message.decode64(authphrase) t3 = t2.response({:user => user, :password => passwd}, @ntlm_opt) return t3.encode64 end nil end |
#reset_challenge ⇒ Object
539 540 541 |
# File 'lib/httpclient.rb', line 539 def reset_challenge @challenge.clear end |
#set(uri, user, passwd) ⇒ Object
543 544 545 546 547 548 549 550 |
# File 'lib/httpclient.rb', line 543 def set(uri, user, passwd) if uri uri = Util.uri_dirname(uri) @auth[uri] = [user, passwd] else @auth_default = [user, passwd] end end |