Class: Rails::Auth::X509::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/auth/x509/matcher.rb

Overview

Matcher for making assertions about X.509 certificates

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Matcher

Returns a new instance of Matcher.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • cn (String)

    Common Name of the subject

  • ou (String)

    Organizational Unit of the subject



10
11
12
# File 'lib/rails/auth/x509/matcher.rb', line 10

def initialize(options)
  @options = options.freeze
end

Instance Method Details

#attributesHash

Generates inspectable attributes for debugging

Returns:

  • (Hash)

    hash containing parts of the certificate subject to match (cn, ou)



25
26
27
# File 'lib/rails/auth/x509/matcher.rb', line 25

def attributes
  @options
end

#match(env) ⇒ Object

Parameters:

  • env (Hash)

    Rack environment



15
16
17
18
19
20
# 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