class SamlIdp::ResponseBuilder

Attributes

assertion_and_signature[RW]
issuer_uri[RW]
raw_algorithm[RW]
reference_id[RW]
response_id[RW]
saml_acs_url[RW]
saml_request_id[RW]

Public Class Methods

new(response_id, issuer_uri, saml_acs_url, saml_request_id, assertion_and_signature, raw_algorithm) click to toggle source
# File lib/saml_idp/response_builder.rb, line 17
def initialize(response_id, issuer_uri, saml_acs_url, saml_request_id, assertion_and_signature, raw_algorithm)
  self.response_id = response_id
  self.issuer_uri = issuer_uri
  self.saml_acs_url = saml_acs_url
  self.saml_request_id = saml_request_id
  self.assertion_and_signature = assertion_and_signature
  self.raw_algorithm = raw_algorithm
end

Public Instance Methods

encoded(signed_message: false, compress: false) click to toggle source
# File lib/saml_idp/response_builder.rb, line 26
def encoded(signed_message: false, compress: false)
  @encoded ||= signed_message ? encode_signed_message(compress) : encode_raw_message(compress)
end
raw() click to toggle source
# File lib/saml_idp/response_builder.rb, line 30
def raw
  build
end

Private Instance Methods

build() click to toggle source
# File lib/saml_idp/response_builder.rb, line 44
def build
  resp_options = {}
  resp_options[:ID] = response_id_string
  resp_options[:Version] =  "2.0"
  resp_options[:IssueInstant] = now_iso
  resp_options[:Destination] = saml_acs_url
  resp_options[:Consent] = Saml::XML::Namespaces::Consents::UNSPECIFIED
  resp_options[:InResponseTo] = saml_request_id unless saml_request_id.nil?
  resp_options["xmlns:samlp"] = Saml::XML::Namespaces::PROTOCOL

  builder = Builder::XmlMarkup.new
  builder.tag! "samlp:Response", resp_options do |response|
      response.Issuer issuer_uri, xmlns: Saml::XML::Namespaces::ASSERTION
      sign response
      response.tag! "samlp:Status" do |status|
        status.tag! "samlp:StatusCode", Value: Saml::XML::Namespaces::Statuses::SUCCESS
      end
      response << assertion_and_signature
    end
end
deflate(inflated) click to toggle source
# File lib/saml_idp/response_builder.rb, line 77
def deflate(inflated)
  Zlib::Deflate.deflate(inflated, 9)[2..-5]
end
encode_raw_message(compress) click to toggle source
# File lib/saml_idp/response_builder.rb, line 34
def encode_raw_message(compress)
  Base64.strict_encode64(compress ? deflate(raw) : raw)
end
encode_signed_message(compress) click to toggle source
# File lib/saml_idp/response_builder.rb, line 39
def encode_signed_message(compress)
  Base64.strict_encode64(compress ? deflate(signed) : signed)
end
now_iso() click to toggle source
# File lib/saml_idp/response_builder.rb, line 72
def now_iso
  Time.now.utc.iso8601
end
response_id_string() click to toggle source
# File lib/saml_idp/response_builder.rb, line 66
def response_id_string
  "_#{response_id}"
end