Class: Onelogin::Saml::LogoutRequest
- Inherits:
-
Object
- Object
- Onelogin::Saml::LogoutRequest
- Defined in:
- lib/onelogin/ruby-saml/logout_request.rb
Constant Summary collapse
- ASSERTION =
"urn:oasis:names:tc:SAML:2.0:assertion"
- PROTOCOL =
"urn:oasis:names:tc:SAML:2.0:protocol"
- DSIG =
"http://www.w3.org/2000/09/xmldsig#"
Constants included from Request
Request::HTTP_GET, Request::HTTP_POST
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Instance Method Summary collapse
- #create(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ LogoutRequest
constructor
A new instance of LogoutRequest.
- #is_valid? ⇒ Boolean
-
#name_id ⇒ Object
Functions for pulling values out from an IdP initiated LogoutRequest.
- #to_s ⇒ Object
-
#to_xml ⇒ Object
function to return the created request as an XML document.
- #validate(soft = true) ⇒ Object
- #validate! ⇒ Object
Methods included from Request
#binding_select, #content_get, #content_post
Methods included from Coding
#decode, #deflate, #encode, #escape, #inflate, #unescape
Constructor Details
#initialize(options = {}) ⇒ LogoutRequest
Returns a new instance of LogoutRequest.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 14 def initialize( = {} ) opt = { :request => nil, :settings => nil }.merge() @settings = opt[:settings] @issue_instant = Onelogin::Saml::LogoutRequest. @request_params = Hash.new # We need to generate a LogoutRequest to send to the IdP if opt[:request].nil? @transaction_id = UUID.new.generate # The IdP sent us a LogoutRequest (IdP initiated SLO) else begin @request = XMLSecurity::SignedDocument.new( decode( opt[:request] )) raise if @request.nil? raise if @request.root.nil? raise if @request.root.namespace != PROTOCOL rescue @request = XMLSecurity::SignedDocument.new( inflate( decode( opt[:request] ) ) ) end Logging.debug "LogoutRequest is: \n#{@request}" end end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
12 13 14 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 12 def settings @settings end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
11 12 13 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 11 def transaction_id @transaction_id end |
Instance Method Details
#create(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 36 def create( = {} ) opt = { :name_id => nil, :session_index => nil, :extra_parameters => nil }.merge() return nil unless opt[:name_id] @request = REXML::Document.new @request.context[:attribute_quote] = :quote root = @request.add_element "saml2p:LogoutRequest", { "xmlns:saml2p" => PROTOCOL } root.attributes['ID'] = @transaction_id root.attributes['IssueInstant'] = @issue_instant root.attributes['Version'] = "2.0" root.attributes['Destination'] = @settings.single_logout_destination issuer = root.add_element "saml2:Issuer", { "xmlns:saml2" => ASSERTION } issuer.attributes['Format'] = "urn:oasis:names:tc:SAML:2.0:nameid-format:entity" #issuer.text = @settings.issuer #per la federazione trentina qui ci vanno i metadati... issuer.text = @settings. name_id = root.add_element "saml2:NameID", { "xmlns:saml2" => ASSERTION } name_id.attributes['Format'] = "urn:oasis:names:tc:SAML:2.0:nameid-format:transient" name_id.attributes['NameQualifier'] = @settings.idp_name_qualifier name_id.text = opt[:name_id] # I believe the rest of these are optional if @settings && @settings.sp_name_qualifier name_id.attributes["SPNameQualifier"] = @settings.sp_name_qualifier end if opt[:session_index] session_index = root.add_element "saml2p:SessionIndex" #, { "xmlns:samlp" => PROTOCOL } session_index.text = opt[:session_index] end Logging.debug "Created LogoutRequest: #{@request}" = Metadata.new(@settings) return .create_slo_request( to_s, opt[:extra_parameters] ) #action, content = binding_select("SingleLogoutService") #Logging.debug "action: #{action} content: #{content}" #return [action, content] end |
#is_valid? ⇒ Boolean
105 106 107 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 105 def is_valid? validate(soft = true) end |
#name_id ⇒ Object
Functions for pulling values out from an IdP initiated LogoutRequest
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 86 def name_id element = REXML::XPath.first(@request, "/p:LogoutRequest/a:NameID", { "p" => PROTOCOL, "a" => ASSERTION } ) return nil if element.nil? # Can't seem to get this to work right... #element.context[:compress_whitespace] = ["NameID"] #element.context[:compress_whitespace] = :all str = element.text.gsub(/^\s+/, "") str.gsub!(/\s+$/, "") return str end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 82 def to_s @request.to_s end |
#to_xml ⇒ Object
function to return the created request as an XML document
77 78 79 80 81 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 77 def to_xml text = "" @request.write(text, 1) return text end |
#validate(soft = true) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 112 def validate( soft = true ) return false if @request.nil? return false if @request.validate(@settings, soft) == false return true end |
#validate! ⇒ Object
109 110 111 |
# File 'lib/onelogin/ruby-saml/logout_request.rb', line 109 def validate! validate( soft = false ) end |