Skip to content

Commit

Permalink
Merge pull request SAML-Toolkits#84 from anthonybatchelor-examtime/pr…
Browse files Browse the repository at this point in the history
…otocol_binding

Add support of BindingProtocol attribute
  • Loading branch information
stouset committed Aug 3, 2013
2 parents 978ac73 + 7e91032 commit b71bdf1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/onelogin/ruby-saml/authrequest.rb
Expand Up @@ -36,7 +36,7 @@ def create(settings, params = {})
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
# 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" }
Expand All @@ -45,6 +45,7 @@ def create_authentication_xml_doc(settings)
root.attributes['Version'] = "2.0"
root.attributes['Destination'] = settings.idp_sso_target_url unless settings.idp_sso_target_url.nil?
root.attributes['IsPassive'] = settings.passive unless settings.passive.nil?
root.attributes['ProtocolBinding'] = settings.protocol_binding unless settings.protocol_binding.nil?

# Conditionally defined elements based on settings
if settings.assertion_consumer_service_url != nil
Expand All @@ -55,7 +56,7 @@ def create_authentication_xml_doc(settings)
issuer.text = settings.issuer
end
if settings.name_identifier_format != nil
root.add_element "samlp:NameIDPolicy", {
root.add_element "samlp:NameIDPolicy", {
"xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol",
# Might want to make AllowCreate a setting?
"AllowCreate" => "true",
Expand All @@ -64,14 +65,14 @@ def create_authentication_xml_doc(settings)
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,
# match required for authentication to succeed. If this is not defined,
# the IdP will choose default rules for authentication. (Shibboleth IdP)
if settings.authn_context != nil
requested_context = root.add_element "samlp:RequestedAuthnContext", {
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", {
class_ref = requested_context.add_element "saml:AuthnContextClassRef", {
"xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion",
}
class_ref.text = settings.authn_context
Expand Down
3 changes: 2 additions & 1 deletion lib/onelogin/ruby-saml/settings.rb
Expand Up @@ -18,9 +18,10 @@ def initialize(overrides = {})
attr_accessor :compress_request
attr_accessor :double_quote_xml_attribute_values
attr_accessor :passive
attr_accessor :protocol_binding

private

DEFAULTS = {:compress_request => true, :double_quote_xml_attribute_values => false}
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/settings_test.rb
Expand Up @@ -12,7 +12,7 @@ class SettingsTest < Test::Unit::TestCase
:idp_sso_target_url, :idp_cert_fingerprint, :name_identifier_format,
:idp_slo_target_url, :name_identifier_value, :sessionindex,
:assertion_consumer_logout_service_url,
:passive
:passive, :protocol_binding
]

accessors.each do |accessor|
Expand All @@ -33,6 +33,7 @@ class SettingsTest < Test::Unit::TestCase
:idp_cert_fingerprint => "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
:name_identifier_format => "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
:passive => true,
:protocol_binding => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
}
@settings = Onelogin::Saml::Settings.new(config)

Expand Down

0 comments on commit b71bdf1

Please sign in to comment.