Skip to content

Commit 15b5483

Browse files
committed
Performance: Memoize the SAML 2.0 Protocol object
1 parent 7cf0d87 commit 15b5483

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/ruby_saml/saml_message.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,19 @@ module RubySaml
1111
# SAML2 Message
1212
class SamlMessage
1313

14-
# @return [Nokogiri::XML::Schema] Gets the schema object of the SAML 2.0 Protocol schema
15-
#
14+
# @return [Nokogiri::XML::Schema] The SAML 2.0 Protocol schema
1615
def self.schema
17-
path = File.expand_path('schemas/saml-schema-protocol-2.0.xsd', __dir__)
18-
File.open(path) do |file|
16+
@schema ||= File.open(File.expand_path('schemas/saml-schema-protocol-2.0.xsd', __dir__)) do |file|
1917
::Nokogiri::XML::Schema(file)
2018
end
2119
end
2220

2321
# @return [String|nil] Gets the Version attribute from the SAML Message if exists.
24-
#
2522
def version(document)
2623
@version ||= root_attribute(document, 'Version')
2724
end
2825

2926
# @return [String|nil] Gets the ID attribute from the SAML Message if exists.
30-
#
3127
def id(document)
3228
@id ||= root_attribute(document, 'ID')
3329
end
@@ -55,7 +51,6 @@ def root_attribute(document, attribute)
5551
# @param check_malformed_doc [Boolean] check_malformed_doc Enable or Disable the check for malformed XML
5652
# @return [Boolean] True if the XML is valid, otherwise False, if soft=True
5753
# @raise [ValidationError] if soft == false and validation fails
58-
#
5954
def valid_saml?(document, soft = true, check_malformed_doc: true)
6055
begin
6156
xml = RubySaml::XML.safe_load_nokogiri(document, check_malformed_doc: check_malformed_doc)

0 commit comments

Comments
 (0)