lib/adauth/user.rb in adauth-1.0.1 vs lib/adauth/user.rb in adauth-1.1.0
- old
+ new
@@ -15,11 +15,13 @@
}
# Multi values were the method needs to return an array for values.
ATTR_MV = {
:groups => [ :memberof,
- Proc.new {|g| g.sub(/.*?CN=(.*?),.*/, '\1')} ]
+ Proc.new {|g| g.sub(/.*?CN=(.*?),.*/, '\1')} ],
+ :ous => [ :memberof,
+ Proc.new {|g| g.sub(/.*?OU=(.*?),.*/, '\1')} ]
}
# Authenticates a user against Active Directory and returns an instance of self
#
# Called as:
@@ -32,11 +34,11 @@
:port => Adauth.config.port,
:base => Adauth.config.base,
:auth => { :username => "#{login}@#{Adauth.config.domain}",
:password => pass,
:method => :simple }
- if conn.bind and user = conn.search(:filter => "sAMAccountName=#{login}").first
+ if conn.bind and user = conn.search(:filter => Net::LDAP::Filter.eq('sAMAccountName', login)).first
return self.new(user)
else
return nil
end
rescue Net::LDAP::LdapError => e
@@ -64,11 +66,11 @@
generate_multi_value_readers
end
end
def self.generate_single_value_readers
- ATTR_SV.each_pair do |k, v|
+ ATTR_SV.merge(Adauth.config.ad_sv_attrs).each_pair do |k, v|
val, block = Array(v)
define_method(k) do
if @entry.attribute_names.include?(val)
if block.is_a?(Proc)
return block[@entry.send(val).to_s]
@@ -81,10 +83,10 @@
end
end
end
def self.generate_multi_value_readers
- ATTR_MV.each_pair do |k, v|
+ ATTR_MV.merge(Adauth.config.ad_mv_attrs).each_pair do |k, v|
val, block = Array(v)
define_method(k) do
if @entry.attribute_names.include?(val)
if block.is_a?(Proc)
return @entry.send(val).collect(&block)
\ No newline at end of file