class Rails::Auth::X509::Matcher

Matcher for making assertions about X.509 certificates

Public Class Methods

new(options) click to toggle source

@option options [String] cn Common Name of the subject @option options [String] ou Organizational Unit of the subject

# File lib/rails/auth/x509/matcher.rb, line 10
def initialize(options)
  @options = options.freeze
end

Public Instance Methods

attributes() click to toggle source

Generates inspectable attributes for debugging

@return [Hash] hash containing parts of the certificate subject to match (cn, ou)

# File lib/rails/auth/x509/matcher.rb, line 25
def attributes
  @options
end
match(env) click to toggle source

@param [Hash] env Rack environment

# File lib/rails/auth/x509/matcher.rb, line 15
def match(env)
  certificate = Rails::Auth.credentials(env)["x509"]
  return false unless certificate

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