Sha256: e02b6402b8ba55a0f2e5d28bdbd719e00d7f1d0d073be1e7d3ef807419124dcc

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

require 'active_support'
require File.expand_path('../../../client/cert.rb', __FILE__)

module Katello
  module Authentication
    module ClientAuthentication
      def authenticate_client
        set_client_user
        User.current.present?
      end

      def set_client_user
        if cert_present?
          client_cert = Client::Cert.new(cert_from_request)
          uuid = client_cert.uuid
          User.current = CpConsumerUser.new(:uuid => uuid, :login => uuid)
        end
      end

      def cert_present?
        ssl_client_cert = cert_from_request
        !ssl_client_cert.nil? && !ssl_client_cert.empty? && ssl_client_cert != "(null)"
      end

      # HTTP_X_RHSM_SSL_CLIENT_CERT - custom client cert header typically coming from a reverse
      #                               proxy on a Capsule passing RHSM traffic through in isolation
      # HTTP_SSL_CLIENT_CERT - standard client cert header coming from direct interactions with the
      #                        server
      def cert_from_request
        request.env['HTTP_X_RHSM_SSL_CLIENT_CERT'] ||
        request.env['SSL_CLIENT_CERT'] ||
        request.env['HTTP_SSL_CLIENT_CERT'] ||
        ENV['HTTP_X_RHSM_SSL_CLIENT_CERT'] ||
        ENV['SSL_CLIENT_CERT'] ||
        ENV['HTTP_SSL_CLIENT_CERT']
      end

      def add_candlepin_version_header
        response.headers["X-CANDLEPIN-VERSION"] = "katello/#{Katello::VERSION}"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/services/katello/authentication/client_authentication.rb
katello-2.4.4 app/services/katello/authentication/client_authentication.rb
katello-2.4.3 app/services/katello/authentication/client_authentication.rb
katello-2.4.2 app/services/katello/authentication/client_authentication.rb
katello-2.4.1 app/services/katello/authentication/client_authentication.rb
katello-2.4.0 app/services/katello/authentication/client_authentication.rb
katello-2.4.0.rc3 app/services/katello/authentication/client_authentication.rb
katello-2.4.0.rc2 app/services/katello/authentication/client_authentication.rb
katello-2.4.0.rc1 app/services/katello/authentication/client_authentication.rb