devise-radius-authenticatable 0.0.1 → 0.0.2
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 +10 -11
- data/lib/devise/models/radius_authenticatable.rb +5 -1
- data/lib/devise/radius_authenticatable.rb +3 -0
- data/lib/devise/radius_authenticatable/version.rb +1 -1
- data/lib/generators/devise_radius_authenticatable/install_generator.rb +9 -0
- data/spec/devise/models/radius_authenticatable_spec.rb +16 -6
- data/spec/generators/install_generator_spec.rb +4 -1
- data/spec/rails_app/config/initializers/devise.rb +7 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -36,14 +36,15 @@ This will update the devise.rb initializer. The IP and SECRET parameters specify
|
|
36
36
|
|
37
37
|
Options:
|
38
38
|
|
39
|
-
[--uid-field=UID_FIELD]
|
40
|
-
|
41
|
-
[--port=PORT]
|
42
|
-
|
43
|
-
[--timeout=TIMEOUT]
|
44
|
-
|
45
|
-
[--retries=RETRIES]
|
46
|
-
|
39
|
+
[--uid-field=UID_FIELD] # What database column to use for the UID
|
40
|
+
# Default: uid
|
41
|
+
[--port=PORT] # The port to connect to the radius server on
|
42
|
+
# Default: 1812
|
43
|
+
[--timeout=TIMEOUT] # How long to wait for a response from the radius server
|
44
|
+
# Default: 60
|
45
|
+
[--retries=RETRIES] # How many times to retry a radius request
|
46
|
+
# Default: 0
|
47
|
+
[--dictionary-path=DICTIONARY_PATH] # The path to load radius dictionary files from
|
47
48
|
|
48
49
|
Documentation
|
49
50
|
-------------
|
@@ -78,6 +79,4 @@ References
|
|
78
79
|
* [Devise](http://github.com/plataformatec/devise)
|
79
80
|
* [Warden](http://github.com/hassox/warden)
|
80
81
|
|
81
|
-
Released under the MIT license
|
82
|
-
|
83
|
-
Copyright (c) 2012 Calvin Bascom
|
82
|
+
Copyright (c) 2012 Calvin Bascom Released under the MIT license
|
@@ -35,6 +35,7 @@ module Devise
|
|
35
35
|
# * +radius_uid_field+: The database column to store the UID in
|
36
36
|
# * +radius_uid_generator+: A proc that takes the username and server as parameters
|
37
37
|
# and returns a string representing the UID
|
38
|
+
# * +radius_dictionary_path+: The path containing the radius dictionary files to load
|
38
39
|
#
|
39
40
|
# == Callbacks
|
40
41
|
#
|
@@ -68,6 +69,9 @@ module Devise
|
|
68
69
|
:reply_timeout => self.class.radius_server_timeout,
|
69
70
|
:retries_number => self.class.radius_server_retries
|
70
71
|
}
|
72
|
+
if self.class.radius_dictionary_path
|
73
|
+
options[:dict] = Radiustar::Dictionary.new(self.class.radius_dictionary_path)
|
74
|
+
end
|
71
75
|
|
72
76
|
req = Radiustar::Request.new("#{server}:#{port}", options)
|
73
77
|
reply = req.authenticate(username, password, secret)
|
@@ -94,7 +98,7 @@ module Devise
|
|
94
98
|
Devise::Models.config(self, :radius_server, :radius_server_port,
|
95
99
|
:radius_server_secret, :radius_server_timeout,
|
96
100
|
:radius_server_retries, :radius_uid_field,
|
97
|
-
:radius_uid_generator)
|
101
|
+
:radius_uid_generator, :radius_dictionary_path)
|
98
102
|
|
99
103
|
# Invoked by the RadiusAuthenticatable stratgey to perform the authentication
|
100
104
|
# against the radius server. The username is extracted from the authentication
|
@@ -26,6 +26,9 @@ module Devise
|
|
26
26
|
# The procedure to use to build the unique identifier for the radius user
|
27
27
|
mattr_accessor :radius_uid_generator
|
28
28
|
@@radius_uid_generator = Proc.new { |username, server| "#{username}@#{server}" }
|
29
|
+
|
30
|
+
# The path to load radius dictionary files from
|
31
|
+
mattr_accessor :radius_dictionary_path
|
29
32
|
end
|
30
33
|
|
31
34
|
Devise.add_module(:radius_authenticatable, :route => :session, :strategy => true,
|
@@ -22,6 +22,8 @@ module DeviseRadiusAuthenticatable
|
|
22
22
|
:desc => 'How long to wait for a response from the radius server')
|
23
23
|
class_option(:retries, :default => 0,
|
24
24
|
:desc => 'How many times to retry a radius request')
|
25
|
+
class_option(:dictionary_path, :default => nil,
|
26
|
+
:desc => 'The path to load radius dictionary files from')
|
25
27
|
|
26
28
|
def install
|
27
29
|
inject_into_file("config/initializers/devise.rb", default_devise_settings,
|
@@ -72,6 +74,13 @@ module DeviseRadiusAuthenticatable
|
|
72
74
|
# config.radius_uid_generator = Proc.new do |username, server|
|
73
75
|
# "\#{username}@\#{server}"
|
74
76
|
# end
|
77
|
+
|
78
|
+
# There is a very basic radius dictionary provided by default. Most of the time
|
79
|
+
# this will not be sufficient, so this configuration option allows you to
|
80
|
+
# specify the path that contains all of the radius dictionary files that should
|
81
|
+
# be loaded.
|
82
|
+
#
|
83
|
+
# config.radius_dictionary_path = '#{options[:dictionary_path]}'
|
75
84
|
CONFIG
|
76
85
|
end
|
77
86
|
end
|
@@ -7,7 +7,8 @@ class Configurable < Admin
|
|
7
7
|
:radius_uid_field => :email,
|
8
8
|
:radius_uid_generator => Proc.new { |username, server|
|
9
9
|
"#{username}_#{server}"
|
10
|
-
}
|
10
|
+
},
|
11
|
+
:radius_dictionary_path => Rails.root.join('config/dictionaries'))
|
11
12
|
end
|
12
13
|
|
13
14
|
describe Devise::Models::RadiusAuthenticatable do
|
@@ -41,6 +42,10 @@ describe Devise::Models::RadiusAuthenticatable do
|
|
41
42
|
Configurable.radius_uid_generator.call('test', '1.2.3.4').should == 'test_1.2.3.4'
|
42
43
|
end
|
43
44
|
|
45
|
+
it "allows configuration of the radius dictionary path" do
|
46
|
+
Configurable.radius_dictionary_path.should == Rails.root.join('config/dictionaries')
|
47
|
+
end
|
48
|
+
|
44
49
|
it "extracts radius credentials based on the configured authentication keys" do
|
45
50
|
swap(Devise, :authentication_keys => [:username, :domain]) do
|
46
51
|
auth_hash = { :username => 'cbascom', :password => 'testing' }
|
@@ -110,14 +115,19 @@ describe Devise::Models::RadiusAuthenticatable do
|
|
110
115
|
|
111
116
|
it "passes the configured options when building the radius request" do
|
112
117
|
server_url = "#{Admin.radius_server}:#{Admin.radius_server_port}"
|
113
|
-
server_options = {
|
114
|
-
:reply_timeout => Admin.radius_server_timeout,
|
115
|
-
:retries_number => Admin.radius_server_retries
|
116
|
-
}
|
117
118
|
@admin.valid_radius_password?('testuser', 'password')
|
118
119
|
|
119
120
|
radius_server.url.should == server_url
|
120
|
-
radius_server.options.should ==
|
121
|
+
radius_server.options[:reply_timeout].should == Admin.radius_server_timeout
|
122
|
+
radius_server.options[:retries_number].should == Admin.radius_server_retries
|
123
|
+
radius_server.options[:dict].should be_a(Radiustar::Dictionary)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not add the :dict option if no dictionary path is configured" do
|
127
|
+
swap(Admin, :radius_dictionary_path => nil) do
|
128
|
+
@admin.valid_radius_password?('testuser', 'password')
|
129
|
+
radius_server.options.should_not have_key(:dict)
|
130
|
+
end
|
121
131
|
end
|
122
132
|
|
123
133
|
it "returns false when the password is incorrect" do
|
@@ -27,11 +27,13 @@ describe DeviseRadiusAuthenticatable::InstallGenerator do
|
|
27
27
|
it { should contain("config.radius_server_retries = 0") }
|
28
28
|
it { should contain("config.radius_uid_field = :uid") }
|
29
29
|
it { should contain("config.radius_uid_generator =") }
|
30
|
+
it { should contain("config.radius_dictionary_path =") }
|
30
31
|
end
|
31
32
|
|
32
33
|
context "with custom options" do
|
33
34
|
before { run_generator ['1.1.1.2', 'password', '--port=1813', '--timeout=120',
|
34
|
-
'--retries=3', '--uid_field=email'
|
35
|
+
'--retries=3', '--uid_field=email',
|
36
|
+
'--dictionary_path=/tmp/dictionaries'] }
|
35
37
|
|
36
38
|
it { should contain('==> Configuration for radius_authenticatable') }
|
37
39
|
it { should contain("config.radius_server = '1.1.1.2'") }
|
@@ -41,6 +43,7 @@ describe DeviseRadiusAuthenticatable::InstallGenerator do
|
|
41
43
|
it { should contain("config.radius_server_retries = 3") }
|
42
44
|
it { should contain("config.radius_uid_field = :email") }
|
43
45
|
it { should contain("config.radius_uid_generator =") }
|
46
|
+
it { should contain("config.radius_dictionary_path = '/tmp/dictionaries'") }
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -214,6 +214,13 @@ Devise.setup do |config|
|
|
214
214
|
# "#{username}@#{server}"
|
215
215
|
# end
|
216
216
|
|
217
|
+
# There is a very basic radius dictionary provided by default. Most of the time
|
218
|
+
# this will not be sufficient, so this configuration option allows you to
|
219
|
+
# specify the path that contains all of the radius dictionary files that should
|
220
|
+
# be loaded.
|
221
|
+
#
|
222
|
+
config.radius_dictionary_path = Rails.root.join('config/dictionaries')
|
223
|
+
|
217
224
|
# ==> Scopes configuration
|
218
225
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
219
226
|
# "users/sessions/new". It's turned off by default because it's slower if you
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-radius-authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: devise
|