Class: WSDL::Security::SecurityHeader
- Inherits:
-
Object
- Object
- WSDL::Security::SecurityHeader
- Defined in:
- lib/wsdl/security/security_header.rb
Overview
Builds the complete wsse:Security header for a SOAP message.
The SecurityHeader class orchestrates the construction of the WS-Security header, including:
- wsu:Timestamp
- wsse:UsernameToken
- wsse:BinarySecurityToken (X.509 certificate)
- ds:Signature
Elements are added in the correct order as required by the WS-Security specification.
Constant Summary collapse
- NS =
Local aliases for namespace constants
Constants::NS
- SecurityNS =
Alias for WS-Security namespace constants.
NS::Security
- AddressingNS =
Alias for WS-Addressing namespace constants.
NS::Addressing
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
Returns the security configuration.
Instance Method Summary collapse
-
#apply(envelope_xml) ⇒ String
Applies the security header to a SOAP document.
-
#initialize(config) ⇒ SecurityHeader
constructor
Creates a new SecurityHeader instance.
Constructor Details
#initialize(config) ⇒ SecurityHeader
Creates a new SecurityHeader instance.
48 49 50 |
# File 'lib/wsdl/security/security_header.rb', line 48 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Config (readonly)
Returns the security configuration.
42 43 44 |
# File 'lib/wsdl/security/security_header.rb', line 42 def config @config end |
Instance Method Details
#apply(envelope_xml) ⇒ String
Applies the security header to a SOAP document.
This method:
- Parses the SOAP envelope
- Creates the wsse:Security element in the SOAP Header
- Adds configured security elements (Timestamp, UsernameToken)
- If signing is configured, computes digests and adds signature
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wsdl/security/security_header.rb', line 64 def apply(envelope_xml) request_context = @config.request_context document = parse_document(envelope_xml) header_node = find_or_create_header(document) security_node = create_security_element(document, header_node) # Add elements to security header (document, security_node, request_context) if request_context. add_username_token(document, security_node, request_context) if request_context.username_token? # Apply signature if configured (must be last) apply_signature(document, security_node, request_context) if request_context.signature? document.to_xml(save_with: ) end |