devise_ldap_authenticatable 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.gitignore +5 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +4 -1
  4. data/Rakefile +52 -0
  5. data/VERSION +1 -0
  6. data/devise_ldap_authenticatable.gemspec +166 -0
  7. data/lib/devise_ldap_authenticatable.rb +3 -0
  8. data/lib/devise_ldap_authenticatable/ldap_adapter.rb +14 -4
  9. data/lib/devise_ldap_authenticatable/model.rb +26 -26
  10. data/lib/devise_ldap_authenticatable/version.rb +1 -1
  11. data/lib/generators/devise_ldap_authenticatable/install_generator.rb +2 -0
  12. data/rails/init.rb +2 -0
  13. data/test/devise_ldap_authenticatable_test.rb +8 -0
  14. data/test/ldap/base.ldif +54 -0
  15. data/test/ldap/clear.ldif +20 -0
  16. data/test/ldap/local.schema +6 -0
  17. data/test/ldap/run-server.sh +4 -0
  18. data/test/ldap/slapd-test.conf +106 -0
  19. data/test/rails_app/Gemfile +22 -0
  20. data/test/rails_app/Rakefile +7 -0
  21. data/test/rails_app/app/controllers/application_controller.rb +4 -0
  22. data/test/rails_app/app/controllers/posts_controller.rb +15 -0
  23. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  24. data/test/rails_app/app/helpers/posts_helper.rb +2 -0
  25. data/test/rails_app/app/models/post.rb +2 -0
  26. data/test/rails_app/app/models/user.rb +10 -0
  27. data/test/rails_app/app/views/layouts/application.html.erb +26 -0
  28. data/test/rails_app/app/views/posts/index.html.erb +2 -0
  29. data/test/rails_app/config.ru +4 -0
  30. data/test/rails_app/config/application.rb +46 -0
  31. data/test/rails_app/config/boot.rb +13 -0
  32. data/test/rails_app/config/cucumber.yml +8 -0
  33. data/test/rails_app/config/database.yml +25 -0
  34. data/test/rails_app/config/environment.rb +5 -0
  35. data/test/rails_app/config/environments/development.rb +22 -0
  36. data/test/rails_app/config/environments/production.rb +46 -0
  37. data/test/rails_app/config/environments/test.rb +34 -0
  38. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/rails_app/config/initializers/devise.rb +140 -0
  40. data/test/rails_app/config/initializers/inflections.rb +10 -0
  41. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  42. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  43. data/test/rails_app/config/initializers/session_store.rb +8 -0
  44. data/test/rails_app/config/ldap.yml +33 -0
  45. data/test/rails_app/config/ldap_with_uid.yml +30 -0
  46. data/test/rails_app/config/locales/devise.en.yml +39 -0
  47. data/test/rails_app/config/locales/en.yml +5 -0
  48. data/test/rails_app/config/routes.rb +64 -0
  49. data/test/rails_app/db/migrate/20100708120302_create_posts.rb +14 -0
  50. data/test/rails_app/db/migrate/20100708120448_devise_create_users.rb +26 -0
  51. data/test/rails_app/db/schema.rb +41 -0
  52. data/test/rails_app/db/seeds.rb +7 -0
  53. data/test/rails_app/features/manage_logins.feature +34 -0
  54. data/test/rails_app/features/step_definitions/login_steps.rb +16 -0
  55. data/test/rails_app/features/step_definitions/web_steps.rb +219 -0
  56. data/test/rails_app/features/support/env.rb +58 -0
  57. data/test/rails_app/features/support/paths.rb +38 -0
  58. data/test/rails_app/lib/tasks/.gitkeep +0 -0
  59. data/test/rails_app/lib/tasks/cucumber.rake +53 -0
  60. data/test/rails_app/public/404.html +26 -0
  61. data/test/rails_app/public/422.html +26 -0
  62. data/test/rails_app/public/500.html +26 -0
  63. data/test/rails_app/public/images/rails.png +0 -0
  64. data/test/rails_app/public/javascripts/application.js +2 -0
  65. data/test/rails_app/public/javascripts/controls.js +965 -0
  66. data/test/rails_app/public/javascripts/dragdrop.js +974 -0
  67. data/test/rails_app/public/javascripts/effects.js +1123 -0
  68. data/test/rails_app/public/javascripts/prototype.js +4874 -0
  69. data/test/rails_app/public/javascripts/rails.js +118 -0
  70. data/test/rails_app/public/stylesheets/.gitkeep +0 -0
  71. data/test/rails_app/script/cucumber +10 -0
  72. data/test/rails_app/script/rails +6 -0
  73. data/test/rails_app/test/factories/users.rb +9 -0
  74. data/test/rails_app/test/functional/posts_controller_test.rb +58 -0
  75. data/test/rails_app/test/performance/browsing_test.rb +9 -0
  76. data/test/rails_app/test/test_helper.rb +22 -0
  77. data/test/rails_app/test/unit/helpers/posts_helper_test.rb +4 -0
  78. data/test/rails_app/test/unit/post_test.rb +8 -0
  79. data/test/rails_app/test/unit/user_test.rb +172 -0
  80. data/test/test_helper.rb +3 -0
  81. metadata +140 -30
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .bundle
2
+ log
3
+ *.sqlite3
4
+ openldap-data
5
+ test/rails_app/tmp
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Curtis Schiewek
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -62,6 +62,7 @@ Devise LDAP Authenticatable works in replacement of Database Authenticatable
62
62
 
