Class: SSO::RequestSecurityToken

Inherits:
SoapInvocable show all
Defined in:
/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb

Overview

Encapsulates an issue operation that requests a security token from the SSO service.

Instance Attribute Summary (collapse)

Attributes inherited from SoapInvocable

#client, #operation, #response

Instance Method Summary (collapse)

Methods inherited from SoapInvocable

#has_header?, #invoke, #request_xml, #response_hash, #response_xml

Constructor Details

- (RequestSecurityToken) initialize(client, username, password, hours = 2)

Constructs a new instance.



158
159
160
161
162
163
164
165
166
167
168
169
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 158

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

- (Object) delegatable

Returns the value of attribute delegatable



155
156
157
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 155

def delegatable
  @delegatable
end

- (Object) request_type

Returns the value of attribute request_type



155
156
157
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 155

def request_type
  @request_type
end

Instance Method Details

- (Object) body_xml(body)

Builds the body XML for the SOAP request.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 213

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

- (Object) created



175
176
177
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 175

def created
    @created ||= now.strftime(DATE_FORMAT)
end

- (Object) expires



183
184
185
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 183

def expires
    @expires ||= future.strftime(DATE_FORMAT)
end

- (Object) future



179
180
181
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 179

def future
    @future ||= now + (2/24.0) #days (for DateTime math)
end

- (Object) header_xml(header)

Builds the header XML for the SOAP request.



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 188

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 |timestamp|
            timestamp.tag!("u:Created") do |element|
                element << created
            end
            timestamp.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

- (Object) now



171
172
173
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 171

def now
    @now ||= Time.now.utc.to_datetime
end

- (SamlToken) saml_token

Gets the saml_token from the SOAP response body.

Returns:



238
239
240
241
242
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sso.rb', line 238

def saml_token
    assertion = response_xml.at_xpath('//saml2:Assertion',
            'saml2' => 'urn:oasis:names:tc:SAML:2.0:assertion')
    SamlToken.new(assertion)
end