Skip to content

Commit ee0ce5b

Browse files
author
Torsten Schoenebaum
committed
Rename parse_options in IdpMetadataParser and improve its docs
1 parent c3321a1 commit ee0ce5b

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

lib/onelogin/ruby-saml/idp_metadata_parser.rb

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,61 @@ class IdpMetadataParser
2222

2323
attr_reader :document
2424
attr_reader :response
25-
attr_reader :parse_options
25+
attr_reader :options
2626

2727
# Parse the Identity Provider metadata and update the settings with the
2828
# IdP values
2929
#
30-
# @param (see IdpMetadataParser#get_idp_metadata)
31-
# @param parse_options [Hash] :settings to provide the OneLogin::RubySaml::Settings object or an hash for Settings overrides
32-
# @return (see IdpMetadataParser#get_idp_metadata)
33-
# @raise (see IdpMetadataParser#get_idp_metadata)
34-
def parse_remote(url, validate_cert = true, parse_options = {})
30+
# @param url [String] Url where the XML of the Identity Provider Metadata is published.
31+
# @param validate_cert [Boolean] If true and the URL is HTTPs, the cert of the domain is checked.
32+
#
33+
# @param options [Hash] options used for parsing the metadata and the returned Settings instance
34+
# @option options [OneLogin::RubySaml::Settings, Hash] :settings the OneLogin::RubySaml::Settings object which gets the parsed metadata merged into or an hash for Settings overrides.
35+
# @option options [Array<String>, nil] :sso_binding an ordered list of bindings to detect the single signon URL. The first binding in the list that is included in the metadata will be used.
36+
# @option options [Array<String>, nil] :slo_binding an ordered list of bindings to detect the single logout URL. The first binding in the list that is included in the metadata will be used.
37+
# @option options [String, nil] :entity_id when this is given, the entity descriptor for this ID is used. When ommitted, the first entity descriptor is used.
38+
#
39+
# @return [OneLogin::RubySaml::Settings]
40+
#
41+
# @raise [HttpError] Failure to fetch remote IdP metadata
42+
def parse_remote(url, validate_cert = true, options = {})
3543
idp_metadata = get_idp_metadata(url, validate_cert)
36-
parse(idp_metadata, parse_options)
44+
parse(idp_metadata, options)
3745
end
3846

3947
# Parse the Identity Provider metadata and return the results as Hash
4048
#
4149
# @param url [String] Url where the XML of the Identity Provider Metadata is published.
4250
# @param validate_cert [Boolean] If true and the URL is HTTPs, the cert of the domain is checked.
43-
# @param parse_options [Hash] :settings to provide the OneLogin::RubySaml::Settings object or an hash for Settings overrides
51+
#
52+
# @param options [Hash] options used for parsing the metadata
53+
# @option options [Array<String>, nil] :sso_binding an ordered list of bindings to detect the single signon URL. The first binding in the list that is included in the metadata will be used.
54+
# @option options [Array<String>, nil] :slo_binding an ordered list of bindings to detect the single logout URL. The first binding in the list that is included in the metadata will be used.
55+
# @option options [String, nil] :entity_id when this is given, the entity descriptor for this ID is used. When ommitted, the first entity descriptor is used.
56+
#
4457
# @return [Hash]
58+
#
4559
# @raise [HttpError] Failure to fetch remote IdP metadata
46-
def parse_remote_to_hash(url, validate_cert = true, parse_options = {})
60+
def parse_remote_to_hash(url, validate_cert = true, options = {})
4761
idp_metadata = get_idp_metadata(url, validate_cert)
48-
parse_to_hash(idp_metadata, parse_options)
62+
parse_to_hash(idp_metadata, options)
4963
end
5064

