Permalink
Browse files

Added config option to build the ldap auth string

Made the auth string for LDAP auth the result of a builder (proc) when not connecting with an admin account

visibility fix
  • Loading branch information...
1 parent d8ce6ff commit 2cbb92e0ebe756be70737602fcfd4dd128057b75 Manuel Ryan committed with dpmcnevin Aug 10, 2010
Showing with 10 additions and 3 deletions.
  1. +3 −0 lib/devise_ldap_authenticatable.rb
  2. +7 −3 lib/devise_ldap_authenticatable/ldap_adapter.rb
View
3 lib/devise_ldap_authenticatable.rb
@@ -31,6 +31,9 @@ module Devise
mattr_accessor :ldap_use_admin_to_bind
@@ldap_use_admin_to_bind = false
+
+ mattr_accessor :ldap_auth_username_builder
+ @@ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "#{attribute}=#{login},#{ldap.base}" }
end
# Add ldap_authenticatable strategy to defaults.
View
10 lib/devise_ldap_authenticatable/ldap_adapter.rb
@@ -5,8 +5,11 @@ module Devise
module LdapAdapter
def self.valid_credentials?(login, password_plaintext)
- options = {:login => login, :password => password_plaintext}
- options.merge!({ :admin => true }) if ::Devise.ldap_use_admin_to_bind
+ options = {:login => login,
+ :password => password_plaintext,
+ :ldap_auth_username_builder => ::Devise.ldap_auth_username_builder,
+ :admin => ::Devise.ldap_use_admin_to_bind}
+
resource = LdapConnect.new(options)
resource.authorized?
end
@@ -35,6 +38,7 @@ def initialize(params = {})
@ldap.port = ldap_config["port"]
@ldap.base = ldap_config["base"]
@attribute = ldap_config["attribute"]
+ @ldap_auth_username_builder = params[:ldap_auth_username_builder]
@group_base = ldap_config["group_base"]
@required_groups = ldap_config["required_groups"]
@@ -53,7 +57,7 @@ def dn
ldap_entry = nil
@ldap.search(:filter => filter) {|entry| ldap_entry = entry}
if ldap_entry.nil?
- "#{@attribute}=#{@login},#{@ldap.base}"
+ @ldap_auth_username_builder.call(@attribute,@login,@ldap)
else
ldap_entry.dn
end

0 comments on commit 2cbb92e

Please sign in to comment.