Sha256: 832b25af99df6eba779560d96a873266aec5d927166997ad6ae2f66e27d74cdc

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require 'zlib'
require 'time'
require 'nokogiri'

require "onelogin/ruby-saml/saml_message"

# Only supports SAML 2.0
module OneLogin
  module RubySaml
    class SloLogoutrequest < SamlMessage
      attr_reader :options
      attr_reader :request
      attr_reader :document

      def initialize(request, options = {})
        raise ArgumentError.new("Request cannot be nil") if request.nil?
        @options  = options
        @request = decode_raw_saml(request)
        @document = REXML::Document.new(@request)
      end

      def is_valid?
        validate
      end

      def validate!
        validate(false)
      end

      # The value of the user identifier as designated by the initialization request response
      def name_id
        @name_id ||= begin
          node = REXML::XPath.first(document, "/p:LogoutRequest/a:NameID", { "p" => PROTOCOL, "a" => ASSERTION })
          node.nil? ? nil : node.text
        end
      end

      def id
        return @id if @id
        element = REXML::XPath.first(document, "/p:LogoutRequest", {
            "p" => PROTOCOL} )
        return nil if element.nil?
        return element.attributes["ID"]
      end

      def issuer
        @issuer ||= begin
          node = REXML::XPath.first(document, "/p:LogoutRequest/a:Issuer", { "p" => PROTOCOL, "a" => ASSERTION })
          node.nil? ? nil : node.text
        end
      end

      private

      def validate(soft = true)
        valid_saml?(document, soft)  && validate_request_state(soft)
      end

      def validate_request_state(soft = true)
        if request.empty?
          return soft ? false : validation_error("Blank request")
        end
        true
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-saml-0.9.2 lib/onelogin/ruby-saml/slo_logoutrequest.rb