SunstoneCloudAuth.rb

Rolandas Naujikas, 02/25/2012 08:45 PM

Download (1.81 KB)

 
1
# -------------------------------------------------------------------------- #
2
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)             #
3
#                                                                            #
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
5
# not use this file except in compliance with the License. You may obtain    #
6
# a copy of the License at                                                   #
7
#                                                                            #
8
# http://www.apache.org/licenses/LICENSE-2.0                                 #
9
#                                                                            #
10
# Unless required by applicable law or agreed to in writing, software        #
11
# distributed under the License is distributed on an "AS IS" BASIS,          #
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13
# See the License for the specific language governing permissions and        #
14
# limitations under the License.                                             #
15
#--------------------------------------------------------------------------- #
16

    
17
module SunstoneCloudAuth
18
    def do_auth(env, params={})
19
        auth = Rack::Auth::Basic::Request.new(env)
20

    
21
        if auth.provided? && auth.basic?
22
            username, password = auth.credentials
23
            begin
24
                client = OpenNebula::Client.new("#{username}:#{password}", "http://cloud00.mif:2633/RPC2")
25
                user_pool = OpenNebula::UserPool.new(client)
26
                rc = user_pool.info
27
                if OpenNebula.is_error?(rc)
28
                    return nil
29
                end
30
            rescue Exception => e
31
                return nil
32
            end
33
            return username
34
        end
35

    
36
        return nil
37
    end
38
end