thecore_auth_commons 3.7.0 → 3.7.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.
- checksums.yaml +4 -4
- data/app/controllers/users/sessions_controller.rb +26 -20
- data/lib/thecore_auth_commons/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c01bc4ef653493a9fcdd7be68a8bf4d14bac360886220bb59b6c65bbc72a5dbb
|
|
4
|
+
data.tar.gz: '06823ef1eb2857d450cd8d76bcea3d0ab194bff19056a12e15df26ca25bb724a'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57c119bb8e461438a3ed596e73395804ec61c741e8af496dc2c370d4980618aa3c6994df90c1c7ac985a660b8528d197f0788d8e3b7868a64acaf0e804ef5fcd
|
|
7
|
+
data.tar.gz: 79f8b576003370ca296c9dcd61311296efbd0cc3ca5f7e7f980eeef389e536b0a4a57bbf761d8d22f8dd802544f1ec609693642b1a8647a6b96f15f2e8197eec
|
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
# app/controllers/users/sessions_controller.rb
|
|
2
2
|
class Users::SessionsController < Devise::SessionsController
|
|
3
3
|
def create
|
|
4
|
-
self.resource =
|
|
4
|
+
self.resource = warden.authenticate(auth_options)
|
|
5
5
|
|
|
6
6
|
if resource
|
|
7
7
|
Rails.logger.info("Authentication: Found local user, signing in")
|
|
8
8
|
sign_in_and_redirect(resource)
|
|
9
9
|
else
|
|
10
10
|
Rails.logger.info("Authentication: Not found a local user, trying LDAP")
|
|
11
|
-
user =
|
|
11
|
+
user = Ldap::Authenticator.new(
|
|
12
|
+
email: params[:user][:email],
|
|
13
|
+
password: params[:user][:password],
|
|
14
|
+
).authenticate
|
|
12
15
|
|
|
13
16
|
if user
|
|
14
17
|
sign_in_and_redirect(user)
|
|
15
18
|
else
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
self.resource = resource_class.new(sign_in_params)
|
|
19
|
-
clean_up_passwords(resource)
|
|
20
|
-
respond_with_navigational(resource) { render :new, status: :unauthorized }
|
|
19
|
+
refuse_like_a_wrong_password
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
private
|
|
26
25
|
|
|
27
|
-
# A user Devise refuses (User#active_for_authentication? false: a locked one) must get
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
# A user Devise refuses (User#active_for_authentication? false: a locked one) must get exactly
|
|
27
|
+
# the wrong-password answer, never the failure app's 302, which would tell that the password was
|
|
28
|
+
# right. Devise refuses by throw :warden from its after_set_user hook (after logging the user
|
|
29
|
+
# out) wherever the user is first authenticated in this request: in create, in sign_in after
|
|
30
|
+
# LDAP, or already in a before_action reading current_user (thecore_ui_commons' reject_locked!),
|
|
31
|
+
# since Devise lets the password strategy run on the form params for the whole sign-in request.
|
|
32
|
+
# So the catch wraps the whole action, callbacks included.
|
|
33
|
+
def process_action(*)
|
|
34
|
+
return super unless action_name == "create"
|
|
35
|
+
|
|
36
|
+
catch(:warden) { return super }
|
|
37
|
+
refuse_like_a_wrong_password
|
|
34
38
|
end
|
|
35
39
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
def refuse_like_a_wrong_password
|
|
41
|
+
# The form params must not authenticate anyone again while the page renders (current_user).
|
|
42
|
+
request.env["devise.allow_params_authentication"] = false
|
|
43
|
+
set_flash_message!(:alert, :invalid, authentication_keys: resource_class.authentication_keys.join(", "))
|
|
44
|
+
|
|
45
|
+
self.resource = resource_class.new(sign_in_params)
|
|
46
|
+
clean_up_passwords(resource)
|
|
47
|
+
respond_with_navigational(resource) { render :new, status: :unauthorized }
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def sign_in_and_redirect(resource)
|