Sha256: 69112b3c9bd0e515c7b82a5fe3982a97fb109cdf8d663eaa70b3fb493df19219

Contents?: true

Size: 1.78 KB

Versions: 18

Compression:

Stored size: 1.78 KB

Contents

# Copyright (C) 2009-2014 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Mongo
  module Sasl
    module GSSAPI

      def self.authenticate(username, client, socket, opts={})
        db           = client.db('$external')
        hostname     = socket.pool.host
        servicename  = opts[:service_name] || 'mongodb'
        canonicalize = opts[:canonicalize_host_name] ? opts[:canonicalize_host_name] : false
        username     += "@#{opts[:service_realm]}" if opts[:service_realm]
        authenticator = Mongo::Sasl::GSSAPIAuthenticator.new(username, hostname, servicename, canonicalize)

        return { } unless authenticator.valid?

        token    = authenticator.initialize_challenge
        cmd      = BSON::OrderedHash['saslStart', 1, 'mechanism', 'GSSAPI', 'payload', token, 'autoAuthorize', 1]
        response = db.command(cmd, :check_response => false, :socket => socket)

        until response['done'] do
          break unless Support.ok?(response)
          token    = authenticator.evaluate_challenge(response['payload'])
          cmd      = BSON::OrderedHash['saslContinue', 1, 'conversationId', response['conversationId'], 'payload', token]
          response = db.command(cmd, :check_response => false, :socket => socket)
        end
        response
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mongo_kerberos-1.12.5-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.5 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.4-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.4 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.3-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.3 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.2-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.2 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.1-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.1 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0.rc2-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0.rc2 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0.rc1-java lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0.rc1 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0.rc0 lib/mongo_kerberos/sasl_c.rb
mongo_kerberos-1.12.0.rc0-java lib/mongo_kerberos/sasl_c.rb