Permalink
Browse files

Dup SOAP strings before caching them

Strings returned from SOAP contain singleton methods which cannot be
serialized.  This dups the string before attempting to cache it.
  • Loading branch information...
1 parent 61796d7 commit c54f37a96d393e2ede9c1a4b11f603dcc90b9484 @blt04 blt04 committed Mar 19, 2012
Showing with 20 additions and 10 deletions.
  1. +20 −10 lib/authlogic_crowd/session.rb
View
30 lib/authlogic_crowd/session.rb
@@ -34,12 +34,11 @@ def crowd_user_token= token
token = token.dup if token
session_user_token = controller && controller.session[:"crowd.token_key"]
cookie_user_token = crowd_sso? && controller && controller.cookies[:"crowd.token_key"]
- cached_info = Rails.cache.read('crowd_cookie_info')
@crowd_client ||= SimpleCrowd::Client.new({
:service_url => klass.crowd_service_url,
:app_name => klass.crowd_app_name,
:app_password => klass.crowd_app_password})
- crowd_cookie_info ||= cached_info || @crowd_client.get_cookie_info
+ crowd_cookie_info = Rails.cache.fetch('crowd_cookie_info') { @crowd_client.get_cookie_info }
controller.session[:"crowd.token_key"] = token unless session_user_token == token || !controller
controller.cookies[:"crowd.token_key"] = {:domain => crowd_cookie_info[:domain],
:secure => crowd_cookie_info[:secure],
@@ -266,17 +265,28 @@ def crowd_client
@crowd_client ||= SimpleCrowd::Client.new(crowd_config)
end
def load_crowd_app_token
- cached_token = Rails.cache.read('crowd_app_token')
- crowd_client.app_token = cached_token unless cached_token.nil?
- Rails.cache.write('crowd_app_token', crowd_client.app_token) unless cached_token == crowd_client.app_token
+ crowd_app_token = Rails.cache.read('crowd_app_token')
+ if crowd_app_token.nil?
+ crowd_app_token = crowd_client.app_token
+ # Strings returned by crowd contain singleton methods which cannot
+ # be serialized into the Rails.cache. Duping the strings removes the
+ # singleton methods.
+ Rails.cache.write('crowd_app_token', crowd_app_token.dup)
+ else
+ crowd_client.app_token = crowd_app_token
+ end
+ crowd_app_token
end
def crowd_cookie_info
- unless @crowd_cookie_info
- cached_info = Rails.cache.read('crowd_cookie_info')
- @crowd_cookie_info ||= cached_info || crowd_client.get_cookie_info
- Rails.cache.write('crowd_cookie_info', @crowd_cookie_info) unless cached_info == @crowd_cookie_info
+ @crowd_cookie_info ||= Rails.cache.fetch('crowd_cookie_info') do
+ # Strings returned by crowd contain singleton methods which cannot
+ # be serialized into the Rails.cache. Do a shallow dup of each string
+ # in the returned hash
+ crowd_client.get_cookie_info.inject({}) do |cookie_info, (key, val)|
+ cookie_info[key] = val ? val.dup : val
+ cookie_info
+ end
end
- @crowd_cookie_info
end
def crowd_config
{:service_url => klass.crowd_service_url,

0 comments on commit c54f37a

Please sign in to comment.