From df90e53dce72a604172c606b1f661ec04cf25e55 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 8 Sep 2011 11:30:37 +0200 Subject: [PATCH] Select the authentication protocols available --- src/authm_mad/one_auth_mad.rb | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/authm_mad/one_auth_mad.rb b/src/authm_mad/one_auth_mad.rb index c1b9d6cd06..0b26c92f45 100755 --- a/src/authm_mad/one_auth_mad.rb +++ b/src/authm_mad/one_auth_mad.rb @@ -49,7 +49,9 @@ class AuthDriver < OpenNebulaDriver # # @param [String] the authorization method to be used, nil to use the # built-in ACL engine - def initialize(authZ, nthreads) + # @param [Array] authentication modules enabled, nil will use any + # any method existing in remotes directory + def initialize(authZ, authN, nthreads) super( "auth", :concurrency => nthreads, @@ -66,6 +68,20 @@ class AuthDriver < OpenNebulaDriver else @authZ_cmd = nil end + + if authN == nil + # get the directories from remotes dir that have an authenticate + # script + @authN_protocols=Dir[@local_scripts_path+"/*/authenticate"].map do |d| + d.split('/')[-2] + end + else + if authN.class==String + @authN_protocols=[authN] + else + @authN_protocols=authN + end + end end # Authenticate a user based in a string of the form user:secret when using the @@ -88,6 +104,14 @@ class AuthDriver < OpenNebulaDriver secret_attr.shift end + unless @authN_protocols.include?(protocol) + return send_message( + ACTION[:authN], + RESULT[:failure], + request_id, + "Authentication rotocol '#{protocol}' not available") + end + #build path for the auth action #/var/lib/one/remotes/auth//authenticate authN_path = File.join(@local_scripts_path, protocol) @@ -133,11 +157,13 @@ end # Auth Driver Main program opts = GetoptLong.new( [ '--threads', '-t', GetoptLong::REQUIRED_ARGUMENT ], - [ '--authz', '-z', GetoptLong::REQUIRED_ARGUMENT ] + [ '--authz', '-z', GetoptLong::REQUIRED_ARGUMENT ], + [ '--authn', '-n', GetoptLong::REQUIRED_ARGUMENT ] ) threads = 15 authz = nil +authn = nil begin opts.each do |opt, arg| @@ -146,12 +172,14 @@ begin threads = arg.to_i when '--authz' authz = arg + when '--authn' + authn = arg.split(',').map {|a| a.strip } end end rescue Exception => e exit(-1) end -auth_driver = AuthDriver.new(authz, threads) +auth_driver = AuthDriver.new(authz, authn, threads) auth_driver.start_driver