Class: Saml::Kit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/saml/kit/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
16
17
# File 'lib/saml/kit/configuration.rb', line 9

def initialize
  @signature_method = :SHA256
  @digest_method = :SHA256
  @registry = DefaultRegistry.new
  @session_timeout = 3.hours
  @logger = Logger.new(STDOUT)
  @key_pairs = []
  yield self if block_given?
end

Instance Attribute Details

#digest_method ⇒ Object

Returns the value of attribute digest_method.



5
6
7
# File 'lib/saml/kit/configuration.rb', line 5

def digest_method
  @digest_method
end

#issuer ⇒ Object

Returns the value of attribute issuer.



4
5
6
# File 'lib/saml/kit/configuration.rb', line 4

def issuer
  @issuer
end

#logger ⇒ Object

Returns the value of attribute logger.



7
8
9
# File 'lib/saml/kit/configuration.rb', line 7

def logger
  @logger
end

#registry ⇒ Object

Returns the value of attribute registry.



6
7
8
# File 'lib/saml/kit/configuration.rb', line 6

def registry
  @registry
end

#session_timeout ⇒ Object

Returns the value of attribute session_timeout.



6
7
8
# File 'lib/saml/kit/configuration.rb', line 6

def session_timeout
  @session_timeout
end

#signature_method ⇒ Object

Returns the value of attribute signature_method.



5
6
7
# File 'lib/saml/kit/configuration.rb', line 5

def signature_method
  @signature_method
end

Instance Method Details

#add_key_pair(certificate, private_key, password:, use: :signing) ⇒ Object



19
20
21
# File 'lib/saml/kit/configuration.rb', line 19

def add_key_pair(certificate, private_key, password:, use: :signing)
  @key_pairs.push(KeyPair.new(certificate, private_key, password, use.to_sym))
end

#certificates(use: nil) ⇒ Object



32
33
34
# File 'lib/saml/kit/configuration.rb', line 32

def certificates(use: nil)
  key_pairs(use: use).flat_map(&:certificate)
end

#encryption_certificate ⇒ Object



40
41
42
43
# File 'lib/saml/kit/configuration.rb', line 40

def encryption_certificate
  Saml::Kit.deprecate("encryption_certificate is deprecated. Use certificates(use: :encryption) instead")
  certificates(use: :encryption).last
end

#encryption_private_key ⇒ Object



50
51
52
53
# File 'lib/saml/kit/configuration.rb', line 50

def encryption_private_key
  Saml::Kit.deprecate("encryption_private_key is deprecated. Use private_keys(use: :encryption) instead")
  private_keys(use: :encryption).last
end

#generate_key_pair_for(use:, password: SecureRandom.uuid) ⇒ Object



23
24
25
26
# File 'lib/saml/kit/configuration.rb', line 23

def generate_key_pair_for(use:, password: SecureRandom.uuid)
  certificate, private_key = SelfSignedCertificate.new(password).create
  add_key_pair(certificate, private_key, password: password, use: use)
end

#key_pairs(use: nil) ⇒ Object



28
29
30
# File 'lib/saml/kit/configuration.rb', line 28

def key_pairs(use: nil)
  use.present? ? @key_pairs.find_all { |x| x.for?(use) } : @key_pairs
end

#private_keys(use: :signing) ⇒ Object



36
37
38
# File 'lib/saml/kit/configuration.rb', line 36

def private_keys(use: :signing)
  key_pairs(use: use).flat_map(&:private_key)
end

#sign? ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/saml/kit/configuration.rb', line 55

def sign?
  certificates(use: :signing).any?
end

#signing_private_key ⇒ Object



45
46
47
48
# File 'lib/saml/kit/configuration.rb', line 45

def signing_private_key
  Saml::Kit.deprecate("signing_private_key is deprecated. Use private_keys(use: :signing) instead")
  private_keys(use: :signing).last
end