Class: Samlr::Request

Inherits:
Object show all
Defined in:
lib/samlr/request.rb

Direct Known Subclasses

LogoutRequest, LogoutResponse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil, options = {}) ⇒ Request

Returns a new instance of Request.


7
8
9
10
# File 'lib/samlr/request.rb', line 7

def initialize(data = nil, options = {})
  @options = options
  @document = Request.parse(data)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document


5
6
7
# File 'lib/samlr/request.rb', line 5

def document
  @document
end

#optionsObject (readonly)

Returns the value of attribute options


5
6
7
# File 'lib/samlr/request.rb', line 5

def options
  @options
end

Class Method Details

.parse(data) ⇒ Object


40
41
42
# File 'lib/samlr/request.rb', line 40

def self.parse(data)
  Samlr::Tools.parse(data, compressed: true)
end

Instance Method Details

#bodyObject

The XML payload body


18
19
20
# File 'lib/samlr/request.rb', line 18

def body
  @body ||= Samlr::Tools::RequestBuilder.build(options)
end

#get_attribute_or_element(x_path, attribute = nil) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/samlr/request.rb', line 44

def get_attribute_or_element(x_path,attribute=nil)
  if document
    element = document.xpath(x_path)
    if element.length == 0
      nil
    elsif attribute
      value = element.attr(attribute)
      value.to_s if value
    else
      element
    end
  else
    raise Samlr::NoDataError.new("Attempting to get attributes of a Request that has no data")
  end
end

#paramObject

The encoded SAML request


13
14
15
# File 'lib/samlr/request.rb', line 13

def param
  @param ||= Samlr::Tools.encode(body)
end

#typeObject


22
23
24
# File 'lib/samlr/request.rb', line 22

def type
  "SAMLRequest"
end

#url(root, params = {}) ⇒ Object

Utility method to get the full redirect destination, Request#url(“idp.example.com/saml”, { :RelayState => “sp.example.com/saml” })


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/samlr/request.rb', line 27

def url(root, params = {})
  dest = root.dup

  dest << (dest.include?("?") ? "&" : "?")
  dest << "#{type}=#{param}"

  params.each_pair do |key, value|
    dest << "&#{key}=#{CGI.escape(value.to_s)}"
  end

  dest
end