{"action":"created","comment":{"url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/comments/41666342","id":41666342,"diff_hunk":"@@ -250,131 +250,13 @@ def next_msgid\n   def bind(auth)\n     instrument \"bind.net_ldap_connection\" do |payload|\n       payload[:method] = meth = auth[:method]\n-      if [:simple, :anonymous, :anon].include?(meth)\n-        bind_simple auth\n-      elsif meth == :sasl\n-        bind_sasl(auth)\n-      elsif meth == :gss_spnego\n-        bind_gss_spnego(auth)\n-      else\n-        raise Net::LDAP::AuthMethodUnsupportedError, \"Unsupported auth method (#{meth})\"\n-      end\n-    end\n-  end\n-\n-  #--\n-  # Implements a simple user/psw authentication. Accessed by calling #bind\n-  # with a method of :simple or :anonymous.\n-  #++\n-  def bind_simple(auth)\n-    user, psw = if auth[:method] == :simple\n-                  [auth[:username] || auth[:dn], auth[:password]]\n-                else\n-                  [\"\", \"\"]\n-                end\n-\n-    raise Net::LDAP::BindingInformationInvalidError, \"Invalid binding information\" unless (user && psw)\n-\n-    message_id = next_msgid\n-    request    = [\n-      LdapVersion.to_ber, user.to_ber,\n-      psw.to_ber_contextspecific(0)\n-    ].to_ber_appsequence(Net::LDAP::PDU::BindRequest)\n-\n-    write(request, nil, message_id)\n-    pdu = queued_read(message_id)\n-\n-    if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult\n-      raise Net::LDAP::NoBindResultError, \"no bind result\"\n+      require \"net/ldap/auth_adapters/#{meth}\"\n+      adapter = Net::LDAP::AuthAdapter[meth]\n+      adapter.new(self).bind(auth)\n     end\n-\n-    pdu\n   end\n \n   #--\n-  # Required parameters: :mechanism, :initial_credential and\n-  # :challenge_response\n-  #\n-  # Mechanism is a string value that will be passed in the SASL-packet's\n-  # \"mechanism\" field.\n-  #\n-  # Initial credential is most likely a string. It's passed in the initial\n-  # BindRequest that goes to the server. In some protocols, it may be empty.\n-  #\n-  # Challenge-response is a Ruby proc that takes a single parameter and\n-  # returns an object that will typically be a string. The\n-  # challenge-response block is called when the server returns a\n-  # BindResponse with a result code of 14 (saslBindInProgress). The\n-  # challenge-response block receives a parameter containing the data\n-  # returned by the server in the saslServerCreds field of the LDAP\n-  # BindResponse packet. The challenge-response block may be called multiple\n-  # times during the course of a SASL authentication, and each time it must\n-  # return a value that will be passed back to the server as the credential\n-  # data in the next BindRequest packet.\n-  #++\n-  def bind_sasl(auth)\n-    mech, cred, chall = auth[:mechanism], auth[:initial_credential],\n-      auth[:challenge_response]\n-    raise Net::LDAP::BindingInformationInvalidError, \"Invalid binding information\" unless (mech && cred && chall)\n-\n-    message_id = next_msgid\n-\n-    n = 0\n-    loop {\n-      sasl = [mech.to_ber, cred.to_ber].to_ber_contextspecific(3)\n-      request = [\n-        LdapVersion.to_ber, \"\".to_ber, sasl\n-      ].to_ber_appsequence(Net::LDAP::PDU::BindRequest)\n-\n-      write(request, nil, message_id)\n-      pdu = queued_read(message_id)\n-\n-      if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult\n-        raise Net::LDAP::NoBindResultError, \"no bind result\"\n-      end\n-\n-      return pdu unless pdu.result_code == Net::LDAP::ResultCodeSaslBindInProgress\n-      raise Net::LDAP::SASLChallengeOverflowError, \"sasl-challenge overflow\" if ((n += 1) > MaxSaslChallenges)\n-\n-      cred = chall.call(pdu.result_server_sasl_creds)\n-    }\n-\n-    raise Net::LDAP::SASLChallengeOverflowError, \"why are we here?\"\n-  end\n-  private :bind_sasl\n-\n-  #--\n-  # PROVISIONAL, only for testing SASL implementations. DON'T USE THIS YET.\n-  # Uses Kohei Kajimoto's Ruby/NTLM. We have to find a clean way to\n-  # integrate it without introducing an external dependency.\n-  #\n-  # This authentication method is accessed by calling #bind with a :method\n-  # parameter of :gss_spnego. It requires :username and :password\n-  # attributes, just like the :simple authentication method. It performs a\n-  # GSS-SPNEGO authentication with the server, which is presumed to be a\n-  # Microsoft Active Directory.\n-  #++\n-  def bind_gss_spnego(auth)\n-    require 'ntlm'\n-\n-    user, psw = [auth[:username] || auth[:dn], auth[:password]]\n-    raise Net::LDAP::BindingInformationInvalidError, \"Invalid binding information\" unless (user && psw)\n-\n-    nego = proc { |challenge|\n-      t2_msg = NTLM::Message.parse(challenge)\n-      t3_msg = t2_msg.response({ :user => user, :password => psw },\n-                               { :ntlmv2 => true })\n-      t3_msg.serialize\n-    }\n-\n-    bind_sasl(:method => :sasl, :mechanism => \"GSS-SPNEGO\",","path":"lib/net/ldap/connection.rb","position":123,"original_position":124,"commit_id":"9bf1f3003a5f20c370f8d0dbd0ce88dfdeac1434","original_commit_id":"ab20ad22cede28a689b47502628fd83a8bb1ba86","user":{"login":"jch","id":19874,"avatar_url":"https://avatars.githubusercontent.com/u/19874?v=3","gravatar_id":"","url":"https://api.github.com/users/jch","html_url":"https://github.com/jch","followers_url":"https://api.github.com/users/jch/followers","following_url":"https://api.github.com/users/jch/following{/other_user}","gists_url":"https://api.github.com/users/jch/gists{/gist_id}","starred_url":"https://api.github.com/users/jch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jch/subscriptions","organizations_url":"https://api.github.com/users/jch/orgs","repos_url":"https://api.github.com/users/jch/repos","events_url":"https://api.github.com/users/jch/events{/privacy}","received_events_url":"https://api.github.com/users/jch/received_events","type":"User","site_admin":true},"body":":+1:","created_at":"2015-10-09T19:01:39Z","updated_at":"2015-10-09T19:01:39Z","html_url":"https://github.com/ruby-ldap/ruby-net-ldap/pull/226#discussion_r41666342","pull_request_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226","_links":{"self":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/comments/41666342"},"html":{"href":"https://github.com/ruby-ldap/ruby-net-ldap/pull/226#discussion_r41666342"},"pull_request":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226"}}},"pull_request":{"url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226","id":46705677,"html_url":"https://github.com/ruby-ldap/ruby-net-ldap/pull/226","diff_url":"https://github.com/ruby-ldap/ruby-net-ldap/pull/226.diff","patch_url":"https://github.com/ruby-ldap/ruby-net-ldap/pull/226.patch","issue_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/issues/226","number":226,"state":"open","locked":false,"title":"Define auth adapters","user":{"login":"satoryu","id":124871,"avatar_url":"https://avatars.githubusercontent.com/u/124871?v=3","gravatar_id":"","url":"https://api.github.com/users/satoryu","html_url":"https://github.com/satoryu","followers_url":"https://api.github.com/users/satoryu/followers","following_url":"https://api.github.com/users/satoryu/following{/other_user}","gists_url":"https://api.github.com/users/satoryu/gists{/gist_id}","starred_url":"https://api.github.com/users/satoryu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satoryu/subscriptions","organizations_url":"https://api.github.com/users/satoryu/orgs","repos_url":"https://api.github.com/users/satoryu/repos","events_url":"https://api.github.com/users/satoryu/events{/privacy}","received_events_url":"https://api.github.com/users/satoryu/received_events","type":"User","site_admin":false},"body":"This PR provide a scheme of defining authentication (bind) of LDAP. \r\nBy merging this PR, we'll be able to define new auth adapter. \r\n\r\n1. create new file can be `require`d as `'net/ldap/auth_adapter/#{auth scheme name}`\r\n2. define an adapter as a subclass of `Net::LDAP::AuthAdapter` \r\n3. register new adapter by `Net::LDAP::AuthAdapter.register`\r\n\r\nI hope this PR would help #210 :) ","created_at":"2015-10-03T13:34:34Z","updated_at":"2015-10-09T19:01:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0820e98488a7b9ae246985ea82aa0f08d53bd83b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226/commits","review_comments_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226/comments","review_comment_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/issues/226/comments","statuses_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/statuses/9bf1f3003a5f20c370f8d0dbd0ce88dfdeac1434","head":{"label":"satoryu:define_auth_adapters","ref":"define_auth_adapters","sha":"9bf1f3003a5f20c370f8d0dbd0ce88dfdeac1434","user":{"login":"satoryu","id":124871,"avatar_url":"https://avatars.githubusercontent.com/u/124871?v=3","gravatar_id":"","url":"https://api.github.com/users/satoryu","html_url":"https://github.com/satoryu","followers_url":"https://api.github.com/users/satoryu/followers","following_url":"https://api.github.com/users/satoryu/following{/other_user}","gists_url":"https://api.github.com/users/satoryu/gists{/gist_id}","starred_url":"https://api.github.com/users/satoryu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satoryu/subscriptions","organizations_url":"https://api.github.com/users/satoryu/orgs","repos_url":"https://api.github.com/users/satoryu/repos","events_url":"https://api.github.com/users/satoryu/events{/privacy}","received_events_url":"https://api.github.com/users/satoryu/received_events","type":"User","site_admin":false},"repo":{"id":8717388,"name":"ruby-net-ldap","full_name":"satoryu/ruby-net-ldap","owner":{"login":"satoryu","id":124871,"avatar_url":"https://avatars.githubusercontent.com/u/124871?v=3","gravatar_id":"","url":"https://api.github.com/users/satoryu","html_url":"https://github.com/satoryu","followers_url":"https://api.github.com/users/satoryu/followers","following_url":"https://api.github.com/users/satoryu/following{/other_user}","gists_url":"https://api.github.com/users/satoryu/gists{/gist_id}","starred_url":"https://api.github.com/users/satoryu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satoryu/subscriptions","organizations_url":"https://api.github.com/users/satoryu/orgs","repos_url":"https://api.github.com/users/satoryu/repos","events_url":"https://api.github.com/users/satoryu/events{/privacy}","received_events_url":"https://api.github.com/users/satoryu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/satoryu/ruby-net-ldap","description":"Pure Ruby LDAP library ","fork":true,"url":"https://api.github.com/repos/satoryu/ruby-net-ldap","forks_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/forks","keys_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/teams","hooks_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/hooks","issue_events_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/issues/events{/number}","events_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/events","assignees_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/assignees{/user}","branches_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/branches{/branch}","tags_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/tags","blobs_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/git/refs{/sha}","trees_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/statuses/{sha}","languages_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/languages","stargazers_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/stargazers","contributors_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/contributors","subscribers_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/subscribers","subscription_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/subscription","commits_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/commits{/sha}","git_commits_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/git/commits{/sha}","comments_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/comments{/number}","issue_comment_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/issues/comments{/number}","contents_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/contents/{+path}","compare_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/merges","archive_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/downloads","issues_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/issues{/number}","pulls_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/pulls{/number}","milestones_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/milestones{/number}","notifications_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/labels{/name}","releases_url":"https://api.github.com/repos/satoryu/ruby-net-ldap/releases{/id}","created_at":"2013-03-12T01:34:38Z","updated_at":"2015-02-05T09:26:52Z","pushed_at":"2015-10-08T20:36:35Z","git_url":"git://github.com/satoryu/ruby-net-ldap.git","ssh_url":"git@github.com:satoryu/ruby-net-ldap.git","clone_url":"https://github.com/satoryu/ruby-net-ldap.git","svn_url":"https://github.com/satoryu/ruby-net-ldap","homepage":"http://rubyldap.com/","size":1382,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ruby-ldap:master","ref":"master","sha":"41576841f5685340679f7938b046ba37efc9ef74","user":{"login":"ruby-ldap","id":676122,"avatar_url":"https://avatars.githubusercontent.com/u/676122?v=3","gravatar_id":"","url":"https://api.github.com/users/ruby-ldap","html_url":"https://github.com/ruby-ldap","followers_url":"https://api.github.com/users/ruby-ldap/followers","following_url":"https://api.github.com/users/ruby-ldap/following{/other_user}","gists_url":"https://api.github.com/users/ruby-ldap/gists{/gist_id}","starred_url":"https://api.github.com/users/ruby-ldap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruby-ldap/subscriptions","organizations_url":"https://api.github.com/users/ruby-ldap/orgs","repos_url":"https://api.github.com/users/ruby-ldap/repos","events_url":"https://api.github.com/users/ruby-ldap/events{/privacy}","received_events_url":"https://api.github.com/users/ruby-ldap/received_events","type":"Organization","site_admin":false},"repo":{"id":1509861,"name":"ruby-net-ldap","full_name":"ruby-ldap/ruby-net-ldap","owner":{"login":"ruby-ldap","id":676122,"avatar_url":"https://avatars.githubusercontent.com/u/676122?v=3","gravatar_id":"","url":"https://api.github.com/users/ruby-ldap","html_url":"https://github.com/ruby-ldap","followers_url":"https://api.github.com/users/ruby-ldap/followers","following_url":"https://api.github.com/users/ruby-ldap/following{/other_user}","gists_url":"https://api.github.com/users/ruby-ldap/gists{/gist_id}","starred_url":"https://api.github.com/users/ruby-ldap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruby-ldap/subscriptions","organizations_url":"https://api.github.com/users/ruby-ldap/orgs","repos_url":"https://api.github.com/users/ruby-ldap/repos","events_url":"https://api.github.com/users/ruby-ldap/events{/privacy}","received_events_url":"https://api.github.com/users/ruby-ldap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ruby-ldap/ruby-net-ldap","description":"Pure Ruby LDAP library ","fork":false,"url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap","forks_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/forks","keys_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/teams","hooks_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/hooks","issue_events_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/issues/events{/number}","events_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/events","assignees_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/assignees{/user}","branches_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/branches{/branch}","tags_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/tags","blobs_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/git/refs{/sha}","trees_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/statuses/{sha}","languages_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/languages","stargazers_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/stargazers","contributors_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/contributors","subscribers_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/subscribers","subscription_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/subscription","commits_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/commits{/sha}","git_commits_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/git/commits{/sha}","comments_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/comments{/number}","issue_comment_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/issues/comments{/number}","contents_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/contents/{+path}","compare_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/merges","archive_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/downloads","issues_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/issues{/number}","pulls_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls{/number}","milestones_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/milestones{/number}","notifications_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/labels{/name}","releases_url":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/releases{/id}","created_at":"2011-03-22T03:52:14Z","updated_at":"2015-10-09T14:11:24Z","pushed_at":"2015-10-08T20:36:35Z","git_url":"git://github.com/ruby-ldap/ruby-net-ldap.git","ssh_url":"git@github.com:ruby-ldap/ruby-net-ldap.git","clone_url":"https://github.com/ruby-ldap/ruby-net-ldap.git","svn_url":"https://github.com/ruby-ldap/ruby-net-ldap","homepage":"https://github.com/ruby-ldap/ruby-net-ldap","size":2384,"stargazers_count":238,"watchers_count":238,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":164,"mirror_url":null,"open_issues_count":34,"forks":164,"open_issues":34,"watchers":238,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226"},"html":{"href":"https://github.com/ruby-ldap/ruby-net-ldap/pull/226"},"issue":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/issues/226"},"comments":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/issues/226/comments"},"review_comments":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226/comments"},"review_comment":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/pulls/226/commits"},"statuses":{"href":"https://api.github.com/repos/ruby-ldap/ruby-net-ldap/statuses/9bf1f3003a5f20c370f8d0dbd0ce88dfdeac1434"}}}}