Sha256: 237aa3bd564482f53ff79918116f01d6927003ad05aa74a1dcaae2685dfd1b05

Contents?: true

Size: 871 Bytes

Versions: 6

Compression:

Stored size: 871 Bytes

Contents

# frozen_string_literal: true

module Rails
  module Auth
    module X509
      # Matcher for making assertions about X.509 certificates
      class Matcher
        # @option options [String] cn Common Name of the subject
        # @option options [String] ou Organizational Unit of the subject
        def initialize(options)
          @options = options.freeze
        end

        # @param [Hash] env Rack environment
        def match(env)
          certificate = Rails::Auth.credentials(env)["x509"]
          return false unless certificate

          @options.all? { |name, value| certificate[name] == value }
        end

        # Generates inspectable attributes for debugging
        #
        # @return [Hash] hash containing parts of the certificate subject to match (cn, ou)
        def attributes
          @options
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails-auth-3.2.0 lib/rails/auth/x509/matcher.rb
rails-auth-3.1.0 lib/rails/auth/x509/matcher.rb
rails-auth-3.0.0 lib/rails/auth/x509/matcher.rb
rails-auth-2.2.2 lib/rails/auth/x509/matcher.rb
rails-auth-2.2.1 lib/rails/auth/x509/matcher.rb
rails-auth-2.2.0 lib/rails/auth/x509/matcher.rb