Class: Maestrano::Saml::Request
- Inherits:
-
Object
- Object
- Maestrano::Saml::Request
- Defined in:
- lib/maestrano/saml/request.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#session ⇒ Object
Returns the value of attribute session.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #create_authentication_xml_doc(settings) ⇒ Object
-
#initialize(params = {}, session = {}) ⇒ Request
constructor
A new instance of Request.
- #redirect_url ⇒ Object
Constructor Details
#initialize(params = {}, session = {}) ⇒ Request
Returns a new instance of Request.
14 15 16 17 18 |
# File 'lib/maestrano/saml/request.rb', line 14 def initialize(params = {}, session = {}) self.settings = Maestrano::SSO.saml_settings self.params = params self.session = session end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
12 13 14 |
# File 'lib/maestrano/saml/request.rb', line 12 def params @params end |
#session ⇒ Object
Returns the value of attribute session.
12 13 14 |
# File 'lib/maestrano/saml/request.rb', line 12 def session @session end |
#settings ⇒ Object
Returns the value of attribute settings.
12 13 14 |
# File 'lib/maestrano/saml/request.rb', line 12 def settings @settings end |
Instance Method Details
#create_authentication_xml_doc(settings) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/maestrano/saml/request.rb', line 44 def create_authentication_xml_doc(settings) uuid = "_" + UUID.new.generate time = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ") # Create AuthnRequest root element using REXML request_doc = REXML::Document.new root = request_doc.add_element "samlp:AuthnRequest", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol" } root.attributes['ID'] = uuid root.attributes['IssueInstant'] = time root.attributes['Version'] = "2.0" root.attributes['Destination'] = self.settings.idp_sso_target_url unless self.settings.idp_sso_target_url.nil? root.attributes['IsPassive'] = self.settings.passive unless self.settings.passive.nil? root.attributes['ProtocolBinding'] = self.settings.protocol_binding unless self.settings.protocol_binding.nil? # Conditionally defined elements based on settings if self.settings.assertion_consumer_service_url != nil root.attributes["AssertionConsumerServiceURL"] = self.settings.assertion_consumer_service_url end if self.settings.issuer != nil issuer = root.add_element "saml:Issuer", { "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion" } issuer.text = self.settings.issuer end if self.settings.name_identifier_format != nil root.add_element "samlp:NameIDPolicy", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol", # Might want to make AllowCreate a setting? "AllowCreate" => "true", "Format" => self.settings.name_identifier_format } end # BUG fix here -- if an authn_context is defined, add the tags with an "exact" # match required for authentication to succeed. If this is not defined, # the IdP will choose default rules for authentication. (Shibboleth IdP) if self.settings.authn_context != nil requested_context = root.add_element "samlp:RequestedAuthnContext", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol", "Comparison" => "exact", } class_ref = requested_context.add_element "saml:AuthnContextClassRef", { "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion", } class_ref.text = self.settings.authn_context end request_doc end |
#redirect_url ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/maestrano/saml/request.rb', line 20 def redirect_url request_doc = create_authentication_xml_doc(settings) request_doc.context[:attribute_quote] = :quote if self.settings.double_quote_xml_attribute_values request = "" request_doc.write(request) request = Zlib::Deflate.deflate(request, 9)[2..-5] if self.settings.compress_request base64_request = Base64.encode64(request) encoded_request = CGI.escape(base64_request) params_prefix = (self.settings.idp_sso_target_url =~ /\?/) ? '&' : '?' request_params = "#{params_prefix}SAMLRequest=#{encoded_request}" self.params.each_pair do |key, value| request_params << "&#{key.to_s}=#{CGI.escape(value.to_s)}" end if (request_params !~ /group_id=/) && (group_id = (self.session[:mno_group_uid] || self.session['mno_group_uid'])) request_params << "&group_id=#{CGI.escape(group_id.to_s)}" end self.settings.idp_sso_target_url + request_params end |