63
63
  This devise plugin has not been tested with DatabaseAuthenticatable enabled at the same time. This is meant as a drop in replacement for DatabaseAuthenticatable allowing for a semi single sign on approach.
64
64
 
65
+ The field that is used for logins is the first key that's configured in the `config/devise.rb` file under `config.authentication_keys`, which by default is email. For help changing this, please see the [Railscast](http://railscasts.com/episodes/210-customizing-devise) that goes through how to customize Devise.
65
66
 
66
67
  Configuration
67
68
  -------------
@@ -81,7 +82,6 @@ In initializer `config/initializers/devise.rb` :
81
82
  * ldap\_update\_password _(default: true)_
82
83
  * When doing password resets, if true will update the LDAP server. Requires admin password in the ldap.yml
83
84
 
84
-
85
85
  * ldap\_check\_group_membership _(default: false)_
86
86
  * When set to true, the user trying to login will be checked to make sure they are in all of groups specified in the ldap.yml file.
87
87
 
@@ -89,6 +89,9 @@ In initializer `config/initializers/devise.rb` :
89
89
  * ldap\_check\_attributes _(default: false)_
90
90
  * When set to true, the user trying to login will be checked to make sure they have all of the attributes in the ldap.yml file.
91
91
 
92
+ * ldap\_use\_admin\_to\_bind _(default: false)_
93
+ * When set to true, the admin user will be used to bind to the LDAP server during authentication.
94
+
92
95
  Testing
93
96
  -------
