Skip to content

Commit

Permalink
Added config option to build the ldap auth string
Browse files Browse the repository at this point in the history
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
Manuel Ryan authored and dpmcnevin committed Aug 11, 2010
1 parent d8ce6ff commit 2cbb92e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/devise_ldap_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions lib/devise_ldap_authenticatable/ldap_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down

0 comments on commit 2cbb92e

Please sign in to comment.