Class: SSO::RequestSecurityToken
- Inherits:
-
SoapInvocable
- Object
- SoapInvocable
- SSO::RequestSecurityToken
- Defined in:
- lib/sso.rb
Overview
Encapsulates an issue operation that requests a security token from the SSO service.
Instance Attribute Summary collapse
-
#delegatable ⇒ Object
Returns the value of attribute delegatable.
-
#request_type ⇒ Object
Returns the value of attribute request_type.
Attributes inherited from SoapInvocable
#client, #operation, #response
Instance Method Summary collapse
-
#body_xml(body) ⇒ Object
Builds the body XML for the SOAP request.
- #created ⇒ Object
- #expires ⇒ Object
- #future ⇒ Object
-
#header_xml(header) ⇒ Object
Builds the header XML for the SOAP request.
-
#initialize(client, username, password, hours = 2) ⇒ RequestSecurityToken
constructor
Constructs a new instance.
- #now ⇒ Object
-
#saml_token ⇒ SamlToken
Gets the saml_token from the SOAP response body.
Methods inherited from SoapInvocable
#has_header?, #invoke, #request_xml, #response_hash, #response_xml
Constructor Details
#initialize(client, username, password, hours = 2) ⇒ RequestSecurityToken
Constructs a new instance.
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/sso.rb', line 149 def initialize(client, username, password, hours = 2) super(:issue, client) @username = username @password = password @hours = hours # TODO: these things should be configurable, so we can get # non-delegatable tokens, HoK tokens, etc. @request_type = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue" @delegatable = true end |
Instance Attribute Details
#delegatable ⇒ Object
Returns the value of attribute delegatable.
146 147 148 |
# File 'lib/sso.rb', line 146 def delegatable @delegatable end |
#request_type ⇒ Object
Returns the value of attribute request_type.
146 147 148 |
# File 'lib/sso.rb', line 146 def request_type @request_type end |
Instance Method Details
#body_xml(body) ⇒ Object
Builds the body XML for the SOAP request.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/sso.rb', line 205 def body_xml(body) body.tag!("wst:RequestSecurityToken") do |rst| rst.tag!("wst:RequestType") do |element| element << request_type end rst.tag!("wst:Delegatable") do |element| element << delegatable.to_s end =begin #TODO: we don't seem to need this, but I'm leaving this #here for now as a reminder. rst.tag!("wst:Lifetime") do |lifetime| lifetime.tag!("u:Created") do |element| element << created end lifetime.tag!("u:Expires") do |element| element << expires end end =end end end |
#created ⇒ Object
166 167 168 |
# File 'lib/sso.rb', line 166 def created @created ||= now.strftime(DATE_FORMAT) end |
#expires ⇒ Object
174 175 176 |
# File 'lib/sso.rb', line 174 def expires @expires ||= future.strftime(DATE_FORMAT) end |
#future ⇒ Object
170 171 172 |
# File 'lib/sso.rb', line 170 def future @future ||= now + (2 / 24.0) # days (for DateTime math) end |
#header_xml(header) ⇒ Object
Builds the header XML for the SOAP request.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/sso.rb', line 179 def header_xml(header) id = "uuid-" + SecureRandom.uuid # header.tag!("x:Security", "x:mustUnderstand" => "1") do |security| header.tag!("x:Security") do |security| security.tag!("u:Timestamp", "u:Id" => "_0") do || .tag!("u:Created") do |element| element << created end .tag!("u:Expires") do |element| element << expires end end security.tag!("x:UsernameToken", "u:Id" => id) do |utoken| utoken.tag!("x:Username") do |element| element << @username end utoken.tag!("x:Password") do |element| element << @password end end end end |
#now ⇒ Object
162 163 164 |
# File 'lib/sso.rb', line 162 def now @now ||= Time.now.utc.to_datetime end |