diff options
author | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2012-11-29 16:56:26 +0100 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2012-11-29 17:27:05 +0100 |
commit | f59b78503c3e6ee39d13a0b1a959784cccca5da6 (patch) | |
tree | ea5d07cfda391d87299f09584b3c67a54319769a /app | |
parent | 1ddc5940e52d8db00ba204f99679bc5a271c425b (diff) | |
download | ecs2-f59b78503c3e6ee39d13a0b1a959784cccca5da6.tar.gz ecs2-f59b78503c3e6ee39d13a0b1a959784cccca5da6.zip |
Moved gc auth code to auths model.
Further made some testcode for auths handling.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/auth.rb | 48 | ||||
-rw-r--r-- | app/models/message.rb | 21 |
2 files changed, 52 insertions, 17 deletions
diff --git a/app/models/auth.rb b/app/models/auth.rb index d1ce104..6ffc164 100644 --- a/app/models/auth.rb +++ b/app/models/auth.rb @@ -5,4 +5,52 @@ class Auth < ActiveRecord::Base # :joins => {:membership_messages => {:membership => :participant}}, # :order => "id ASC", # :conditions => {:participants => {:id => participant.id}}}} + + + def test_validation_window + b = JSON.parse(message.body) + sov = Time.parse(b["sov"]) + eov = Time.parse(b["eov"]) + if sov > Time.now or eov < Time.now + false + else + true + end + end + + # garbage collect outtimed authorization tokens + def self.gc_outtimed + gc_sys_auths_lock= "#{Rails.root}/tmp/gc_sys_auths.lock" + if File.exists?(gc_sys_auths_lock) + logtext= "GC: there seems to be already running a ecs:gc_sys_auths process (#{gc_sys_auths_lock}). Aborting." + logger.info logtext + puts logtext unless Rails.env.test? + else + begin + File.open(gc_sys_auths_lock,"w") do |f| + f.puts "#{Process.pid}" + end + logtext= "GC: Searching for outtimed auths ..." + logger.info logtext + puts logtext unless Rails.env.test? + Auth.all.each do |auth| + if ! auth.test_validation_window + auth.message.destroy_as_sender + logtext= "GC: garbage collect auths token: #{auth.one_touch_hash}" + logger.info logtext + puts logtext unless Rails.env.test? + end + end + logtext= "GC: Searching for outtimed auths done." + logger.info logtext + puts logtext unless Rails.env.test? + ensure + begin + File.delete(gc_sys_auths_lock) + rescue + end + end + end + end + end diff --git a/app/models/message.rb b/app/models/message.rb index 8f225df..ca4c306 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -163,18 +163,6 @@ class Message < ActiveRecord::Base end end - def test_auths_validation_window - b = JSON.parse(body) - sov = Time.parse(b["sov"]) - eov = Time.parse(b["eov"]) - if sov > Time.now or eov < Time.now - false - else - true - end - end - - def self.filter(action_name, app_namespace, ressource_name, record, params) d="filter/#{app_namespace}/#{ressource_name}/#{action_name}/*" filters=Dir[d].collect{|f| File.directory?(f) ? f : nil}.compact @@ -291,23 +279,22 @@ class Message < ActiveRecord::Base resource_name == 'auths' and !memberships.empty? and !participant.sender?(self) and - !test_auths_validation_window + !auth.test_validation_window end - def valid_auths_resource_fetched_by_non_owner?(app_namespace, resource_name, memberships, participant) app_namespace == 'sys' and resource_name == 'auths' and !memberships.empty? and - !participant.sender?(@record) and - test_auths_validation_window + !participant.sender?(self) and + auth.test_validation_window end def valid_no_auths_resource_fetched_by_non_owner?(app_namespace, resource_name, memberships, participant) app_namespace != 'sys' and ressource_name != 'auths' and !memberships.empty? and - !participant.sender?(@record) + !participant.sender?(self) end # Helper function for create and update |