Method: OpenNebula::LdapAuth#initialize

Defined in:
lib/opennebula/ldap_auth.rb

#initialize(options) ⇒ LdapAuth

Returns a new instance of LdapAuth.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/opennebula/ldap_auth.rb', line 37

def initialize(options)
    @options={
        :host               => 'localhost',
        :port               => 389,
        :user               => nil,
        :password           => nil,
        :base               => nil,
        :group_base         => nil,
        :auth_method        => :simple,
        :user_field         => 'cn',
        :user_group_field   => 'dn',
        :group_field        => 'member',
        :mapping_generate   => true,
        :mapping_timeout    => 300,
        :mapping_filename   => 'server1.yaml',
        :mapping_key        => 'GROUP_DN',
        :mapping_default    => 1,
        :attributes         => [ "memberOf" ],
        :rfc2307bis         => true,
        :group_admin_group_dn => nil
    }.merge(options)

    ops={}

    if @options[:user]
        ops[:auth] = {
            :method => @options[:auth_method],
            :username => @options[:user],
            :password => @options[:password]
        }
    end

    # always fetch user_filed to compare whitespace diff
    @options[:attributes] << @options[:user_field]

    # fetch the user group field only if we need that
    if @options[:group] or !@options[:rfc2307bis]
        @options[:attributes] << @options[:user_group_field]
    end

    ops[:host]=@options[:host] if @options[:host]
    ops[:port]=@options[:port].to_i if @options[:port]
    ops[:encryption]=@options[:encryption] if @options[:encryption]

    @options[:mapping_file_path] = VAR_LOCATION + @options[:mapping_filename]
    generate_mapping if @options[:mapping_generate]
    load_mapping

    @ldap=Net::LDAP.new(ops)
end