Class: OneLogin::RubySaml::IdpMetadataParser
- Inherits:
-
Object
- Object
- OneLogin::RubySaml::IdpMetadataParser
- Includes:
- SamlMetadata::Vocabulary
- Defined in:
- lib/onelogin/ruby-saml/idp_metadata_parser.rb
Overview
Auxiliary class to retrieve and parse the Identity Provider Metadata
This class does not validate in any way the URL that is introduced, make sure to validate it properly before use it in a parse_remote method. Read the ‘Security warning` section of the README.md file to get more info
Defined Under Namespace
Modules: SamlMetadata Classes: IdpMetadata
Constant Summary
Constants included from SamlMetadata::Vocabulary
SamlMetadata::Vocabulary::DSIG, SamlMetadata::Vocabulary::METADATA, SamlMetadata::Vocabulary::NAME_FORMAT, SamlMetadata::Vocabulary::SAML_ASSERTION
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.get_idps(metadata_document, only_entity_id = nil) ⇒ Object
fetch IdP descriptors from a metadata document.
Instance Method Summary collapse
-
#parse(idp_metadata, options = {}) ⇒ OneLogin::RubySaml::Settings
Parse the Identity Provider metadata and update the settings with the IdP values.
-
#parse_remote(url, validate_cert = true, options = {}) ⇒ OneLogin::RubySaml::Settings
Parse the Identity Provider metadata and update the settings with the IdP values.
-
#parse_remote_to_array(url, validate_cert = true, options = {}) ⇒ Array<Hash>
Parse all Identity Provider metadata and return the results as Array.
-
#parse_remote_to_hash(url, validate_cert = true, options = {}) ⇒ Hash
Parse the Identity Provider metadata and return the results as Hash.
-
#parse_to_array(idp_metadata, options = {}) ⇒ Array<Hash>
Parse all Identity Provider metadata and return the results as Array.
-
#parse_to_hash(idp_metadata, options = {}) ⇒ Hash
Parse the Identity Provider metadata and return the results as Hash.
- #parse_to_idp_metadata_array(idp_metadata, options = {}) ⇒ Object
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
37 38 39 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 37 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
39 40 41 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 39 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
38 39 40 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 38 def response @response end |
Class Method Details
.get_idps(metadata_document, only_entity_id = nil) ⇒ Object
fetch IdP descriptors from a metadata document
42 43 44 45 46 47 48 49 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 42 def self.get_idps(, only_entity_id=nil) path = "//md:EntityDescriptor#{only_entity_id && '[@entityID="' + only_entity_id + '"]'}/md:IDPSSODescriptor" REXML::XPath.match( , path, SamlMetadata::NAMESPACE ) end |
Instance Method Details
#parse(idp_metadata, options = {}) ⇒ OneLogin::RubySaml::Settings
Parse the Identity Provider metadata and update the settings with the IdP values
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 121 def parse(, = {}) = parse_to_hash(, ) unless [:cache_duration].nil? = OneLogin::RubySaml::Utils.parse_duration([:cache_duration]) unless .nil? if [:valid_until].nil? || < Time.parse([:valid_until], Time.now.utc).to_i [:valid_until] = Time.at().utc.strftime("%Y-%m-%dT%H:%M:%SZ") end end end # Remove the cache_duration because on the settings # we only gonna suppot valid_until .delete(:cache_duration) settings = [:settings] if settings.nil? OneLogin::RubySaml::Settings.new() elsif settings.is_a?(Hash) OneLogin::RubySaml::Settings.new(settings.merge()) else (settings, ) end end |
#parse_remote(url, validate_cert = true, options = {}) ⇒ OneLogin::RubySaml::Settings
Parse the Identity Provider metadata and update the settings with the IdP values
67 68 69 70 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 67 def parse_remote(url, validate_cert = true, = {}) = (url, validate_cert) parse(, ) end |
#parse_remote_to_array(url, validate_cert = true, options = {}) ⇒ Array<Hash>
Parse all Identity Provider metadata and return the results as Array
104 105 106 107 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 104 def parse_remote_to_array(url, validate_cert = true, = {}) = (url, validate_cert) parse_to_array(, ) end |
#parse_remote_to_hash(url, validate_cert = true, options = {}) ⇒ Hash
Parse the Identity Provider metadata and return the results as Hash
86 87 88 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 86 def parse_remote_to_hash(url, validate_cert = true, = {}) parse_remote_to_array(url, validate_cert, )[0] end |
#parse_to_array(idp_metadata, options = {}) ⇒ Array<Hash>
Parse all Identity Provider metadata and return the results as Array
173 174 175 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 173 def parse_to_array(, = {}) (, ).map { |idp_md| idp_md.to_hash() } end |
#parse_to_hash(idp_metadata, options = {}) ⇒ Hash
Parse the Identity Provider metadata and return the results as Hash
158 159 160 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 158 def parse_to_hash(, = {}) parse_to_array(, )[0] end |
#parse_to_idp_metadata_array(idp_metadata, options = {}) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/onelogin/ruby-saml/idp_metadata_parser.rb', line 177 def (, = {}) @document = REXML::Document.new() @options = idpsso_descriptors = self.class.get_idps(@document, [:entity_id]) if !idpsso_descriptors.any? raise ArgumentError.new("idp_metadata must contain an IDPSSODescriptor element") end idpsso_descriptors.map {|id| IdpMetadata.new(id, id.parent.attributes["entityID"])} end |