devise-radius-authenticatable 0.0.1
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/.gitignore +7 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +21 -0
- data/README.md +83 -0
- data/Rakefile +16 -0
- data/devise-radius-authenticatable.gemspec +32 -0
- data/lib/devise/models/radius_authenticatable.rb +131 -0
- data/lib/devise/radius_authenticatable/version.rb +5 -0
- data/lib/devise/radius_authenticatable.rb +32 -0
- data/lib/devise/strategies/radius_authenticatable.rb +27 -0
- data/lib/devise-radius-authenticatable.rb +2 -0
- data/lib/generators/devise_radius_authenticatable/install_generator.rb +78 -0
- data/spec/devise/models/radius_authenticatable_spec.rb +136 -0
- data/spec/factories/admins.rb +10 -0
- data/spec/fixtures/devise.rb +238 -0
- data/spec/generators/install_generator_spec.rb +46 -0
- data/spec/integration/radius_authenticatable_spec.rb +101 -0
- data/spec/rails_app/.gitignore +15 -0
- data/spec/rails_app/Gemfile +4 -0
- data/spec/rails_app/Rakefile +7 -0
- data/spec/rails_app/app/assets/images/rails.png +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +15 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
- data/spec/rails_app/app/controllers/admins_controller.rb +83 -0
- data/spec/rails_app/app/controllers/application_controller.rb +11 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_app/app/mailers/.gitkeep +0 -0
- data/spec/rails_app/app/models/.gitkeep +0 -0
- data/spec/rails_app/app/models/admin.rb +13 -0
- data/spec/rails_app/app/views/admins/_form.html.erb +17 -0
- data/spec/rails_app/app/views/admins/edit.html.erb +6 -0
- data/spec/rails_app/app/views/admins/index.html.erb +21 -0
- data/spec/rails_app/app/views/admins/new.html.erb +5 -0
- data/spec/rails_app/app/views/admins/show.html.erb +5 -0
- data/spec/rails_app/app/views/devise/confirmations/new.html.erb +12 -0
- data/spec/rails_app/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/spec/rails_app/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/spec/rails_app/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/spec/rails_app/app/views/devise/passwords/edit.html.erb +16 -0
- data/spec/rails_app/app/views/devise/passwords/new.html.erb +12 -0
- data/spec/rails_app/app/views/devise/registrations/edit.html.erb +25 -0
- data/spec/rails_app/app/views/devise/registrations/new.html.erb +18 -0
- data/spec/rails_app/app/views/devise/sessions/new.html.erb +17 -0
- data/spec/rails_app/app/views/devise/shared/_links.erb +25 -0
- data/spec/rails_app/app/views/devise/unlocks/new.html.erb +12 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +25 -0
- data/spec/rails_app/config/application.rb +62 -0
- data/spec/rails_app/config/boot.rb +6 -0
- data/spec/rails_app/config/database.yml +25 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +37 -0
- data/spec/rails_app/config/environments/production.rb +67 -0
- data/spec/rails_app/config/environments/test.rb +37 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/devise.rb +278 -0
- data/spec/rails_app/config/initializers/inflections.rb +15 -0
- data/spec/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/rails_app/config/initializers/session_store.rb +8 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_app/config/locales/devise.en.yml +58 -0
- data/spec/rails_app/config/locales/en.yml +5 -0
- data/spec/rails_app/config/routes.rb +66 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/db/migrate/20120627042556_devise_create_admins.rb +48 -0
- data/spec/rails_app/db/schema.rb +37 -0
- data/spec/rails_app/db/seeds.rb +7 -0
- data/spec/rails_app/lib/assets/.gitkeep +0 -0
- data/spec/rails_app/lib/tasks/.gitkeep +0 -0
- data/spec/rails_app/public/404.html +26 -0
- data/spec/rails_app/public/422.html +26 -0
- data/spec/rails_app/public/500.html +25 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/robots.txt +5 -0
- data/spec/rails_app/script/rails +6 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/devise_helpers.rb +18 -0
- data/spec/support/generator_helpers.rb +19 -0
- data/spec/support/radius_helpers.rb +84 -0
- metadata +389 -0
@@ -0,0 +1,238 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth.
|
2
|
+
# Many of these configuration options can be set straight in your model.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# ==> Mailer Configuration
|
5
|
+
# Configure the e-mail address which will be shown in Devise::Mailer,
|
6
|
+
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
7
|
+
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
8
|
+
|
9
|
+
# Configure the class responsible to send e-mails.
|
10
|
+
# config.mailer = "Devise::Mailer"
|
11
|
+
|
12
|
+
# ==> ORM configuration
|
13
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
14
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
15
|
+
# available as additional gems.
|
16
|
+
require 'devise/orm/active_record'
|
17
|
+
|
18
|
+
# ==> Configuration for any authentication mechanism
|
19
|
+
# Configure which keys are used when authenticating a user. The default is
|
20
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
21
|
+
# authenticating a user, both parameters are required. Remember that those
|
22
|
+
# parameters are used only when authenticating and not when retrieving from
|
23
|
+
# session. If you need permissions, you should implement that in a before filter.
|
24
|
+
# You can also supply a hash where the value is a boolean determining whether
|
25
|
+
# or not authentication should be aborted when the value is not present.
|
26
|
+
# config.authentication_keys = [ :email ]
|
27
|
+
|
28
|
+
# Configure parameters from the request object used for authentication. Each entry
|
29
|
+
# given should be a request method and it will automatically be passed to the
|
30
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
31
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
32
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
33
|
+
# config.request_keys = []
|
34
|
+
|
35
|
+
# Configure which authentication keys should be case-insensitive.
|
36
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
37
|
+
# to authenticate or find a user. Default is :email.
|
38
|
+
config.case_insensitive_keys = [ :email ]
|
39
|
+
|
40
|
+
# Configure which authentication keys should have whitespace stripped.
|
41
|
+
# These keys will have whitespace before and after removed upon creating or
|
42
|
+
# modifying a user and when used to authenticate or find a user. Default is :email.
|
43
|
+
config.strip_whitespace_keys = [ :email ]
|
44
|
+
|
45
|
+
# Tell if authentication through request.params is enabled. True by default.
|
46
|
+
# It can be set to an array that will enable params authentication only for the
|
47
|
+
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
48
|
+
# enable it only for database (email + password) authentication.
|
49
|
+
# config.params_authenticatable = true
|
50
|
+
|
51
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
52
|
+
# It can be set to an array that will enable http authentication only for the
|
53
|
+
# given strategies, for example, `config.http_authenticatable = [:token]` will
|
54
|
+
# enable it only for token authentication.
|
55
|
+
# config.http_authenticatable = false
|
56
|
+
|
57
|
+
# If http headers should be returned for AJAX requests. True by default.
|
58
|
+
# config.http_authenticatable_on_xhr = true
|
59
|
+
|
60
|
+
# The realm used in Http Basic Authentication. "Application" by default.
|
61
|
+
# config.http_authentication_realm = "Application"
|
62
|
+
|
63
|
+
# It will change confirmation, password recovery and other workflows
|
64
|
+
# to behave the same regardless if the e-mail provided was right or wrong.
|
65
|
+
# Does not affect registerable.
|
66
|
+
# config.paranoid = true
|
67
|
+
|
68
|
+
# By default Devise will store the user in session. You can skip storage for
|
69
|
+
# :http_auth and :token_auth by adding those symbols to the array below.
|
70
|
+
# Notice that if you are skipping storage for all authentication paths, you
|
71
|
+
# may want to disable generating routes to Devise's sessions controller by
|
72
|
+
# passing :skip => :sessions to `devise_for` in your config/routes.rb
|
73
|
+
config.skip_session_storage = [:http_auth]
|
74
|
+
|
75
|
+
# ==> Configuration for :database_authenticatable
|
76
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
77
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
78
|
+
#
|
79
|
+
# Limiting the stretches to just one in testing will increase the performance of
|
80
|
+
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
81
|
+
# a value less than 10 in other environments.
|
82
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
83
|
+
|
84
|
+
# Setup a pepper to generate the encrypted password.
|
85
|
+
# config.pepper = "f71add1f76d905b20d078ddc6b517eb3228ced6c75913835875b0379829892d52f79f79ace5f42df0aa299aa894186db070ccbe678bf575d7a081b515bcfde60"
|
86
|
+
|
87
|
+
# ==> Configuration for :confirmable
|
88
|
+
# A period that the user is allowed to access the website even without
|
89
|
+
# confirming his account. For instance, if set to 2.days, the user will be
|
90
|
+
# able to access the website for two days without confirming his account,
|
91
|
+
# access will be blocked just in the third day. Default is 0.days, meaning
|
92
|
+
# the user cannot access the website without confirming his account.
|
93
|
+
# config.allow_unconfirmed_access_for = 2.days
|
94
|
+
|
95
|
+
# If true, requires any email changes to be confirmed (exactly the same way as
|
96
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
97
|
+
# db field (see migrations). Until confirmed new email is stored in
|
98
|
+
# unconfirmed email column, and copied to email column on successful confirmation.
|
99
|
+
config.reconfirmable = true
|
100
|
+
|
101
|
+
# Defines which key will be used when confirming an account
|
102
|
+
# config.confirmation_keys = [ :email ]
|
103
|
+
|
104
|
+
# ==> Configuration for :rememberable
|
105
|
+
# The time the user will be remembered without asking for credentials again.
|
106
|
+
# config.remember_for = 2.weeks
|
107
|
+
|
108
|
+
# If true, extends the user's remember period when remembered via cookie.
|
109
|
+
# config.extend_remember_period = false
|
110
|
+
|
111
|
+
# Options to be passed to the created cookie. For instance, you can set
|
112
|
+
# :secure => true in order to force SSL only cookies.
|
113
|
+
# config.rememberable_options = {}
|
114
|
+
|
115
|
+
# ==> Configuration for :validatable
|
116
|
+
# Range for password length. Default is 6..128.
|
117
|
+
# config.password_length = 6..128
|
118
|
+
|
119
|
+
# Email regex used to validate email formats. It simply asserts that
|
120
|
+
# an one (and only one) @ exists in the given string. This is mainly
|
121
|
+
# to give user feedback and not to assert the e-mail validity.
|
122
|
+
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
123
|
+
|
124
|
+
# ==> Configuration for :timeoutable
|
125
|
+
# The time you want to timeout the user session without activity. After this
|
126
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
127
|
+
# config.timeout_in = 30.minutes
|
128
|
+
|
129
|
+
# If true, expires auth token on session timeout.
|
130
|
+
# config.expire_auth_token_on_timeout = false
|
131
|
+
|
132
|
+
# ==> Configuration for :lockable
|
133
|
+
# Defines which strategy will be used to lock an account.
|
134
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
135
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
136
|
+
# config.lock_strategy = :failed_attempts
|
137
|
+
|
138
|
+
# Defines which key will be used when locking and unlocking an account
|
139
|
+
# config.unlock_keys = [ :email ]
|
140
|
+
|
141
|
+
# Defines which strategy will be used to unlock an account.
|
142
|
+
# :email = Sends an unlock link to the user email
|
143
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
144
|
+
# :both = Enables both strategies
|
145
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
146
|
+
# config.unlock_strategy = :both
|
147
|
+
|
148
|
+
# Number of authentication tries before locking an account if lock_strategy
|
149
|
+
# is failed attempts.
|
150
|
+
# config.maximum_attempts = 20
|
151
|
+
|
152
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
153
|
+
# config.unlock_in = 1.hour
|
154
|
+
|
155
|
+
# ==> Configuration for :recoverable
|
156
|
+
#
|
157
|
+
# Defines which key will be used when recovering the password for an account
|
158
|
+
# config.reset_password_keys = [ :email ]
|
159
|
+
|
160
|
+
# Time interval you can reset your password with a reset password key.
|
161
|
+
# Don't put a too small interval or your users won't have the time to
|
162
|
+
# change their passwords.
|
163
|
+
config.reset_password_within = 6.hours
|
164
|
+
|
165
|
+
# ==> Configuration for :encryptable
|
166
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
167
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
168
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
169
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
170
|
+
# REST_AUTH_SITE_KEY to pepper)
|
171
|
+
# config.encryptor = :sha512
|
172
|
+
|
173
|
+
# ==> Configuration for :token_authenticatable
|
174
|
+
# Defines name of the authentication token params key
|
175
|
+
# config.token_authentication_key = :auth_token
|
176
|
+
|
177
|
+
# ==> Scopes configuration
|
178
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
179
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
180
|
+
# are using only default views.
|
181
|
+
# config.scoped_views = false
|
182
|
+
|
183
|
+
# Configure the default scope given to Warden. By default it's the first
|
184
|
+
# devise role declared in your routes (usually :user).
|
185
|
+
# config.default_scope = :user
|
186
|
+
|
187
|
+
# Set this configuration to false if you want /users/sign_out to sign out
|
188
|
+
# only the current scope. By default, Devise signs out all scopes.
|
189
|
+
# config.sign_out_all_scopes = true
|
190
|
+
|
191
|
+
# ==> Navigation configuration
|
192
|
+
# Lists the formats that should be treated as navigational. Formats like
|
193
|
+
# :html, should redirect to the sign in page when the user does not have
|
194
|
+
# access, but formats like :xml or :json, should return 401.
|
195
|
+
#
|
196
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
197
|
+
# should add them to the navigational formats lists.
|
198
|
+
#
|
199
|
+
# The "*/*" below is required to match Internet Explorer requests.
|
200
|
+
# config.navigational_formats = ["*/*", :html]
|
201
|
+
|
202
|
+
# The default HTTP method used to sign out a resource. Default is :delete.
|
203
|
+
config.sign_out_via = :delete
|
204
|
+
|
205
|
+
# ==> OmniAuth
|
206
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
207
|
+
# up on your models and hooks.
|
208
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
209
|
+
|
210
|
+
# ==> Warden configuration
|
211
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
212
|
+
# change the failure app, you can configure them inside the config.warden block.
|
213
|
+
#
|
214
|
+
# config.warden do |manager|
|
215
|
+
# manager.intercept_401 = false
|
216
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
217
|
+
# end
|
218
|
+
config.warden do |warden_config|
|
219
|
+
warden_config.default_strategies(:token_authenticatable,
|
220
|
+
:database_authenticatable,
|
221
|
+
:radius_authenticatable,
|
222
|
+
{:scope => :administrator})
|
223
|
+
end
|
224
|
+
|
225
|
+
# ==> Mountable engine configurations
|
226
|
+
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
|
227
|
+
# is mountable, there are some extra configurations to be taken into account.
|
228
|
+
# The following options are available, assuming the engine is mounted as:
|
229
|
+
#
|
230
|
+
# mount MyEngine, at: "/my_engine"
|
231
|
+
#
|
232
|
+
# The router that invoked `devise_for`, in the example above, would be:
|
233
|
+
# config.router_name = :my_engine
|
234
|
+
#
|
235
|
+
# When using omniauth, Devise cannot automatically set Omniauth path,
|
236
|
+
# so you need to do it manually. For the users scope, it would be:
|
237
|
+
# config.omniauth_path_prefix = "/my_engine/users/auth"
|
238
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/devise_radius_authenticatable/install_generator'
|
3
|
+
|
4
|
+
describe DeviseRadiusAuthenticatable::InstallGenerator do
|
5
|
+
it "requires the radius server IP to be specified" do
|
6
|
+
expect { run_generator }.
|
7
|
+
to raise_error(Thor::RequiredArgumentMissingError, /required arguments 'server'/)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "requires the radius server shared secret to be specified" do
|
11
|
+
expect { run_generator ['1.1.1.1'] }.
|
12
|
+
to raise_error(Thor::RequiredArgumentMissingError, /required arguments 'secret'/)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with required arguments" do
|
16
|
+
|
17
|
+
subject { file('config/initializers/devise.rb') }
|
18
|
+
|
19
|
+
context "with default options" do
|
20
|
+
before { run_generator ['1.1.1.1', 'secret'] }
|
21
|
+
|
22
|
+
it { should contain('==> Configuration for radius_authenticatable') }
|
23
|
+
it { should contain("config.radius_server = '1.1.1.1'") }
|
24
|
+
it { should contain("config.radius_server_port = 1812") }
|
25
|
+
it { should contain("config.radius_server_secret = 'secret'") }
|
26
|
+
it { should contain("config.radius_server_timeout = 60") }
|
27
|
+
it { should contain("config.radius_server_retries = 0") }
|
28
|
+
it { should contain("config.radius_uid_field = :uid") }
|
29
|
+
it { should contain("config.radius_uid_generator =") }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with custom options" do
|
33
|
+
before { run_generator ['1.1.1.2', 'password', '--port=1813', '--timeout=120',
|
34
|
+
'--retries=3', '--uid_field=email'] }
|
35
|
+
|
36
|
+
it { should contain('==> Configuration for radius_authenticatable') }
|
37
|
+
it { should contain("config.radius_server = '1.1.1.2'") }
|
38
|
+
it { should contain("config.radius_server_port = 1813") }
|
39
|
+
it { should contain("config.radius_server_secret = 'password'") }
|
40
|
+
it { should contain("config.radius_server_timeout = 120") }
|
41
|
+
it { should contain("config.radius_server_retries = 3") }
|
42
|
+
it { should contain("config.radius_uid_field = :email") }
|
43
|
+
it { should contain("config.radius_uid_generator =") }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "login" do
|
4
|
+
before do
|
5
|
+
@admin = FactoryGirl.create(:admin, :password => 'password')
|
6
|
+
create_radius_user('testuser', 'password')
|
7
|
+
visit new_admin_session_path
|
8
|
+
end
|
9
|
+
|
10
|
+
it "is successful for a database user" do
|
11
|
+
fill_in "Login", :with => @admin.email
|
12
|
+
fill_in "Password", :with => 'password'
|
13
|
+
click_button "Sign in"
|
14
|
+
|
15
|
+
current_path.should == root_path
|
16
|
+
page.should have_content("Signed in successfully")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is successful for a radius user" do
|
20
|
+
fill_in "Login", :with => 'testuser'
|
21
|
+
fill_in "Password", :with => 'password'
|
22
|
+
click_button "Sign in"
|
23
|
+
|
24
|
+
current_path.should == root_path
|
25
|
+
page.should have_content("Signed in successfully")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "fails for wrong database password" do
|
29
|
+
fill_in "Login", :with => @admin.email
|
30
|
+
fill_in "Password", :with => 'password2'
|
31
|
+
click_button "Sign in"
|
32
|
+
|
33
|
+
current_path.should == new_admin_session_path
|
34
|
+
page.should have_content("Invalid email or password")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "fails for wrong radius password" do
|
38
|
+
fill_in "Login", :with => 'testuser'
|
39
|
+
fill_in "Password", :with => 'password2'
|
40
|
+
click_button "Sign in"
|
41
|
+
|
42
|
+
current_path.should == new_admin_session_path
|
43
|
+
page.should have_content("Invalid email or password")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "invokes the after_radius_authentication callback" do
|
47
|
+
fill_in "Login", :with => 'testuser'
|
48
|
+
fill_in "Password", :with => 'password'
|
49
|
+
click_button "Sign in"
|
50
|
+
|
51
|
+
uid = Admin.radius_uid_generator.call('testuser', Admin.radius_server)
|
52
|
+
Admin.where(Admin.radius_uid_field => uid).count.should == 1
|
53
|
+
end
|
54
|
+
|
55
|
+
it "successfully logs in a user with case insensitive username" do
|
56
|
+
swap(Devise, :case_insensitive_keys => [Admin.authentication_keys.first]) do
|
57
|
+
fill_in "Login", :with => 'TESTUSER'
|
58
|
+
fill_in "Password", :with => 'password'
|
59
|
+
click_button "Sign in"
|
60
|
+
|
61
|
+
current_path.should == root_path
|
62
|
+
page.should have_content("Signed in successfully")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "fails to log in a user with case sensitive username" do
|
67
|
+
swap(Devise, :case_insensitive_keys => []) do
|
68
|
+
fill_in "Login", :with => 'TESTUSER'
|
69
|
+
fill_in "Password", :with => 'password'
|
70
|
+
click_button "Sign in"
|
71
|
+
|
72
|
+
current_path.should == new_admin_session_path
|
73
|
+
page.should have_content("Invalid email or password")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when radius authentication is the first strategy" do
|
78
|
+
before do
|
79
|
+
@admin2 = FactoryGirl.create(:admin, :password => 'password')
|
80
|
+
create_radius_user(@admin2.email, 'password2')
|
81
|
+
|
82
|
+
@orig_order = Devise.warden_config.default_strategies(:scope => :admin)
|
83
|
+
Devise.warden_config.default_strategies(:radius_authenticatable,
|
84
|
+
:database_authenticatable,
|
85
|
+
{:scope => :admin})
|
86
|
+
end
|
87
|
+
|
88
|
+
after do
|
89
|
+
Devise.warden_config.default_strategies(@orig_order, {:scope => :admin})
|
90
|
+
end
|
91
|
+
|
92
|
+
it "proceeds with the next strategy if radius authentication fails" do
|
93
|
+
fill_in "Login", :with => @admin2.email
|
94
|
+
fill_in "Password", :with => 'password'
|
95
|
+
click_button "Sign in"
|
96
|
+
|
97
|
+
current_path.should == root_path
|
98
|
+
page.should have_content("Signed in successfully")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
RailsApp::Application.load_tasks
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class AdminsController < ApplicationController
|
2
|
+
# GET /admins
|
3
|
+
# GET /admins.json
|
4
|
+
def index
|
5
|
+
@admins = Admin.all
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.json { render json: @admins }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /admins/1
|
14
|
+
# GET /admins/1.json
|
15
|
+
def show
|
16
|
+
@admin = Admin.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.json { render json: @admin }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /admins/new
|
25
|
+
# GET /admins/new.json
|
26
|
+
def new
|
27
|
+
@admin = Admin.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.json { render json: @admin }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /admins/1/edit
|
36
|
+
def edit
|
37
|
+
@admin = Admin.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /admins
|
41
|
+
# POST /admins.json
|
42
|
+
def create
|
43
|
+
@admin = Admin.new(params[:admin])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @admin.save
|
47
|
+
format.html { redirect_to @admin, notice: 'Admin was successfully created.' }
|
48
|
+
format.json { render json: @admin, status: :created, location: @admin }
|
49
|
+
else
|
50
|
+
format.html { render action: "new" }
|
51
|
+
format.json { render json: @admin.errors, status: :unprocessable_entity }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# PUT /admins/1
|
57
|
+
# PUT /admins/1.json
|
58
|
+
def update
|
59
|
+
@admin = Admin.find(params[:id])
|
60
|
+
|
61
|
+
respond_to do |format|
|
62
|
+
if @admin.update_attributes(params[:admin])
|
63
|
+
format.html { redirect_to @admin, notice: 'Admin was successfully updated.' }
|
64
|
+
format.json { head :no_content }
|
65
|
+
else
|
66
|
+
format.html { render action: "edit" }
|
67
|
+
format.json { render json: @admin.errors, status: :unprocessable_entity }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# DELETE /admins/1
|
73
|
+
# DELETE /admins/1.json
|
74
|
+
def destroy
|
75
|
+
@admin = Admin.find(params[:id])
|
76
|
+
@admin.destroy
|
77
|
+
|
78
|
+
respond_to do |format|
|
79
|
+
format.html { redirect_to admins_url }
|
80
|
+
format.json { head :no_content }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Admin < ActiveRecord::Base
|
2
|
+
devise :database_authenticatable, :token_authenticatable, :radius_authenticatable
|
3
|
+
|
4
|
+
attr_accessor :login
|
5
|
+
|
6
|
+
attr_accessible :login, :email, :password, :password_confirmation, :remember_me, :uid
|
7
|
+
|
8
|
+
def self.find_for_database_authentication(conditions)
|
9
|
+
login = conditions.delete(:login)
|
10
|
+
conditions[:email] = login
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= form_for(@admin) do |f| %>
|
2
|
+
<% if @admin.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@admin.errors.count, "error") %> prohibited this admin from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @admin.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="actions">
|
15
|
+
<%= f.submit %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<h1>Listing admins</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th></th>
|
6
|
+
<th></th>
|
7
|
+
<th></th>
|
8
|
+
</tr>
|
9
|
+
|
10
|
+
<% @admins.each do |admin| %>
|
11
|
+
<tr>
|
12
|
+
<td><%= link_to 'Show', admin %></td>
|
13
|
+
<td><%= link_to 'Edit', edit_admin_path(admin) %></td>
|
14
|
+
<td><%= link_to 'Destroy', admin, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
15
|
+
</tr>
|
16
|
+
<% end %>
|
17
|
+
</table>
|
18
|
+
|
19
|
+
<br />
|
20
|
+
|
21
|
+
<%= link_to 'New Admin', new_admin_path %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2>Resend confirmation instructions</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<div><%= f.label :email %><br />
|
7
|
+
<%= f.email_field :email %></div>
|
8
|
+
|
9
|
+
<div><%= f.submit "Resend confirmation instructions" %></div>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<p>Hello <%= @resource.email %>!</p>
|
2
|
+
|
3
|
+
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
|
4
|
+
|
5
|
+
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
|
6
|
+
|
7
|
+
<p>If you didn't request this, please ignore this email.</p>
|
8
|
+
<p>Your password won't change until you access the link above and create a new one.</p>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<p>Hello <%= @resource.email %>!</p>
|
2
|
+
|
3
|
+
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
|
4
|
+
|
5
|
+
<p>Click the link below to unlock your account:</p>
|
6
|
+
|
7
|
+
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
|