Class: WSDL::Security::Config
- Inherits:
-
Object
- Object
- WSDL::Security::Config
- Defined in:
- lib/wsdl/security/config.rb
Overview
Fluent facade for configuring request and response security policies.
Config is intentionally thin and delegates to focused components:
- RequestPolicy for outbound message security intent
- ResponsePolicy for inbound verification enforcement
- CredentialNormalizer for credential normalization and validation
Per-request runtime security artifacts (nonce, IDs, timestamps, references) are generated by RequestMaterializer to avoid replayable state reuse.
Constant Summary collapse
- KeyRef =
Local alias for key reference constants
Constants::KeyReference
Instance Method Summary collapse
-
#check_certificate_validity ⇒ Boolean
Returns whether certificate validity checking is enabled.
-
#clear ⇒ self
Clears all security policy.
-
#clock_skew ⇒ Integer
Returns response timestamp clock skew in seconds.
-
#configured? ⇒ Boolean
Returns whether any request security is configured.
-
#dup ⇒ Config
Returns deep-copy style duplicate.
-
#explicit_namespace_prefixes? ⇒ Boolean
Returns whether explicit signature namespace prefixes are enabled.
-
#initialize(policy: Policy.default, credential_normalizer: CredentialNormalizer.new) ⇒ Config
constructor
A new instance of Config.
-
#inspect ⇒ String
Returns redacted configuration for safe logging.
-
#key_reference ⇒ Symbol
Returns key reference method.
-
#request_context(now: Time.now.utc) ⇒ RequestContext
Builds per-request runtime security context.
-
#response_policy ⇒ ResponsePolicy
Returns the response policy for verification enforcement.
-
#response_verification_options ⇒ ResponseVerification::Options
Returns response verification options.
-
#sign_addressing? ⇒ Boolean
Returns whether WS-Addressing signing is enabled.
-
#sign_timestamp? ⇒ Boolean
Returns whether timestamp signing is enabled.
-
#signature(certificate:, private_key:, **options) ⇒ self
Configures X.509 certificate signing.
-
#signature? ⇒ Boolean
Returns whether X.509 signing is configured.
-
#timestamp(created_at: nil, expires_in: Timestamp::DEFAULT_TTL, expires_at: nil) ⇒ self
Configures a wsu:Timestamp header.
-
#timestamp? ⇒ Boolean
Returns whether Timestamp is configured.
-
#username_token(username, password, digest: false, created_at: nil) ⇒ self
Configures UsernameToken authentication.
-
#username_token? ⇒ Boolean
Returns whether UsernameToken is configured.
-
#validate_timestamp ⇒ Boolean
Returns whether response timestamp validation is enabled.
-
#verification_mode ⇒ Symbol
Returns response verification mode.
-
#verification_trust_store ⇒ OpenSSL::X509::Store, ...
Returns configured response verification trust store.
-
#verify_response(mode: ResponsePolicy::MODE_REQUIRED, trust_store: nil, check_validity: true, validate_timestamp: true, clock_skew: 300) ⇒ self
Configures response verification enforcement.
-
#verify_response? ⇒ Boolean
Returns whether response verification enforcement is enabled.
Constructor Details
#initialize(policy: Policy.default, credential_normalizer: CredentialNormalizer.new) ⇒ Config
Returns a new instance of Config.
20 21 22 23 |
# File 'lib/wsdl/security/config.rb', line 20 def initialize(policy: Policy.default, credential_normalizer: CredentialNormalizer.new) @policy = policy @credential_normalizer = credential_normalizer end |
Instance Method Details
#check_certificate_validity ⇒ Boolean
Returns whether certificate validity checking is enabled.
176 177 178 |
# File 'lib/wsdl/security/config.rb', line 176 def check_certificate_validity .certificate.verify_not_expired end |
#clear ⇒ self
Clears all security policy.
226 227 228 229 |
# File 'lib/wsdl/security/config.rb', line 226 def clear @policy = Policy.default self end |
#clock_skew ⇒ Integer
Returns response timestamp clock skew in seconds.
190 191 192 |
# File 'lib/wsdl/security/config.rb', line 190 def clock_skew ..tolerance_seconds end |
#configured? ⇒ Boolean
Returns whether any request security is configured.
113 114 115 |
# File 'lib/wsdl/security/config.rb', line 113 def configured? @policy.request.configured? end |
#dup ⇒ Config
Returns deep-copy style duplicate.
234 235 236 |
# File 'lib/wsdl/security/config.rb', line 234 def dup self.class.new(policy: @policy, credential_normalizer: @credential_normalizer) end |
#explicit_namespace_prefixes? ⇒ Boolean
Returns whether explicit signature namespace prefixes are enabled.
155 156 157 |
# File 'lib/wsdl/security/config.rb', line 155 def explicit_namespace_prefixes? @policy.request.explicit_namespace_prefixes? end |
#inspect ⇒ String
Returns redacted configuration for safe logging.
241 242 243 244 245 246 247 248 249 |
# File 'lib/wsdl/security/config.rb', line 241 def inspect parts = inspect_base_parts parts.concat(inspect_username_token_parts) if @policy.request.username_token parts.concat(inspect_signature_parts) if @policy.request.signature "#<#{self.class.name} #{parts.join(' ')}>" rescue StandardError "#<#{self.class.name} username_token=#{username_token?} timestamp=#{timestamp?} " \ "signature=#{signature?} verify_response=#{verify_response?}>" end |
#key_reference ⇒ Symbol
Returns key reference method.
162 163 164 |
# File 'lib/wsdl/security/config.rb', line 162 def key_reference @policy.request.key_reference end |
#request_context(now: Time.now.utc) ⇒ RequestContext
Builds per-request runtime security context.
219 220 221 |
# File 'lib/wsdl/security/config.rb', line 219 def request_context(now: Time.now.utc) RequestMaterializer.materialize(@policy.request, now:) end |
#response_policy ⇒ ResponsePolicy
Returns the response policy for verification enforcement.
211 212 213 |
# File 'lib/wsdl/security/config.rb', line 211 def response_policy @policy.response end |
#response_verification_options ⇒ ResponseVerification::Options
Returns response verification options.
204 205 206 |
# File 'lib/wsdl/security/config.rb', line 204 def @policy.response. end |
#sign_addressing? ⇒ Boolean
Returns whether WS-Addressing signing is enabled.
148 149 150 |
# File 'lib/wsdl/security/config.rb', line 148 def sign_addressing? @policy.request.sign_addressing? end |
#sign_timestamp? ⇒ Boolean
Returns whether timestamp signing is enabled.
141 142 143 |
# File 'lib/wsdl/security/config.rb', line 141 def @policy.request. end |
#signature(certificate:, private_key:, **options) ⇒ self
Configures X.509 certificate signing.
SOAP Body signing is mandatory and cannot be disabled.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wsdl/security/config.rb', line 58 def signature(certificate:, private_key:, **) cert = @credential_normalizer.normalize_certificate(certificate) key = @credential_normalizer.normalize_private_key(private_key, [:key_password]) = SignatureOptions.from_hash().freeze @credential_normalizer.validate_key_reference!(.key_reference, cert) signature = RequestPolicy::Signature.new( certificate: cert, private_key: key, options: ) @policy = @policy.with_request(@policy.request.with_signature(signature)) self end |
#signature? ⇒ Boolean
Returns whether X.509 signing is configured.
134 135 136 |
# File 'lib/wsdl/security/config.rb', line 134 def signature? @policy.request.signature? end |
#timestamp(created_at: nil, expires_in: Timestamp::DEFAULT_TTL, expires_at: nil) ⇒ self
Configures a wsu:Timestamp header.
44 45 46 47 48 |
# File 'lib/wsdl/security/config.rb', line 44 def (created_at: nil, expires_in: Timestamp::DEFAULT_TTL, expires_at: nil) ts = RequestPolicy::Timestamp.new(created_at:, expires_in:, expires_at:) @policy = @policy.with_request(@policy.request.(ts)) self end |
#timestamp? ⇒ Boolean
Returns whether Timestamp is configured.
127 128 129 |
# File 'lib/wsdl/security/config.rb', line 127 def @policy.request. end |
#username_token(username, password, digest: false, created_at: nil) ⇒ self
Configures UsernameToken authentication.
32 33 34 35 36 |
# File 'lib/wsdl/security/config.rb', line 32 def username_token(username, password, digest: false, created_at: nil) token = RequestPolicy::UsernameToken.new(username:, password:, digest:, created_at:) @policy = @policy.with_request(@policy.request.with_username_token(token)) self end |
#username_token? ⇒ Boolean
Returns whether UsernameToken is configured.
120 121 122 |
# File 'lib/wsdl/security/config.rb', line 120 def username_token? @policy.request.username_token? end |
#validate_timestamp ⇒ Boolean
Returns whether response timestamp validation is enabled.
183 184 185 |
# File 'lib/wsdl/security/config.rb', line 183 def ..validate end |
#verification_mode ⇒ Symbol
Returns response verification mode.
197 198 199 |
# File 'lib/wsdl/security/config.rb', line 197 def verification_mode @policy.response.mode end |
#verification_trust_store ⇒ OpenSSL::X509::Store, ...
Returns configured response verification trust store.
169 170 171 |
# File 'lib/wsdl/security/config.rb', line 169 def verification_trust_store .certificate.trust_store end |
#verify_response(mode: ResponsePolicy::MODE_REQUIRED, trust_store: nil, check_validity: true, validate_timestamp: true, clock_skew: 300) ⇒ self
Configures response verification enforcement.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/wsdl/security/config.rb', line 83 def verify_response(mode: ResponsePolicy::MODE_REQUIRED, trust_store: nil, check_validity: true, validate_timestamp: true, clock_skew: 300) resolved_trust_store = resolve_trust_store(mode:, trust_store:) = ResponseVerification::Options.new( certificate: ResponseVerification::Certificate.new( trust_store: resolved_trust_store, verify_not_expired: check_validity ), timestamp: ResponseVerification::Timestamp.new( validate: , tolerance_seconds: clock_skew ) ) response = @policy.response.with_mode(mode).() @policy = @policy.with_response(response) self end |
#verify_response? ⇒ Boolean
Returns whether response verification enforcement is enabled.
106 107 108 |
# File 'lib/wsdl/security/config.rb', line 106 def verify_response? !@policy.response.disabled? end |