Class: WSDL::Security::SecurityHeader

Inherits:
Object
  • Object
show all
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.

Examples:

Building a security header

header = SecurityHeader.new(config)
header.apply(document)

See Also:

Constant Summary collapse

NS =

Local aliases for namespace constants

Constants::NS
SecurityNS =

Alias for WS-Security namespace constants.

Returns:

  • (Module)
NS::Security
AddressingNS =

Alias for WS-Addressing namespace constants.

Returns:

  • (Module)
NS::Addressing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SecurityHeader

Creates a new SecurityHeader instance.

Parameters:

  • config (Config)

    the security configuration



48
49
50
# File 'lib/wsdl/security/security_header.rb', line 48

def initialize(config)
  @config = config
end

Instance Attribute Details

#configConfig (readonly)

Returns the security configuration.

Returns:



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:

  1. Parses the SOAP envelope
  2. Creates the wsse:Security element in the SOAP Header
  3. Adds configured security elements (Timestamp, UsernameToken)
  4. If signing is configured, computes digests and adds signature

Parameters:

  • envelope_xml (String, Nokogiri::XML::Document)

    the SOAP envelope as an XML string or prebuilt document

Returns:

  • (String)

    the SOAP envelope with security header



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
  add_timestamp(document, security_node, request_context) if request_context.timestamp?
  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: xml_save_options)
end