active_directory_login 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47fbbe0fe7ddb8fd3ec3ba897b83d98ba377e915
|
4
|
+
data.tar.gz: bfa62e77801d567ca7d95fff669f792c8f84b443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 613463170d1b6f58ce61c69171f277901a0f6c5e93641db2a98ecc6c22ac3c26123ad5f5bf03dab4ae28a689c29eddd84ff11d7a0290dd336df220ff1d3353ad
|
7
|
+
data.tar.gz: 70010927678048f1713484efade2d723f113bab7d2766e5cbabc34f09c543a27ebc191e9ab2a9b1cbf2bbb6aa77cfb64d9b224f7a2641684a0b007ede983cefb
|
@@ -28,7 +28,7 @@ module ActiveDirectoryLogin
|
|
28
28
|
|
29
29
|
def_delegators :default_client, :validate!, :sync_groups, :benched
|
30
30
|
|
31
|
-
def_delegators :default_client, :with_user, :lock_user, :authenticate_user, :has_member_access?, :create_or_update_user
|
31
|
+
def_delegators :default_client, :find_user, :with_user, :lock_user, :authenticate_user, :has_member_access?, :create_or_update_user
|
32
32
|
|
33
33
|
#logger modelled on https://github.com/pusher/pusher-gem/blob/master/lib/pusher.rb
|
34
34
|
attr_writer :logger
|
@@ -174,18 +174,16 @@ module ActiveDirectoryLogin
|
|
174
174
|
allowed = User.where(email: staff_member_emails, staff: false)
|
175
175
|
staff_allowed_emails = allowed.collect(&:email)
|
176
176
|
allowed.update_all(staff: true)
|
177
|
-
pending = staff_member_emails - staff_allowed_emails
|
178
177
|
|
179
178
|
disallowed = User.where.not(email: staff_member_emails).where(staff: true)
|
180
179
|
staff_disallowed_emails = disallowed.collect(&:email)
|
181
180
|
disallowed.update_all(staff: false)
|
182
|
-
pending = pending - staff_disallowed_emails
|
183
181
|
|
184
182
|
staff_unchanged = User.where(email: staff_member_emails, staff: true)
|
185
183
|
staff_unchanged_emails = staff_unchanged.collect(&:email)
|
186
|
-
pending = pending - staff_unchanged_emails
|
187
184
|
|
188
185
|
# create any new staff
|
186
|
+
pending = Array(staff_member_emails - staff_allowed_emails - staff_disallowed_emails - staff_unchanged_emails)
|
189
187
|
pending.each do |pending_email|
|
190
188
|
with_user(pending_email, SecureRandom.hex){ create_or_update_user }
|
191
189
|
end
|
@@ -200,19 +198,17 @@ module ActiveDirectoryLogin
|
|
200
198
|
allowed = User.where(email: superuser_member_emails, superuser: false)
|
201
199
|
superuser_allowed_emails = allowed.collect(&:email)
|
202
200
|
allowed.update_all(superuser: true)
|
203
|
-
pending = superuser_member_emails - superuser_allowed_emails
|
204
201
|
|
205
202
|
disallowed = User.where.not(email: superuser_member_emails).where(superuser: true)
|
206
203
|
superuser_disallowed_emails = disallowed.collect(&:email)
|
207
204
|
disallowed.update_all(superuser: false)
|
208
|
-
pending = pending - superuser_disallowed_emails
|
209
205
|
|
210
206
|
superuser_unchanged = User.where(email: superuser_member_emails, superuser: true)
|
211
207
|
superuser_unchanged_emails = superuser_unchanged.collect(&:email)
|
212
|
-
|
213
|
-
|
208
|
+
|
214
209
|
# create any new superuser
|
215
|
-
pending
|
210
|
+
pending = Array(superuser_member_emails - superuser_allowed_emails - superuser_disallowed_emails - superuser_unchanged_emails)
|
211
|
+
pending.each do |pending_email|
|
216
212
|
with_user(pending_email, SecureRandom.hex){ create_or_update_user }
|
217
213
|
end
|
218
214
|
superuser_created_emails = pending
|
@@ -222,7 +218,6 @@ module ActiveDirectoryLogin
|
|
222
218
|
|
223
219
|
## update users
|
224
220
|
user_group = find_group(user_dn)
|
225
|
-
# member_cns = user_group.entry[:member]
|
226
221
|
|
227
222
|
member_emails = user_group.member.collect(&:mail).map(&:downcase)
|
228
223
|
member_emails = member_emails - superuser_member_emails - staff_member_emails
|
@@ -230,24 +225,21 @@ module ActiveDirectoryLogin
|
|
230
225
|
allowed = User.where(email: member_emails, staff: false, superuser: false).where.not(locked_at: nil)
|
231
226
|
user_allowed_emails = allowed.collect(&:email)
|
232
227
|
allowed.update_all(locked_at: nil)
|
233
|
-
pending = member_emails - user_allowed_emails
|
234
228
|
|
235
|
-
disallowed = User.where.not(email: member_emails
|
229
|
+
disallowed = User.where.not(email: member_emails).where(staff: false, superuser: false)
|
236
230
|
user_disallowed_emails = disallowed.collect(&:email)
|
237
231
|
disallowed.each {|u| u.lock_access! }
|
238
232
|
|
239
233
|
user_unchanged = User.where(email: member_emails, staff: false, superuser: false)
|
240
234
|
user_unchanged_emails = user_unchanged.collect(&:email)
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
#create any new superuser
|
235
|
+
|
236
|
+
#create any new user
|
237
|
+
pending = Array(pending - user_allowed_emails - user_unchanged_emails)
|
246
238
|
pending.each do |pending_email|
|
247
239
|
with_user(pending_email, SecureRandom.hex){ create_or_update_user }
|
248
240
|
end
|
249
241
|
user_created_emails = pending
|
250
|
-
|
242
|
+
|
251
243
|
#report on changes
|
252
244
|
ActiveDirectoryLogin.logger.info "Staff allowed: #{staff_allowed_emails}"
|
253
245
|
ActiveDirectoryLogin.logger.info "Staff disallowed: #{staff_disallowed_emails}"
|
@@ -263,13 +255,9 @@ module ActiveDirectoryLogin
|
|
263
255
|
ActiveDirectoryLogin.logger.info "User disallowed: #{user_disallowed_emails}"
|
264
256
|
ActiveDirectoryLogin.logger.info "User created: #{user_created_emails}"
|
265
257
|
ActiveDirectoryLogin.logger.info "User unchanged: #{user_unchanged_emails}"
|
266
|
-
|
267
|
-
|
268
|
-
|
269
258
|
end
|
270
259
|
|
271
|
-
|
272
|
-
|
260
|
+
#report new numbers of users
|
273
261
|
ActiveDirectoryLogin.logger.info "Staff: #{User.staff.count}"
|
274
262
|
ActiveDirectoryLogin.logger.info "Superusers: #{User.superusers.count}"
|
275
263
|
ActiveDirectoryLogin.logger.info "Users: #{User.normals.count}"
|
@@ -8,28 +8,27 @@ module Devise
|
|
8
8
|
def authenticate!
|
9
9
|
#FIXME enterprise mode was here
|
10
10
|
if params[:user]
|
11
|
-
|
12
11
|
username_or_email = params[:user][:login]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
if ActiveDirectoryLogin.find_user(username_or_email).nil?
|
13
|
+
fail(:invalid)
|
14
|
+
else
|
15
|
+
ActiveDirectoryLogin.with_user(username_or_email, params[:user][:password]) do
|
16
|
+
|
17
|
+
if ActiveDirectoryLogin.authenticate_user
|
18
|
+
if ActiveDirectoryLogin.has_member_access?
|
19
|
+
user = ActiveDirectoryLogin.create_or_update_user
|
20
|
+
success!(user)
|
21
|
+
else
|
22
|
+
ActiveDirectoryLogin.lock_user
|
23
|
+
fail(:locked)
|
24
|
+
end
|
20
25
|
else
|
21
|
-
|
22
|
-
fail(:locked)
|
26
|
+
fail(:invalid)
|
23
27
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
28
|
+
end #with_user
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end # authenticate
|
32
|
+
end # class
|
33
|
+
end # module
|
34
|
+
end # module
|
@@ -1,94 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'active_directory_login'
|
3
3
|
require 'active_directory_login/group_resource'
|
4
|
-
|
4
|
+
|
5
5
|
require 'devise/strategies/authenticatable'
|
6
6
|
require 'devise'
|
7
7
|
describe ActiveDirectoryLogin do
|
8
8
|
|
9
9
|
before do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@user_resource = ActiveDirectoryLogin::UserResource
|
20
|
-
@group_resource = ActiveDirectoryLogin::GroupResource
|
21
|
-
|
10
|
+
ActiveDirectoryLogin.auth_method = 'simple'
|
11
|
+
ActiveDirectoryLogin.username = 'svcdgauth'
|
12
|
+
ActiveDirectoryLogin.password = 'Friday10'
|
13
|
+
ActiveDirectoryLogin.host = 'dnzdc3.datacom.co.nz'
|
14
|
+
ActiveDirectoryLogin.port = '389'
|
15
|
+
ActiveDirectoryLogin.base = 'DC=datacom,DC=co,DC=nz'
|
16
|
+
ActiveDirectoryLogin.staff_dn = 'CN=DocGenie-Staff,OU=Datacom Systems Wellington,OU=Datacom Systems,OU=Groups - Universal Distribution Lists,DC=datacom,DC=co,DC=nz'
|
17
|
+
ActiveDirectoryLogin.superuser_dn = 'CN=DocGenie-SystemOwners,OU=Datacom Systems Wellington,OU=Datacom Systems,OU=Groups - Universal Distribution Lists,DC=datacom,DC=co,DC=nz'
|
18
|
+
ActiveDirectoryLogin.user_dn = 'CN=DocGenie-Users,OU=Datacom Systems Wellington,OU=Datacom Systems,OU=Groups - Universal Distribution Lists,DC=datacom,DC=co,DC=nz'
|
22
19
|
end
|
23
20
|
|
24
|
-
let(:staff_group) {"CN=DocGenie-Staff,OU=Datacom Systems Wellington,OU=Datacom Systems,OU=Groups - Universal Distribution Lists,DC=datacom,DC=co,DC=nz"}
|
25
|
-
|
26
21
|
describe '.user' do
|
27
22
|
|
28
23
|
it 'requires a value' do
|
29
|
-
expect {
|
24
|
+
expect { ActiveDirectoryLogin.find_user nil
|
30
25
|
}.to raise_error ActiveDirectoryLogin::NoSearchKey
|
31
26
|
end
|
32
27
|
|
33
28
|
it 'requires a value' do
|
34
|
-
expect {
|
29
|
+
expect { ActiveDirectoryLogin.find_user ''
|
35
30
|
}.to raise_error ActiveDirectoryLogin::NoSearchKey
|
36
31
|
end
|
37
32
|
|
38
33
|
end
|
39
34
|
|
40
|
-
it 'finds
|
35
|
+
it 'finds Brad by username' do
|
41
36
|
login = 'bradmu'
|
42
|
-
user =
|
37
|
+
user = ActiveDirectoryLogin.find_user login
|
43
38
|
user[:cn].should == "Brad Murray [DATACOM]"
|
44
39
|
end
|
45
40
|
|
46
|
-
it 'finds
|
41
|
+
it 'finds Brad by email' do
|
47
42
|
login = 'brad.murray@datacom.co.nz'
|
48
|
-
user =
|
43
|
+
user = ActiveDirectoryLogin.find_user login
|
49
44
|
user[:cn].should == "Brad Murray [DATACOM]"
|
50
45
|
end
|
51
46
|
|
52
|
-
|
53
|
-
it 'finds me by email' do
|
54
|
-
login = 'brad.murray@datacom.co.nz'
|
55
|
-
user = @user_resource.find login
|
56
|
-
user[:cn].should == "Brad Murray [DATACOM]"
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'finds DocGenie staff group' do
|
60
|
-
group = @group_resource.find staff_group
|
61
|
-
group.name.should == "DocGenie-Staff"
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'can get members of DocGenie staff group' do
|
65
|
-
group = @group_resource.find staff_group
|
66
|
-
group.member.count.should == 5
|
67
|
-
@group_resource.member_names(group).should == ["Patrick Copeland [DATACOM]",
|
68
|
-
"Owen Bannister [DATACOM]",
|
69
|
-
"Tatyana Kudiyarova [DATACOM]",
|
70
|
-
"Brad Murray [DATACOM]",
|
71
|
-
"Blair Nilsson [DATACOM]"]
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'can find user groups' do
|
75
|
-
login = 'owen.bannister@datacom.co.nz'
|
76
|
-
user = @user_resource.find login
|
77
|
-
groups = @user_resource.groups user
|
78
|
-
groups.count.should > 0
|
79
|
-
groups.include?(staff_group).should == true
|
80
|
-
end
|
81
|
-
|
82
|
-
# let(:User) { stub 'User'}
|
83
|
-
it 'can validate me by my groups' do
|
84
|
-
login = 'owen.bannister@datacom.co.nz'
|
85
|
-
user = @user_resource.find login
|
86
|
-
|
87
|
-
permission = @group_resource.has_group_access? @user_resource.groups(user)
|
88
|
-
permission.should == false
|
89
|
-
|
90
|
-
ENV['DG_STAFF_DN'] = staff_group
|
91
|
-
permission = @group_resource.has_group_access? @user_resource.groups(user)
|
92
|
-
permission.should == true
|
93
|
-
end
|
94
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_directory_login
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Murray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|