5165
# Parse the Identity Provider metadata and update the settings with the IdP values
5266
#
5367
# @param idp_metadata [String]
54-
# @param parse_options [Hash] :settings to provide the OneLogin::RubySaml::Settings object or an hash for Settings overrides
5568
#
56-
# @return [Settings]
57-
def parse(idp_metadata, parse_options = {})
58-
parsed_metadata = parse_to_hash(idp_metadata, parse_options)
69+
# @param options [Hash] :settings to provide the OneLogin::RubySaml::Settings object or an hash for Settings overrides
70+
# @option options [OneLogin::RubySaml::Settings, Hash] :settings the OneLogin::RubySaml::Settings object which gets the parsed metadata merged into or an hash for Settings overrides.
71+
# @option options [Array<String>, nil] :sso_binding an ordered list of bindings to detect the single signon URL. The first binding in the list that is included in the metadata will be used.
72+
# @option options [Array<String>, nil] :slo_binding an ordered list of bindings to detect the single logout URL. The first binding in the list that is included in the metadata will be used.
73+
# @option options [String, nil] :entity_id when this is given, the entity descriptor for this ID is used. When ommitted, the first entity descriptor is used.
74+
#
75+
# @return [OneLogin::RubySaml::Settings]
76+
def parse(idp_metadata, options = {})
77+
parsed_metadata = parse_to_hash(idp_metadata, options)
5978

60-
settings = parse_options[:settings]
79+
settings = options[:settings]
6180

6281
if settings.nil?
6382
OneLogin::RubySaml::Settings.new(parsed_metadata)
@@ -71,19 +90,23 @@ def parse(idp_metadata, parse_options = {})
7190
# Parse the Identity Provider metadata and return the results as Hash
7291
#
7392
# @param idp_metadata [String]
74-
# @param parse_options [Hash] :settings to provide the OneLogin::RubySaml::Settings object or an hash for Settings overrides
7593
#
76-
# @return [Settings]
77-
def parse_to_hash(idp_metadata, parse_options = {})
94+
# @param options [Hash] options used for parsing the metadata and the returned Settings instance
95+
# @option options [Array<String>, nil] :sso_binding an ordered list of bindings to detect the single signon URL. The first binding in the list that is included in the metadata will be used.
96+
# @option options [Array<String>, nil] :slo_binding an ordered list of bindings to detect the single logout URL. The first binding in the list that is included in the metadata will be used.
97+
# @option options [String, nil] :entity_id when this is given, the entity descriptor for this ID is used. When ommitted, the first entity descriptor is used.
98+
#
99+
# @return [Hash]
100+
def parse_to_hash(idp_metadata, options = {})
78101
@document = REXML::Document.new(idp_metadata)
79-
@parse_options = parse_options
102+
@options = options
80103
@entity_descriptor = nil
81104

82105
{
83106
:idp_entity_id => idp_entity_id,
84107
:name_identifier_format => idp_name_id_format,
85-
:idp_sso_target_url => single_signon_service_url(parse_options),
86-
:idp_slo_target_url => single_logout_service_url(parse_options),
108+
:idp_sso_target_url => single_signon_service_url(options),
109+
:idp_slo_target_url => single_logout_service_url(options),
87110
:idp_attribute_names => attribute_names,
88111
:idp_cert => nil,
89112
:idp_cert_fingerprint => nil,
@@ -136,7 +159,7 @@ def entity_descriptor
136159

137160
def entity_descriptor_path
138161
path = "//md:EntityDescriptor"
139-
entity_id = parse_options[:entity_id]
162+
entity_id = options[:entity_id]
140163
return path unless entity_id
141164
path << "[@entityID=\"#{entity_id}\"]"
142165
end
@@ -180,7 +203,7 @@ def single_signon_service_binding(binding_priority = nil)
180203
#
181204
def single_signon_service_url(options = {})
182205
binding = single_signon_service_binding(options[:sso_binding])
183-
unless binding.nil?
206+
unless binding.nil?
184207
node = REXML::XPath.first(
185208
entity_descriptor,
186209
"md:IDPSSODescriptor/md:SingleSignOnService[@Binding=\"#{binding}\"]/@Location",
@@ -240,7 +263,7 @@ def certificates
240263

241264
certs = nil
242265
unless signing_nodes.empty? && encryption_nodes.empty?
243-
certs = {}
266+
certs = {}
244267
unless signing_nodes.empty?
245268
certs['signing'] = []
246269
signing_nodes.each do |cert_node|

0 commit comments

Comments
 (0)