diff --git a/src/cloud/common/CloudAuth.rb b/src/cloud/common/CloudAuth.rb index f3fe29ca15..b69934dd81 100644 --- a/src/cloud/common/CloudAuth.rb +++ b/src/cloud/common/CloudAuth.rb @@ -44,8 +44,11 @@ class CloudAuth def initialize(conf) @conf = conf + # @token_expiration_delta: Number of seconds that will be used + # the same timestamp for the token generation + # @token_expiration_time: Current timestamp to be used in tokens. @token_expiration_delta = @conf[:token_expiration_delta] || EXPIRE_DELTA - @token_expiration_time = Time.now.to_i + @token_expiration_delta + @token_expiration_time = Time.now.to_i + @token_expiration_delta if AUTH_MODULES.include?(@conf[:auth]) require 'CloudAuth/' + AUTH_MODULES[@conf[:auth]] @@ -78,14 +81,23 @@ class CloudAuth Client.new(token,@conf[:one_xmlrpc]) end + def update_userpool_cache + @user_pool = OpenNebula::UserPool.new(client) + + rc = @user_pool.info + if OpenNebula.is_error?(rc) + raise rc.message + end + end + protected def expiration_time time_now = Time.now.to_i if time_now > @token_expiration_time - EXPIRE_MARGIN - update_userpool_cache @token_expiration_time = time_now + @token_expiration_delta + update_userpool_cache end @token_expiration_time @@ -97,15 +109,6 @@ class CloudAuth @user_pool end - def update_userpool_cache - @user_pool = OpenNebula::UserPool.new(client) - - rc = @user_pool.info - if OpenNebula.is_error?(rc) - raise rc.message - end - end - def get_password(username, non_public_user=false) if non_public_user == true xp="USER[NAME=\"#{username}\" and AUTH_DRIVER!=\"public\"]/PASSWORD" diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index e901caa82c..009072ae38 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -89,6 +89,7 @@ helpers do def build_session begin + settings.cloud_auth.update_userpool_cache result = settings.cloud_auth.auth(request.env, params) rescue Exception => e error 500, e.message