Class: HTTPClient::ProxyAuth

Inherits:
AuthFilterBase show all
Defined in:
lib/httpclient.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProxyAuth

Returns a new instance of ProxyAuth.



728
729
730
731
732
733
734
# File 'lib/httpclient.rb', line 728

def initialize
  @basic_auth = BasicAuth.new
  @negotiate_auth = NegotiateAuth.new
  @sspi_negotiate_auth = SSPINegotiateAuth.new
  # sort authenticators by priority
  @authenticator = [@negotiate_auth, @sspi_negotiate_auth, @basic_auth]
end

Instance Attribute Details

#basic_authObject (readonly)

Returns the value of attribute basic_auth.



724
725
726
# File 'lib/httpclient.rb', line 724

def basic_auth
  @basic_auth
end

#negotiate_authObject (readonly)

Returns the value of attribute negotiate_auth.



725
726
727
# File 'lib/httpclient.rb', line 725

def negotiate_auth
  @negotiate_auth
end

#sspi_negotiate_authObject (readonly)

Returns the value of attribute sspi_negotiate_auth.



726
727
728
# File 'lib/httpclient.rb', line 726

def sspi_negotiate_auth
  @sspi_negotiate_auth
end

Instance Method Details

#filter_request(req) ⇒ Object



747
748
749
750
751
752
753
754
# File 'lib/httpclient.rb', line 747

def filter_request(req)
  @authenticator.each do |auth|
    if cred = auth.get(req)
      req.header.set('Proxy-Authorization', auth.scheme + " " + cred)
      return
    end
  end
end

#filter_response(req, res) ⇒ Object



756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
# File 'lib/httpclient.rb', line 756

def filter_response(req, res)
  command = nil
  uri = req.header.request_uri
  if res.status == HTTP::Status::PROXY_AUTHENTICATE_REQUIRED
    if challenge = parse_authentication_header(res, 'proxy-authenticate')
      challenge.each do |scheme, param_str|
        @authenticator.each do |auth|
          if scheme.downcase == auth.scheme.downcase
            challengeable = auth.challenge(uri, param_str)
            command = :retry if challengeable
          end
        end
      end
      # ignore unknown authentication scheme
    end
  end
  command
end

#reset_challengeObject



736
737
738
739
740
# File 'lib/httpclient.rb', line 736

def reset_challenge
  @authenticator.each do |auth|
    auth.reset_challenge
  end
end

#set_auth(user, passwd) ⇒ Object



742
743
744
745
# File 'lib/httpclient.rb', line 742

def set_auth(user, passwd)
  @basic_auth.set(nil, user, passwd)
  @negotiate_auth.set(nil, user, passwd)
end