Skip to content

Commit

Permalink
Support multiple settings.auth_context
Browse files Browse the repository at this point in the history
**Why**: SAML supports multiple AuthnContextClassRef elements
in an Authn request.
  • Loading branch information
Peter Karman committed Jul 28, 2016
1 parent 7d48ca8 commit 7bbef08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/onelogin/ruby-saml/authrequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ def create_xml_document(settings)
}

if settings.authn_context != nil
class_ref = requested_context.add_element "saml:AuthnContextClassRef"
class_ref.text = settings.authn_context
authn_contexts = settings.authn_context.is_a?(Array) ? settings.authn_context : [settings.authn_context]
authn_contexts.each do |authn_context|
class_ref = requested_context.add_element "saml:AuthnContextClassRef"
class_ref.text = authn_context
end
end
# add saml:AuthnContextDeclRef element
if settings.authn_context_decl_ref != nil
Expand Down
7 changes: 7 additions & 0 deletions test/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ class RequestTest < Minitest::Test
assert_match /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/, auth_doc.to_s
end

it "create multiple saml:AuthnContextClassRef elements correctly" do
settings.authn_context = ['foo', 'bar']
auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
assert_match /<saml:AuthnContextClassRef>foo<\/saml:AuthnContextClassRef>/, auth_doc.to_s
assert_match /<saml:AuthnContextClassRef>bar<\/saml:AuthnContextClassRef>/, auth_doc.to_s
end

it "create the saml:AuthnContextClassRef with comparison exact" do
settings.authn_context = 'secure/name/password/uri'
auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
Expand Down

0 comments on commit 7bbef08

Please sign in to comment.