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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50add36032057f0024e7af81e7055804e02e4eb61f90d176c699edc74992fddc
4
- data.tar.gz: cfc23a269d4db8c23ea42dcf75497d8d29e3787d3cf400253e7469d393ee11ee
3
+ metadata.gz: c01bc4ef653493a9fcdd7be68a8bf4d14bac360886220bb59b6c65bbc72a5dbb
4
+ data.tar.gz: '06823ef1eb2857d450cd8d76bcea3d0ab194bff19056a12e15df26ca25bb724a'
5
5
  SHA512:
6
- metadata.gz: 0ebba7a86ee0066b17941a455ee6ea4c9f492b6d40b30af9a815a2964e5ede52cfc844c61803f4ebcf4e434b1b2cbe78c93f0ae51eaad57ec7b9d9ec6ae11a26
7
- data.tar.gz: ae818e334a2b1e04e8420d68f2eecc2c281ec88507442dcd46ce1e59ba5092a32c6c9d2e6058c4d69db0407d7cfb1325d4ee4a9cf49e81746fccba2c1d95168a
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 = local_user
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 = ldap_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
- set_flash_message!(:alert, :invalid, authentication_keys: resource_class.authentication_keys.join(", "))
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 the same
28
- # answer as a wrong password, never the failure app's redirect, which would tell that the
29
- # password was right. Devise refuses by throw :warden from its after_set_user hook, after
30
- # logging the user out: caught here, it becomes "no local user".
31
- def local_user
32
- user = catch(:warden) { warden.authenticate(auth_options) }
33
- user if user.is_a?(resource_class)
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 ldap_user
37
- user = Ldap::Authenticator.new(
38
- email: params[:user][:email],
39
- password: params[:user][:password],
40
- ).authenticate
41
- user if user&.active_for_authentication?
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)
@@ -1,3 +1,3 @@
1
1
  module ThecoreAuthCommons
2
- VERSION = "3.7.0".freeze
2
+ VERSION = "3.7.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_auth_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni