Class: WSDL::Security::Timestamp
- Inherits:
-
Object
- Object
- WSDL::Security::Timestamp
- Defined in:
- lib/wsdl/security/timestamp.rb
Overview
Represents a WS-Security Timestamp element.
The Timestamp element provides freshness guarantees by including creation and expiration times. It's commonly signed to prevent replay attacks.
Constant Summary collapse
- DEFAULT_TTL =
Default time-to-live in seconds (5 minutes)
300
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
Returns the creation time.
-
#expires_at ⇒ Time
readonly
Returns the expiration time.
-
#id ⇒ String
readonly
Returns the unique ID for this timestamp element.
Instance Method Summary collapse
-
#created_at_xml ⇒ String
Returns the created timestamp as an XML Schema dateTime string.
-
#expired? ⇒ Boolean
Checks if the timestamp has expired.
-
#expires_at_xml ⇒ String
Returns the expiration timestamp as an XML Schema dateTime string.
-
#initialize(created_at: nil, expires_in: DEFAULT_TTL, expires_at: nil, id: nil) ⇒ Timestamp
constructor
Creates a new Timestamp instance.
-
#to_hash ⇒ Hash
Returns a Hash representation suitable for Gyoku XML generation.
-
#to_xml(xml) ⇒ void
Builds the XML representation of the Timestamp element.
Constructor Details
#initialize(created_at: nil, expires_in: DEFAULT_TTL, expires_at: nil, id: nil) ⇒ Timestamp
Creates a new Timestamp instance.
45 46 47 48 49 |
# File 'lib/wsdl/security/timestamp.rb', line 45 def initialize(created_at: nil, expires_in: DEFAULT_TTL, expires_at: nil, id: nil) @created_at = (created_at || Time.now).utc @expires_at = expires_at&.utc || (@created_at + expires_in) @id = id || IdGenerator.for('Timestamp') end |
Instance Attribute Details
#created_at ⇒ Time (readonly)
Returns the creation time.
28 29 30 |
# File 'lib/wsdl/security/timestamp.rb', line 28 def created_at @created_at end |
#expires_at ⇒ Time (readonly)
Returns the expiration time.
32 33 34 |
# File 'lib/wsdl/security/timestamp.rb', line 32 def expires_at @expires_at end |
#id ⇒ String (readonly)
Returns the unique ID for this timestamp element.
36 37 38 |
# File 'lib/wsdl/security/timestamp.rb', line 36 def id @id end |
Instance Method Details
#created_at_xml ⇒ String
Returns the created timestamp as an XML Schema dateTime string.
55 56 57 |
# File 'lib/wsdl/security/timestamp.rb', line 55 def created_at_xml @created_at.xmlschema end |
#expired? ⇒ Boolean
Checks if the timestamp has expired.
71 72 73 |
# File 'lib/wsdl/security/timestamp.rb', line 71 def expired? Time.now.utc > @expires_at end |
#expires_at_xml ⇒ String
Returns the expiration timestamp as an XML Schema dateTime string.
63 64 65 |
# File 'lib/wsdl/security/timestamp.rb', line 63 def expires_at_xml @expires_at.xmlschema end |
#to_hash ⇒ Hash
Returns a Hash representation suitable for Gyoku XML generation.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/wsdl/security/timestamp.rb', line 97 def to_hash { 'wsu:Timestamp' => { 'wsu:Created' => created_at_xml, 'wsu:Expires' => expires_at_xml, :attributes! => { 'wsu:Timestamp' => { 'wsu:Id' => @id } }, :order! => ['wsu:Created', 'wsu:Expires'] } } end |
#to_xml(xml) ⇒ void
This method returns an undefined value.
Builds the XML representation of the Timestamp element.
86 87 88 89 90 91 |
# File 'lib/wsdl/security/timestamp.rb', line 86 def to_xml(xml) xml['wsu'].Timestamp('wsu:Id' => @id) do xml['wsu'].Created(created_at_xml) xml['wsu'].Expires(expires_at_xml) end end |