module WSDL
module Security
class RequestPolicy
UsernameToken = Data.define(:username, :password, :digest, :created_at)
Timestamp = Data.define(:created_at, :expires_in, :expires_at)
Signature = Data.define(:certificate, :private_key, :options)
def self.empty
new
end
def initialize(username_token: nil, timestamp: nil, signature: nil)
@username_token = username_token
@timestamp = timestamp
@signature = signature
freeze
end
attr_reader :username_token
attr_reader :timestamp
attr_reader :signature
def with_username_token(username_token)
self.class.new(username_token:, timestamp: @timestamp, signature: @signature)
end
def with_timestamp(timestamp)
self.class.new(username_token: @username_token, timestamp:, signature: @signature)
end
def with_signature(signature)
self.class.new(username_token: @username_token, timestamp: @timestamp, signature:)
end
def configured?
username_token? || timestamp? || signature?
end
def username_token?
!@username_token.nil?
end
def timestamp?
!@timestamp.nil?
end
def signature?
!@signature.nil?
end
def sign_timestamp?
(@signature&.options&.sign_timestamp? && timestamp?) || false
end
def sign_addressing?
@signature&.options&.sign_addressing? || false
end
def explicit_namespace_prefixes?
@signature&.options&.explicit_namespace_prefixes? || false
end
def key_reference
@signature&.options&.key_reference || Constants::KeyReference::BINARY_SECURITY_TOKEN
end
end
end
end