devise_ldap_authenticatable 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +20 -10
- data/VERSION +1 -1
- data/devise_ldap_authenticatable.gemspec +2 -2
- data/lib/devise_ldap_authenticatable.rb +3 -0
- data/lib/devise_ldap_authenticatable/ldap_adapter.rb +7 -3
- data/lib/devise_ldap_authenticatable/version.rb +1 -1
- data/lib/generators/devise_ldap_authenticatable/install_generator.rb +12 -2
- data/test/ldap/base.ldif +17 -0
- data/test/ldap/clear.ldif +6 -0
- data/test/rails_app/Gemfile.lock +1 -1
- data/test/rails_app/test/factories/users.rb +5 -0
- data/test/rails_app/test/test_helper.rb +1 -0
- data/test/rails_app/test/unit/user_test.rb +25 -12
- metadata +4 -4
data/README.md
CHANGED
@@ -32,7 +32,7 @@ This will *only* work for Rails 3 applications.
|
|
32
32
|
In the Gemfile for your application:
|
33
33
|
|
34
34
|
gem "devise", "1.1.1"
|
35
|
-
gem "devise_ldap_authenticatable", "0.4.
|
35
|
+
gem "devise_ldap_authenticatable", "0.4.4"
|
36
36
|
|
37
37
|
To get the latest version, pull directly from github instead of the gem:
|
38
38
|
|
@@ -44,17 +44,18 @@ Setup
|
|
44
44
|
|
45
45
|
Run the rails generator
|
46
46
|
|
47
|
-
rails generate devise_ldap_authenticatable:install
|
47
|
+
rails generate devise_ldap_authenticatable:install [options]
|
48
48
|
|
49
49
|
This will install the sample.yml, update the devise.rb initializer, and update your user model. There are some options you can pass to it:
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
Options:
|
52
|
+
[--user-model=USER_MODEL] # Model to update
|
53
|
+
# Default: user
|
54
|
+
[--update-model] # Update model to change from database_authenticatable to ldap_authenticatable
|
55
|
+
# Default: true
|
56
|
+
[--add-rescue] # Update Application Controller with resuce_from for DeviseLdapAuthenticatable::LdapException
|
57
|
+
# Default: true
|
58
|
+
[--advanced] # Add advanced config options to the devise initializer
|
58
59
|
|
59
60
|
|
60
61
|
Usage
|
@@ -96,6 +97,15 @@ In initializer `config/initializers/devise.rb` :
|
|
96
97
|
* ldap\_use\_admin\_to\_bind _(default: false)_
|
97
98
|
* When set to true, the admin user will be used to bind to the LDAP server during authentication.
|
98
99
|
|
100
|
+
|
101
|
+
Advanced Configuration
|
102
|
+
----------------------
|
103
|
+
|
104
|
+
These parameters will be added to `config/initializers/devise.rb` when you pass the `--advanced` switch to the generator:
|
105
|
+
|
106
|
+
* ldap\_auth\_username\_builder _(default: `Proc.new() {|attribute, login, ldap| "#{attribute}=#{login},#{ldap.base}" }`)_
|
107
|
+
* You can pass a proc to the username option to explicitly specify the format that you search for a users' DN on your LDAP server.
|
108
|
+
|
99
109
|
Testing
|
100
110
|
-------
|
101
111
|
|
@@ -139,7 +149,7 @@ This will allow requests to go to the test LDAP server without being signed by a
|
|
139
149
|
References
|
140
150
|
----------
|
141
151
|
|
142
|
-
* [
|
152
|
+
* [OpenLDAP](http://www.openldap.org/)
|
143
153
|
* [Devise](http://github.com/plataformatec/devise)
|
144
154
|
* [Warden](http://github.com/hassox/warden)
|
145
155
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{devise_ldap_authenticatable}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Curtis Schiewek", "Daniel McNevin"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-14}
|
13
13
|
s.description = %q{LDAP authentication module for Devise}
|
14
14
|
s.email = %q{curtis.schiewek@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,6 +31,9 @@ module Devise
|
|
31
31
|
|
32
32
|
mattr_accessor :ldap_use_admin_to_bind
|
33
33
|
@@ldap_use_admin_to_bind = false
|
34
|
+
|
35
|
+
mattr_accessor :ldap_auth_username_builder
|
36
|
+
@@ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "#{attribute}=#{login},#{ldap.base}" }
|
34
37
|
end
|
35
38
|
|
36
39
|
# Add ldap_authenticatable strategy to defaults.
|
@@ -5,8 +5,11 @@ module Devise
|
|
5
5
|
module LdapAdapter
|
6
6
|
|
7
7
|
def self.valid_credentials?(login, password_plaintext)
|
8
|
-
options = {:login => login,
|
9
|
-
|
8
|
+
options = {:login => login,
|
9
|
+
:password => password_plaintext,
|
10
|
+
:ldap_auth_username_builder => ::Devise.ldap_auth_username_builder,
|
11
|
+
:admin => ::Devise.ldap_use_admin_to_bind}
|
12
|
+
|
10
13
|
resource = LdapConnect.new(options)
|
11
14
|
resource.authorized?
|
12
15
|
end
|
@@ -35,6 +38,7 @@ module Devise
|
|
35
38
|
@ldap.port = ldap_config["port"]
|
36
39
|
@ldap.base = ldap_config["base"]
|
37
40
|
@attribute = ldap_config["attribute"]
|
41
|
+
@ldap_auth_username_builder = params[:ldap_auth_username_builder]
|
38
42
|
|
39
43
|
@group_base = ldap_config["group_base"]
|
40
44
|
@required_groups = ldap_config["required_groups"]
|
@@ -53,7 +57,7 @@ module Devise
|
|
53
57
|
ldap_entry = nil
|
54
58
|
@ldap.search(:filter => filter) {|entry| ldap_entry = entry}
|
55
59
|
if ldap_entry.nil?
|
56
|
-
|
60
|
+
@ldap_auth_username_builder.call(@attribute,@login,@ldap)
|
57
61
|
else
|
58
62
|
ldap_entry.dn
|
59
63
|
end
|
@@ -5,6 +5,7 @@ module DeviseLdapAuthenticatable
|
|
5
5
|
class_option :user_model, :type => :string, :default => "user", :desc => "Model to update"
|
6
6
|
class_option :update_model, :type => :boolean, :default => true, :desc => "Update model to change from database_authenticatable to ldap_authenticatable"
|
7
7
|
class_option :add_rescue, :type => :boolean, :default => true, :desc => "Update Application Controller with resuce_from for DeviseLdapAuthenticatable::LdapException"
|
8
|
+
class_option :advanced, :type => :boolean, :desc => "Add advanced config options to the devise initializer"
|
8
9
|
|
9
10
|
|
10
11
|
def create_ldap_config
|
@@ -26,7 +27,7 @@ module DeviseLdapAuthenticatable
|
|
26
27
|
private
|
27
28
|
|
28
29
|
def default_devise_settings
|
29
|
-
<<-eof
|
30
|
+
settings = <<-eof
|
30
31
|
# ==> LDAP Configuration
|
31
32
|
# config.ldap_logger = true
|
32
33
|
# config.ldap_create_user = false
|
@@ -37,6 +38,15 @@ module DeviseLdapAuthenticatable
|
|
37
38
|
# config.ldap_use_admin_to_bind = false
|
38
39
|
|
39
40
|
eof
|
41
|
+
if options.advanced?
|
42
|
+
settings << <<-eof
|
43
|
+
# ==> Advanced LDAP Configuration
|
44
|
+
# config.ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "\#{attribute}=\#{login},\#{ldap.base}" }
|
45
|
+
|
46
|
+
eof
|
47
|
+
end
|
48
|
+
|
49
|
+
settings
|
40
50
|
end
|
41
51
|
|
42
52
|
def rescue_from_exception
|
@@ -48,4 +58,4 @@ module DeviseLdapAuthenticatable
|
|
48
58
|
end
|
49
59
|
|
50
60
|
end
|
51
|
-
end
|
61
|
+
end
|
data/test/ldap/base.ldif
CHANGED
@@ -10,6 +10,10 @@ dn: ou=people,dc=test,dc=com
|
|
10
10
|
objectClass: organizationalUnit
|
11
11
|
ou: people
|
12
12
|
|
13
|
+
dn: ou=others,dc=test,dc=com
|
14
|
+
objectClass: organizationalUnit
|
15
|
+
ou: others
|
16
|
+
|
13
17
|
dn: ou=groups,dc=test,dc=com
|
14
18
|
objectClass: organizationalUnit
|
15
19
|
ou: groups
|
@@ -26,6 +30,19 @@ authorizationRole: blogUser
|
|
26
30
|
userPassword:: e1NTSEF9ZXRYaE9NcjRjOGFiTjlqYUxyczZKSll5MFlaZUF1NURCVWhhY0E9PQ=
|
27
31
|
=
|
28
32
|
|
33
|
+
# other.user@test.com
|
34
|
+
dn: cn=other.user@test.com,ou=others,dc=test,dc=com
|
35
|
+
objectClass: inetOrgPerson
|
36
|
+
objectClass: authorizations
|
37
|
+
objectClass: organizationalPerson
|
38
|
+
objectClass: person
|
39
|
+
objectClass: top
|
40
|
+
sn: Other
|
41
|
+
uid: other_user
|
42
|
+
cn: other.user@test.com
|
43
|
+
authorizationRole: blogUser
|
44
|
+
userPassword:: e1NIQX1IQXdtdk13RGF1ZUpyZDhwakxXMzZ6Yi9jTUU9
|
45
|
+
|
29
46
|
# example.admin@test.com, people, test.com
|
30
47
|
dn: cn=example.admin@test.com,ou=people,dc=test,dc=com
|
31
48
|
objectClass: inetOrgPerson
|
data/test/ldap/clear.ldif
CHANGED
@@ -10,11 +10,17 @@ changetype: delete
|
|
10
10
|
dn: cn=example.user@test.com,ou=people,dc=test,dc=com
|
11
11
|
changetype: delete
|
12
12
|
|
13
|
+
dn: cn=other.user@test.com,ou=others,dc=test,dc=com
|
14
|
+
changetype: delete
|
15
|
+
|
13
16
|
dn: ou=groups,dc=test,dc=com
|
14
17
|
changetype: delete
|
15
18
|
|
16
19
|
dn: ou=people,dc=test,dc=com
|
17
20
|
changetype: delete
|
18
21
|
|
22
|
+
dn: ou=others,dc=test,dc=com
|
23
|
+
changetype: delete
|
24
|
+
|
19
25
|
dn: dc=test,dc=com
|
20
26
|
changetype: delete
|
data/test/rails_app/Gemfile.lock
CHANGED
@@ -21,6 +21,7 @@ class ActiveSupport::TestCase
|
|
21
21
|
::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap.yml"
|
22
22
|
::Devise.ldap_check_group_membership = false
|
23
23
|
::Devise.ldap_check_attributes = false
|
24
|
+
::Devise.ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "#{attribute}=#{login},#{ldap.base}" }
|
24
25
|
::Devise.authentication_keys = [:email]
|
25
26
|
end
|
26
27
|
|
@@ -20,7 +20,7 @@ class UserTest < ActiveSupport::TestCase
|
|
20
20
|
setup do
|
21
21
|
@user = Factory(:user)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
should "check for password validation" do
|
25
25
|
assert_equal(@user.email, "example.user@test.com")
|
26
26
|
should_be_validated @user, "secret"
|
@@ -33,7 +33,7 @@ class UserTest < ActiveSupport::TestCase
|
|
33
33
|
setup do
|
34
34
|
@user = Factory(:user)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
should "change password" do
|
38
38
|
should_be_validated @user, "secret"
|
39
39
|
@user.reset_password!("changed","changed")
|
@@ -70,7 +70,7 @@ class UserTest < ActiveSupport::TestCase
|
|
70
70
|
assert_equal(User.all.size, 1)
|
71
71
|
assert_contains(User.all.collect(&:email), "example.user@test.com", "user not in database")
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
should "not create a user in the database if the password is wrong_secret" do
|
75
75
|
@user = User.authenticate_with_ldap(:email => "example.user", :password => "wrong_secret")
|
76
76
|
assert(User.all.blank?, "There's users in the database")
|
@@ -91,7 +91,7 @@ class UserTest < ActiveSupport::TestCase
|
|
91
91
|
::Devise.authentication_keys = [:email]
|
92
92
|
::Devise.ldap_check_group_membership = true
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
should "admin should be allowed in" do
|
96
96
|
should_be_validated @admin, "admin_secret"
|
97
97
|
end
|
@@ -111,7 +111,7 @@ class UserTest < ActiveSupport::TestCase
|
|
111
111
|
@user = Factory(:user)
|
112
112
|
::Devise.ldap_check_attributes = true
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
should "admin should be allowed in" do
|
116
116
|
should_be_validated @admin, "admin_secret"
|
117
117
|
end
|
@@ -127,7 +127,7 @@ class UserTest < ActiveSupport::TestCase
|
|
127
127
|
@user = Factory(:user)
|
128
128
|
::Devise.ldap_use_admin_to_bind = true
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
should "description" do
|
132
132
|
should_be_validated @admin, "admin_secret"
|
133
133
|
end
|
@@ -142,13 +142,13 @@ class UserTest < ActiveSupport::TestCase
|
|
142
142
|
::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_uid.yml"
|
143
143
|
::Devise.authentication_keys = [:uid]
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
context "description" do
|
147
147
|
setup do
|
148
148
|
@admin = Factory(:admin)
|
149
149
|
@user = Factory(:user, :uid => "example_user")
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
should "be able to authenticate using uid" do
|
153
153
|
should_be_validated @user, "secret"
|
154
154
|
should_not_be_validated @admin, "admin_secret"
|
@@ -159,7 +159,7 @@ class UserTest < ActiveSupport::TestCase
|
|
159
159
|
setup do
|
160
160
|
::Devise.ldap_create_user = true
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
should "create a user in the database" do
|
164
164
|
@user = User.authenticate_with_ldap(:uid => "example_user", :password => "secret")
|
165
165
|
assert_equal(User.all.size, 1)
|
@@ -174,13 +174,13 @@ class UserTest < ActiveSupport::TestCase
|
|
174
174
|
reset_ldap_server!
|
175
175
|
::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_erb.yml"
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
context "authenticate" do
|
179
179
|
setup do
|
180
180
|
@admin = Factory(:admin)
|
181
181
|
@user = Factory(:user)
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
should "be able to authenticate" do
|
185
185
|
should_be_validated @user, "secret"
|
186
186
|
should_be_validated @admin, "admin_secret"
|
@@ -188,6 +188,19 @@ class UserTest < ActiveSupport::TestCase
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
|
191
|
+
context "use username builder" do
|
192
|
+
setup do
|
193
|
+
default_devise_settings!
|
194
|
+
reset_ldap_server!
|
195
|
+
::Devise.ldap_auth_username_builder = Proc.new() do |attribute, login, ldap|
|
196
|
+
"#{attribute}=#{login},ou=others,dc=test,dc=com"
|
197
|
+
end
|
198
|
+
@other = Factory(:other)
|
199
|
+
end
|
200
|
+
|
201
|
+
should "be able to authenticate" do
|
202
|
+
should_be_validated @other, "other_secret"
|
203
|
+
end
|
204
|
+
end
|
192
205
|
|
193
206
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_ldap_authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Curtis Schiewek
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-08-
|
19
|
+
date: 2010-08-14 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|