Sha256: a88b8c27b5bb7a69a72a1e205d284ef057dc2c8c391f37a63f244be10af1c0b0

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Saml
  module Kit
    # This module provides the behaviours
    # associated with SAML Response documents.
    # .e.g. Response, LogoutResponse
    module Respondable
      extend ActiveSupport::Concern
      attr_reader :request_id

      included do
        validates_inclusion_of :status_code, in: [Namespaces::SUCCESS]
        validate :must_match_request_id
      end

      # @!visibility private
      def query_string_parameter
        'SAMLResponse'
      end

      # Returns the /Status/StatusCode@Value
      def status_code
        at_xpath('./*/samlp:Status/samlp:StatusCode/@Value').try(:value)
      end

      # Returns the /Status/StatusMessage
      def status_message
        at_xpath('./*/samlp:Status/samlp:StatusMessage').try(:text)
      end

      # Returns the /InResponseTo attribute.
      def in_response_to
        at_xpath('./*/@InResponseTo').try(:value)
      end

      # Returns true if the Status code is #{Saml::Kit::Namespaces::SUCCESS}
      def success?
        Namespaces::SUCCESS == status_code
      end

      private

      def must_match_request_id
        return if request_id.nil?
        return if in_response_to == request_id

        errors[:in_response_to] << error_message(:invalid_response_to)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
saml-kit-1.1.0 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.31 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.30 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.29 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.28 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.27 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.26 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.25 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.24 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.23 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.22 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.21 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.20 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.19 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.18 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.17 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.16 lib/saml/kit/concerns/respondable.rb
saml-kit-1.0.15 lib/saml/kit/respondable.rb