Skip to content

Commit 7f4cb4b

Browse files
committed
added ability to specify the attribute name on required groups by passing an array
1 parent 4e9615b commit 7f4cb4b

File tree

12 files changed

+50
-20
lines changed

12 files changed

+50
-20
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This will *only* work for Rails 3 applications.
3232
In the Gemfile for your application:
3333

3434
gem "devise", "1.1.2"
35-
gem "devise_ldap_authenticatable", "0.4.5"
35+
gem "devise_ldap_authenticatable"
3636

3737
To get the latest version, pull directly from github instead of the gem:
3838

@@ -96,7 +96,6 @@ In initializer `config/initializers/devise.rb` :
9696
* ldap\_check\_group_membership _(default: false)_
9797
* 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.
9898

99-
10099
* ldap\_check\_attributes _(default: false)_
101100
* 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.
102101

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.5
1+
0.4.6

devise_ldap_authenticatable.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
Gem::Specification.new do |s|
77
s.name = %q{devise_ldap_authenticatable}
8-
s.version = "0.4.5"
8+
s.version = "0.4.6"
99

1010
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1111
s.authors = ["Curtis Schiewek", "Daniel McNevin"]
12-
s.date = %q{2010-08-30}
12+
s.date = %q{2010-09-23}
1313
s.description = %q{LDAP authentication module for Devise}
1414
s.email = %q{[email protected]}
1515
s.extra_rdoc_files = [

lib/devise_ldap_authenticatable/ldap_adapter.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,15 @@ def in_required_groups?
9090
admin_ldap = LdapConnect.admin
9191

9292
for group in @required_groups
93-
admin_ldap.search(:base => group, :scope => Net::LDAP::SearchScope_BaseObject) do |entry|
94-
unless entry.uniqueMember.include? dn
95-
DeviseLdapAuthenticatable::Logger.send("User #{dn} is not in group: #{group}")
93+
if group.is_a?(Array)
94+
group_attribute, group_name = group
95+
else
96+
group_attribute = "uniqueMember"
97+
group_name = group
98+
end
99+
admin_ldap.search(:base => group_name, :scope => Net::LDAP::SearchScope_BaseObject) do |entry|
100+
unless entry[group_attribute].include? dn
101+
DeviseLdapAuthenticatable::Logger.send("User #{dn} is not in group: #{group_name }")
96102
return false
97103
end
98104
end
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module DeviseLdapAuthenticatable
2-
VERSION = "0.4.5"
2+
VERSION = "0.4.6"
33
end
44

lib/generators/devise_ldap_authenticatable/templates/ldap.yml

+3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ authorizations: &AUTHORIZATIONS
77
## Requires config.ldap_check_group_membership in devise.rb be true
88
# Can have multiple values, must match all to be authorized
99
required_groups:
10+
# If only a group name is given, membership will be checked against "uniqueMember"
1011
- cn=admins,ou=groups,dc=test,dc=com
1112
- cn=users,ou=groups,dc=test,dc=com
13+
# If an array is given, the first element will be the attribute to check against, the second the group name
14+
- ["moreMembers", "cn=users,ou=groups,dc=test,dc=com"]
1215
## Requires config.ldap_check_attributes in devise.rb to be true
1316
## Can have multiple attributes and values, must match all to be authorized
1417
require_attribute:

test/ldap/base.ldif

+2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ userPassword:: e1NIQX0wcUNXaERISGFwWmc3ekJxZWRRanBzNW1EUDA9
5858

5959
# users, groups, test.com
6060
dn: cn=users,ou=groups,dc=test,dc=com
61+
objectClass: authorizations
6162
objectClass: groupOfUniqueNames
6263
objectClass: top
6364
uniqueMember: [email protected],ou=people,dc=test,dc=com
65+
authorizationRole: [email protected],ou=people,dc=test,dc=com
6466
cn: users
6567

6668
# users, groups, test.com

test/rails_app/Gemfile.lock

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PATH
22
remote: /Users/dpmcnevin/Rails/devise_ldap_authenticatable
33
specs:
4-
devise_ldap_authenticatable (0.4.4)
5-
devise (> 1.0.4)
6-
net-ldap (>= 0.1.1)
4+
devise_ldap_authenticatable (0.4.5)
5+
devise (= 1.1.2)
6+
net-ldap (= 0.1.1)
77

88
GEM
99
remote: http://rubygems.org/
@@ -52,6 +52,7 @@ GEM
5252
rack (>= 1.0.0)
5353
rack-test (>= 0.5.4)
5454
selenium-webdriver (>= 0.0.3)
55+
columnize (0.3.1)
5556
configuration (1.1.0)
5657
cucumber (0.8.5)
5758
builder (~> 2.1.2)
@@ -82,6 +83,7 @@ GEM
8283
launchy (0.3.7)
8384
configuration (>= 0.0.5)
8485
rake (>= 0.8.1)
86+
linecache (0.43)
8587
mail (2.2.5)
8688
activesupport (>= 2.3.6)
8789
mime-types
@@ -111,6 +113,12 @@ GEM
111113
rake (>= 0.8.4)
112114
thor (~> 0.14.0)
113115
rake (0.8.7)
116+
redgreen (1.2.2)
117+
ruby-debug (0.10.3)
118+
columnize (>= 0.1)
119+
ruby-debug-base (~> 0.10.3.0)
120+
ruby-debug-base (0.10.3)
121+
linecache (>= 0.3)
114122
rubyzip (0.9.4)
115123
selenium-webdriver (0.0.28)
116124
ffi (>= 0.6.1)
@@ -143,5 +151,7 @@ DEPENDENCIES
143151
launchy
144152
mocha
145153
rails (= 3.0.0)
154+
redgreen
155+
ruby-debug
146156
shoulda
147157
sqlite3-ruby

test/rails_app/config/ldap.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ authorizations: &AUTHORIZATIONS
33
group_base: ou=groups,dc=test,dc=com
44
required_groups:
55
- cn=admins,ou=groups,dc=test,dc=com
6+
- ["authorizationRole", "cn=users,ou=groups,dc=test,dc=com"]
67
require_attribute:
78
objectClass: inetOrgPerson
89
authorizationRole: blogAdmin

test/rails_app/test/test_helper.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44

55
class ActiveSupport::TestCase
66

7+
def ldap_connect_string
8+
if ENV["LDAP_SSL"]
9+
"-x -H ldaps://localhost:3389 -D 'cn=admin,dc=test,dc=com' -w secret"
10+
else
11+
"-x -h localhost -p 3389 -D 'cn=admin,dc=test,dc=com' -w secret"
12+
end
13+
end
14+
715
def reset_ldap_server!
816
if ENV["LDAP_SSL"]
9-
`ldapmodify -x -H ldaps://localhost:3389 -D "cn=admin,dc=test,dc=com" -w secret -f ../ldap/clear.ldif`
10-
`ldapadd -x -H ldaps://localhost:3389 -D "cn=admin,dc=test,dc=com" -w secret -f ../ldap/base.ldif`
17+
`ldapmodify #{ldap_connect_string} -f ../ldap/clear.ldif`
18+
`ldapadd #{ldap_connect_string} -f ../ldap/base.ldif`
1119
else
12-
`ldapmodify -x -h localhost -p 3389 -D "cn=admin,dc=test,dc=com" -w secret -f ../ldap/clear.ldif`
13-
`ldapadd -x -h localhost -p 3389 -D "cn=admin,dc=test,dc=com" -w secret -f ../ldap/base.ldif`
20+
`ldapmodify #{ldap_connect_string} -f ../ldap/clear.ldif`
21+
`ldapadd #{ldap_connect_string} -f ../ldap/base.ldif`
1422
end
1523
end
1624

test/rails_app/test/unit/post_test.rb

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
require 'test_helper'
22

33
class PostTest < ActiveSupport::TestCase
4-
# Replace this with your real tests.
5-
test "the truth" do
6-
assert true
7-
end
84
end

test/rails_app/test/unit/user_test.rb

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def should_not_be_validated(user, password, message = "Password is not properly
103103
should "user should not be allowed in" do
104104
should_not_be_validated @user, "secret"
105105
end
106+
107+
should "not be validated if group with different attribute is removed" do
108+
`ldapmodify #{ldap_connect_string} -f ../ldap/delete_authorization_role.ldif`
109+
should_not_be_validated @admin, "admin_secret"
110+
end
106111
end
107112

108113
context "use role attribute for authorization" do

0 commit comments

Comments
 (0)