class OneLogin::RubySaml::SamlMessage

SAML2 Message

Constants

ASSERTION
BASE64_FORMAT
PROTOCOL

Public Instance Methods

id(document) click to toggle source

@return [String|nil] Gets the ID attribute from the SAML Message if exists.

# File lib/onelogin/ruby-saml/saml_message.rb, line 50
def id(document)
  @id ||= begin
    node = REXML::XPath.first(
      document,
      "/p:AuthnRequest | /p:Response | /p:LogoutResponse | /p:LogoutRequest",
      { "p" => PROTOCOL }
    )
    node.nil? ? nil : node.attributes['ID']
  end
end
valid_saml?(document, soft = true) click to toggle source

Validates the SAML Message against the specified schema. @param document [REXML::Document] The message that will be validated @param soft [Boolean] soft Enable or Disable the soft mode (In order to raise exceptions when the message is invalid or not) @return [Boolean] True if the XML is valid, otherwise False, if soft=True @raise [ValidationError] if soft == false and validation fails

# File lib/onelogin/ruby-saml/saml_message.rb, line 67
def valid_saml?(document, soft = true)
  begin
    xml = Nokogiri::XML(document.to_s) do |config|
      config.options = XMLSecurity::BaseDocument::NOKOGIRI_OPTIONS
    end
  rescue Exception => error
    return false if soft
    raise ValidationError.new("XML load failed: #{error.message}")
  end

  SamlMessage.schema.validate(xml).map do |error|
    return false if soft
    raise ValidationError.new("#{error.message}\n\n#{xml.to_s}")
  end
end
version(document) click to toggle source

@return [String|nil] Gets the Version attribute from the SAML Message if exists.

# File lib/onelogin/ruby-saml/saml_message.rb, line 37
def version(document)
  @version ||= begin
    node = REXML::XPath.first(
      document,
      "/p:AuthnRequest | /p:Response | /p:LogoutResponse | /p:LogoutRequest",
      { "p" => PROTOCOL }
    )
    node.nil? ? nil : node.attributes['Version']
  end
end

Public Class Methods

schema() click to toggle source

@return [Nokogiri::XML::Schema] Gets the schema object of the SAML 2.0 Protocol schema

# File lib/onelogin/ruby-saml/saml_message.rb, line 27
def self.schema
  @@mutex.synchronize do
    Dir.chdir(File.expand_path("../../../schemas", __FILE__)) do
      ::Nokogiri::XML::Schema(File.read("saml-schema-protocol-2.0.xsd"))
    end
  end
end