lib/global_session/directory.rb in global_session-1.0.0 vs lib/global_session/directory.rb in global_session-1.0.2

- old
+ new

@@ -1,5 +1,7 @@ +require 'set' + module GlobalSession # The global session directory, which provides some lookup and decision services # to instances of Session. # # The default implementation is simplistic, but should be suitable for most applications. @@ -27,11 +29,11 @@ # # If more than one key file is found, Directory will raise an error # at initialization time. # class Directory - attr_reader :configuration, :authorities, :private_key, :local_authority_name + attr_reader :configuration, :authorities, :private_key # Create a new Directory. # # === Parameters # keystore_directory(String):: Absolute path to authority keystore @@ -50,19 +52,24 @@ authority = basename[0...(basename.rindex('.'))] #chop trailing .ext @authorities[authority] = OpenSSL::PKey::RSA.new(File.read(cert_file)) raise ConfigurationError, "Expected #{basename} to contain an RSA public key" unless @authorities[authority].public? end - if (authority_name = @configuration['authority']) - key_file = keys.detect { |kf| kf =~ /#{authority_name}.key$/ } - raise ConfigurationError, "Key file #{authority_name}.key not found" unless key_file + if local_authority_name + key_file = keys.detect { |kf| kf =~ /#{local_authority_name}.key$/ } + raise ConfigurationError, "Key file #{local_authority_name}.key not found" unless key_file @private_key = OpenSSL::PKey::RSA.new(File.read(key_file)) raise ConfigurationError, "Expected #{key_file} to contain an RSA private key" unless @private_key.private? - @local_authority_name = authority_name end + + @invalid_sessions = Set.new end + def local_authority_name + @configuration['authority'] + end + # Determine whether this system trusts a particular authority based on # the trust settings specified in Configuration. # # === Parameters # authority(String):: The name of the authority @@ -83,21 +90,23 @@ # expired_at(Time):: When the session expired (or will expire) # # === Return # valid(true|false):: whether the specified session is valid def valid_session?(uuid, expired_at) - expired_at > Time.now + (expired_at > Time.now) && !@invalid_sessions.include?(uuid) end # Callback used by Session objects to report when the application code calls - # #invalidate! on them. The default implementation of this method does nothing. + # #invalidate! on them. The default implementation of this method records + # invalid session IDs using an in-memory data structure, which is not ideal + # for most implementations. # # uuid(String):: Global session UUID # expired_at(Time):: When the session expired # # === Return # true:: Always returns true def report_invalid_session(uuid, expired_at) - true + @invalid_sessions << uuid end end end \ No newline at end of file