SAML2 Message
@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
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
@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
@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