94
97
 
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the devise_imapable plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ # t.libs << 'lib'
11
+ # t.libs << 'test'
12
+ # t.pattern = 'test/**/*_test.rb'
13
+ # t.verbose = true
14
+ puts <<-eof
15
+
16
+ *** NOTICE ***
17
+
18
+ All tests are done in the sample Rails app.
19
+
20
+ Please go to test/rails_app and run the tests there.
21
+
22
+ Make sure to bundle install and rake db:migrate
23
+
24
+ eof
25
+ end
26
+
27
+ desc 'Generate documentation for the devise_ldap_authenticatable plugin.'
28
+ Rake::RDocTask.new(:rdoc) do |rdoc|
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = 'DeviseLDAPAuthenticatable'
31
+ rdoc.options << '--line-numbers' << '--inline-source'
32
+ rdoc.rdoc_files.include('README')
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ end
35
+
36
+
37
+ begin
38
+ require 'jeweler'
39
+ Jeweler::Tasks.new do |gemspec|
40
+ gemspec.name = "devise_ldap_authenticatable"
41
+ gemspec.summary = "LDAP authentication module for Devise"
42
+ gemspec.description = "LDAP authentication module for Devise"
43
+ gemspec.email = "curtis.schiewek@gmail.com"
44
+ gemspec.homepage = "http://github.com/cschiewek/devise_ldap_authenticatable"
45
+ gemspec.authors = ["Curtis Schiewek"]
46
+ gemspec.add_runtime_dependency "devise", "> 1.0.4"
47
+ gemspec.add_runtime_dependency "net-ldap", ">= 0.0.0"
48
+ end
49
+ Jeweler::GemcutterTasks.new
50
+ rescue LoadError
51
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.1
@@ -0,0 +1,166 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{devise_ldap_authenticatable}
8
+ s.version = "0.4.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Curtis Schiewek"]
12
+ s.date = %q{2010-08-01}
13
+ s.description = %q{LDAP authentication module for Devise}
14
+ s.email = %q{curtis.schiewek@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "devise_ldap_authenticatable.gemspec",
25
+ "lib/devise_ldap_authenticatable.rb",
26
+ "lib/devise_ldap_authenticatable/exception.rb",
27
+ "lib/devise_ldap_authenticatable/ldap_adapter.rb",
28
+ "lib/devise_ldap_authenticatable/logger.rb",
29
+ "lib/devise_ldap_authenticatable/model.rb",
30
+ "lib/devise_ldap_authenticatable/routes.rb",
31
+ "lib/devise_ldap_authenticatable/schema.rb",
32
+ "lib/devise_ldap_authenticatable/strategy.rb",
33
+ "lib/devise_ldap_authenticatable/version.rb",
34
+ "lib/generators/devise_ldap_authenticatable/install_generator.rb",
35
+ "lib/generators/devise_ldap_authenticatable/templates/ldap.yml",
36
+ "rails/init.rb",
37
+ "test/devise_ldap_authenticatable_test.rb",
38
+ "test/ldap/base.ldif",
39
+ "test/ldap/clear.ldif",
40
+ "test/ldap/local.schema",
41
+ "test/ldap/run-server.sh",
42
+ "test/ldap/slapd-test.conf",
43
+ "test/rails_app/Gemfile",
44
+ "test/rails_app/Rakefile",
45
+ "test/rails_app/app/controllers/application_controller.rb",
46
+ "test/rails_app/app/controllers/posts_controller.rb",
47
+ "test/rails_app/app/helpers/application_helper.rb",
48
+ "test/rails_app/app/helpers/posts_helper.rb",
49
+ "test/rails_app/app/models/post.rb",
50
+ "test/rails_app/app/models/user.rb",
51
+ "test/rails_app/app/views/layouts/application.html.erb",
52
+ "test/rails_app/app/views/posts/index.html.erb",
53
+ "test/rails_app/config.ru",
54
+ "test/rails_app/config/application.rb",
55
+ "test/rails_app/config/boot.rb",
56
+ "test/rails_app/config/cucumber.yml",
57
+ "test/rails_app/config/database.yml",
58
+ "test/rails_app/config/environment.rb",
59
+ "test/rails_app/config/environments/development.rb",
60
+ "test/rails_app/config/environments/production.rb",
61
+ "test/rails_app/config/environments/test.rb",
62
+ "test/rails_app/config/initializers/backtrace_silencers.rb",
63
+ "test/rails_app/config/initializers/devise.rb",
64
+ "test/rails_app/config/initializers/inflections.rb",
65
+ "test/rails_app/config/initializers/mime_types.rb",
66
+ "test/rails_app/config/initializers/secret_token.rb",
67
+ "test/rails_app/config/initializers/session_store.rb",
68
+ "test/rails_app/config/ldap.yml",
69
+ "test/rails_app/config/ldap_with_uid.yml",
70
+ "test/rails_app/config/locales/devise.en.yml",
71
+ "test/rails_app/config/locales/en.yml",
72
+ "test/rails_app/config/routes.rb",
73
+ "test/rails_app/db/migrate/20100708120302_create_posts.rb",
74
+ "test/rails_app/db/migrate/20100708120448_devise_create_users.rb",
75
+ "test/rails_app/db/schema.rb",
76
+ "test/rails_app/db/seeds.rb",
77
+ "test/rails_app/features/manage_logins.feature",
78
+ "test/rails_app/features/step_definitions/login_steps.rb",
79
+ "test/rails_app/features/step_definitions/web_steps.rb",
80
+ "test/rails_app/features/support/env.rb",
81
+ "test/rails_app/features/support/paths.rb",
82
+ "test/rails_app/lib/tasks/.gitkeep",
83
+ "test/rails_app/lib/tasks/cucumber.rake",
84
+ "test/rails_app/public/404.html",
85
+ "test/rails_app/public/422.html",
86
+ "test/rails_app/public/500.html",
87
+ "test/rails_app/public/images/rails.png",
88
+ "test/rails_app/public/javascripts/application.js",
89
+ "test/rails_app/public/javascripts/controls.js",
90
+ "test/rails_app/public/javascripts/dragdrop.js",
91
+ "test/rails_app/public/javascripts/effects.js",
92
+ "test/rails_app/public/javascripts/prototype.js",
93
+ "test/rails_app/public/javascripts/rails.js",
94
+ "test/rails_app/public/stylesheets/.gitkeep",
95
+ "test/rails_app/script/cucumber",
96
+ "test/rails_app/script/rails",
97
+ "test/rails_app/test/factories/users.rb",
98
+ "test/rails_app/test/functional/posts_controller_test.rb",
99
+ "test/rails_app/test/performance/browsing_test.rb",
100
+ "test/rails_app/test/test_helper.rb",
101
+ "test/rails_app/test/unit/helpers/posts_helper_test.rb",
102
+ "test/rails_app/test/unit/post_test.rb",
103
+ "test/rails_app/test/unit/user_test.rb",
104
+ "test/test_helper.rb"
105
+ ]
106
+ s.homepage = %q{http://github.com/cschiewek/devise_ldap_authenticatable}
107
+ s.rdoc_options = ["--charset=UTF-8"]
108
+ s.require_paths = ["lib"]
109
+ s.rubygems_version = %q{1.3.7}
110
+ s.summary = %q{LDAP authentication module for Devise}
111
+ s.test_files = [
112
+ "test/devise_ldap_authenticatable_test.rb",
113
+ "test/rails_app/app/controllers/application_controller.rb",
114
+ "test/rails_app/app/controllers/posts_controller.rb",
115
+ "test/rails_app/app/helpers/application_helper.rb",
116
+ "test/rails_app/app/helpers/posts_helper.rb",
117
+ "test/rails_app/app/models/post.rb",
118
+ "test/rails_app/app/models/user.rb",
119
+ "test/rails_app/config/application.rb",
120
+ "test/rails_app/config/boot.rb",
121
+ "test/rails_app/config/environment.rb",
122
+ "test/rails_app/config/environments/development.rb",
123
+ "test/rails_app/config/environments/production.rb",
124
+ "test/rails_app/config/environments/test.rb",
125
+ "test/rails_app/config/initializers/backtrace_silencers.rb",
126
+ "test/rails_app/config/initializers/devise.rb",
127
+ "test/rails_app/config/initializers/inflections.rb",
128
+ "test/rails_app/config/initializers/mime_types.rb",
129
+ "test/rails_app/config/initializers/secret_token.rb",
130
+ "test/rails_app/config/initializers/session_store.rb",
131
+ "test/rails_app/config/routes.rb",
132
+ "test/rails_app/db/migrate/20100708120302_create_posts.rb",
133
+ "test/rails_app/db/migrate/20100708120448_devise_create_users.rb",
134
+ "test/rails_app/db/schema.rb",
135
+ "test/rails_app/db/seeds.rb",
136
+ "test/rails_app/features/step_definitions/login_steps.rb",
137
+ "test/rails_app/features/step_definitions/web_steps.rb",
138
+ "test/rails_app/features/support/env.rb",
139
+ "test/rails_app/features/support/paths.rb",
140
+ "test/rails_app/test/factories/users.rb",
141
+ "test/rails_app/test/functional/posts_controller_test.rb",
142
+ "test/rails_app/test/performance/browsing_test.rb",
143
+ "test/rails_app/test/test_helper.rb",
144
+ "test/rails_app/test/unit/helpers/posts_helper_test.rb",
145
+ "test/rails_app/test/unit/post_test.rb",
146
+ "test/rails_app/test/unit/user_test.rb",
147
+ "test/test_helper.rb"
148
+ ]
149
+
150
+ if s.respond_to? :specification_version then
151
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
152
+ s.specification_version = 3
153
+
154
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
155
+ s.add_runtime_dependency(%q<devise>, ["> 1.0.4"])
156
+ s.add_runtime_dependency(%q<net-ldap>, [">= 0.0.0"])
157
+ else
158
+ s.add_dependency(%q<devise>, ["> 1.0.4"])
159
+ s.add_dependency(%q<net-ldap>, [">= 0.0.0"])
160
+ end
161
+ else
162
+ s.add_dependency(%q<devise>, ["> 1.0.4"])
163
+ s.add_dependency(%q<net-ldap>, [">= 0.0.0"])
164
+ end
165
+ end
166
+
@@ -28,6 +28,9 @@ module Devise
28
28
 
29
29
  mattr_accessor :ldap_check_attributes
30
30
  @@ldap_check_role_attribute = false
31
+
32
+ mattr_accessor :ldap_use_admin_to_bind
33
+ @@ldap_use_admin_to_bind = false
31
34
  end
32
35
 
33
36
  # Add ldap_authenticatable strategy to defaults.
@@ -5,7 +5,9 @@ module Devise
5
5
  module LdapAdapter
6
6
 
7
7
  def self.valid_credentials?(login, password_plaintext)
8
- resource = LdapConnect.new(:login => login, :password => password_plaintext)
8
+ options = {:login => login, :password => password_plaintext}
9
+ options.merge({ :admin => true }) if ::Devise.ldap_use_admin_to_bind
10
+ resource = LdapConnect.new(options)
9
11
  resource.authorized?
10
12
  end
11
13
 
@@ -21,7 +23,7 @@ module Devise
21
23
 
22
24
  class LdapConnect
23
25
 
24
- attr_reader :ldap, :login #, :base, :attribute, :required_groups, :login, :password, :new_password
26
+ attr_reader :ldap, :login
25
27
 
26
28
  def initialize(params = {})
27
29
  ldap_config = YAML.load_file(::Devise.ldap_config || "#{Rails.root}/config/ldap.yml")[Rails.env]
@@ -45,7 +47,15 @@ module Devise
45
47
  end
46
48
 
47
49
  def dn
48
- "#{@attribute}=#{@login},#{@ldap.base}"
50
+ DeviseLdapAuthenticatable::Logger.send("LDAP search: #{@attribute}=#{@login}")
51
+ filter = Net::LDAP::Filter.eq(@attribute.to_s, @login.to_s)
52
+ ldap_entry = nil
53
+ @ldap.search(:filter => filter) {|entry| ldap_entry = entry}
54
+ if ldap_entry.nil?
55
+ "#{@attribute}=#{@login},#{@ldap.base}"
56
+ else
57
+ ldap_entry.dn
58
+ end
49
59
  end
50
60
 
51
61
  def authenticate!
@@ -149,4 +159,4 @@ module Devise
149
159
 
150
160
  end
151
161
 
152
- end
162
+ end
@@ -13,25 +13,29 @@ module Devise
13
13
  extend ActiveSupport::Concern
14
14
 
15
15
  included do
16
- attr_reader :password, :current_password
16
+ attr_reader :current_password, :password
17
17
  attr_accessor :password_confirmation
18
18
  end
19
19
 
20
- def password=(new_password)
21
- @password = new_password
22
-
23
- if @password.present?
24
- Devise::LdapAdapter.update_password(self.email, password) if ::Devise.ldap_update_password
20
+ def login_with
21
+ self[::Devise.authentication_keys.first]
22
+ end
23
+
24
+ def reset_password!(new_password, new_password_confirmation)
25
+ if new_password == new_password_confirmation && ::Devise.ldap_update_password
26
+ Devise::LdapAdapter.update_password(login_with, new_password)
25
27
  end
28
+ clear_reset_password_token if valid?
29
+ save
26
30
  end
27
31
 
28
- ## FIXME find out how to get rid of this.
29
- def clean_up_passwords
32
+ def password=(new_password)
33
+ @password = new_password
30
34
  end
31
35
 
32
36
  # Checks if a resource is valid upon authentication.
33
37
  def valid_ldap_authentication?(password)
34
- if Devise::LdapAdapter.valid_credentials?(self.email, password)
38
+ if Devise::LdapAdapter.valid_credentials?(login_with, password)
35
39
  return true
36
40
  else
37
41
  return false
@@ -39,39 +43,35 @@ module Devise
39
43
  end
40
44
 
41
45
  def ldap_groups
42
- Devise::LdapAdapter.get_groups(self.email)
46
+ Devise::LdapAdapter.get_groups(login_with)
43
47
  end
44
48
 
45
49
  module ClassMethods
46
50
  # Authenticate a user based on configured attribute keys. Returns the
47
51
  # authenticated user if it's valid or nil.
48
52
  def authenticate_with_ldap(attributes={})
49
- return nil unless attributes[:email].present?
50
- conditions = attributes.slice(:email)
53
+ @login_with = ::Devise.authentication_keys.first
54
+ return nil unless attributes[@login_with].present?
51
55
 
52
- unless conditions[:email]
53
- conditions[:email] = "#{conditions[:email]}"
54
- end
55
-
56
- resource = find_for_ldap_authentication(conditions)
57
-
56
+ # resource = find_for_ldap_authentication(conditions)
57
+ resource = scoped.where(@login_with => attributes[@login_with]).first
58
+
58
59
  if (resource.blank? and ::Devise.ldap_create_user)
59
- resource = new(conditions.merge({:password => attributes[:password]}))
60
+ resource = new
61
+ resource[@login_with] = attributes[@login_with]
62
+ resource.password = attributes[:password]
60
63
  end
61
-
64
+
62
65
  if resource.try(:valid_ldap_authentication?, attributes[:password])
63
66
  resource.save if resource.new_record?
64
67
  return resource
65
68
  else
66
69
  return nil
67
70
  end
68
-
69
71
  end
70
-
71
- protected
72
-
73
- def find_for_ldap_authentication(conditions)
74
- scoped.where(conditions).first
72
+
73
+ def update_with_password(resource)
74
+ puts "UPDATE_WITH_PASSWORD: #{resource.inspect}"
75
75
  end
76
76
 
77
77
  end
@@ -1,4 +1,4 @@
1
1
  module DeviseLdapAuthenticatable
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
4
4
 
@@ -34,6 +34,8 @@ module DeviseLdapAuthenticatable
34
34
  # config.ldap_config = "\#{Rails.root}/config/ldap.yml"
35
35
  # config.ldap_check_group_membership = false
36
36
  # config.ldap_check_attributes = false
37
+ # config.ldap_use_admin_to_bind = false
38
+
37
39
  eof
38
40
  end
39
41
 
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require 'devise_ldap_authenticatable'
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class DeviseLdapAuthenticatableTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end