thecore_auth_commons 3.6.5 → 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: 8882fd092e0638c3dd090eb752eda2a9a0150f6c000e1b4cbf3343da6dbb853d
4
- data.tar.gz: 2dd4868c8183cdf702fc148a9927d795e93027161f1ef249b7d96ea492168fd6
3
+ metadata.gz: c01bc4ef653493a9fcdd7be68a8bf4d14bac360886220bb59b6c65bbc72a5dbb
4
+ data.tar.gz: '06823ef1eb2857d450cd8d76bcea3d0ab194bff19056a12e15df26ca25bb724a'
5
5
  SHA512:
6
- metadata.gz: d7ff0c9f614b4652a44beb92ea26197b148674c7113375f891971fc3f599ad0f224dfca434be127e468580434e52ada696659e0bb26c55f094682a78265f43dd
7
- data.tar.gz: e5f0cd716bbdb5b8a730b1bece85b3f26d9bd0d658739e66511fc4b4aacad8284068e609ad106e933c595d5c8a0445f31d0a7f099533d15458556df8acff4c04
6
+ metadata.gz: 57c119bb8e461438a3ed596e73395804ec61c741e8af496dc2c370d4980618aa3c6994df90c1c7ac985a660b8528d197f0788d8e3b7868a64acaf0e804ef5fcd
7
+ data.tar.gz: 79f8b576003370ca296c9dcd61311296efbd0cc3ca5f7e7f980eeef389e536b0a4a57bbf761d8d22f8dd802544f1ec609693642b1a8647a6b96f15f2e8197eec
data/README.md CHANGED
@@ -94,6 +94,10 @@ user.roles << role
94
94
 
95
95
  `Users::SessionsController#create` tries Devise first; if that fails it tries `Ldap::Authenticator`. On successful LDAP auth the user is created/updated via `ThecoreAuthCommons.align_user` and signed in.
96
96
 
97
+ ### Locked users
98
+
99
+ A user with `locked = true` can't sign in through any channel (password, LDAP, OAuth) and an open session ends at its next request; the message is the same as for a wrong password. `User#active_for_authentication?` is the check, also used by the API, M2M tokens and ActionCable in the gems above.
100
+
97
101
  ### LDAP servers (`LdapServer` model)
98
102
 
99
103
  Multiple servers are supported, ordered by `priority` (ascending). Each server configures:
@@ -16,17 +16,37 @@ class Users::SessionsController < Devise::SessionsController
16
16
  if user
17
17
  sign_in_and_redirect(user)
18
18
  else
19
- set_flash_message!(:alert, :invalid, authentication_keys: resource_class.authentication_keys.join(", "))
20
-
21
- self.resource = resource_class.new(sign_in_params)
22
- clean_up_passwords(resource)
23
- respond_with_navigational(resource) { render :new, status: :unauthorized }
19
+ refuse_like_a_wrong_password
24
20
  end
25
21
  end
26
22
  end
27
23
 
28
24
  private
29
25
 
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
38
+ end
39
+
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 }
48
+ end
49
+
30
50
  def sign_in_and_redirect(resource)
31
51
  set_flash_message!(:notice, :signed_in)
32
52
  sign_in(resource_name, resource)
data/app/models/user.rb CHANGED
@@ -38,6 +38,19 @@ class User < ApplicationRecord
38
38
  record.errors.add(attr, I18n.t("validation.errors.cannot_lock_last_admin")) if record.locked_changed? && record.locked_was == false && User.where(locked: false).count == 1
39
39
  end
40
40
 
41
+ # Devise asks this at every login (local, LDAP, OAuth) and at every request of an open session:
42
+ # a locked user is signed out and refused. Every other way to authenticate must ask it too
43
+ # (Odoo #6051).
44
+ def active_for_authentication?
45
+ super && !locked?
46
+ end
47
+
48
+ # The refusal reads like a wrong password, so it doesn't reveal that the account exists. Not
49
+ # Devise's :locked key: hosts and devise-i18n translate it as "Your account is locked."
50
+ def inactive_message
51
+ locked? ? :user_locked : super
52
+ end
53
+
41
54
  def display_name
42
55
  email
43
56
  end
@@ -3,6 +3,9 @@ en:
3
3
  test_connection:
4
4
  no_admin_credentials: "No admin user and password are configured for this server"
5
5
  devise:
6
+ failure:
7
+ # A locked user is refused with the same words as a wrong password (User#inactive_message)
8
+ user_locked: "Invalid credentials or password."
6
9
  sessions:
7
10
  invalid: "Invalid credentials or password."
8
11
  user:
@@ -3,6 +3,9 @@ it:
3
3
  test_connection:
4
4
  no_admin_credentials: "Utente e password di amministrazione non configurati per questo server"
5
5
  devise:
6
+ failure:
7
+ # A locked user is refused with the same words as a wrong password (User#inactive_message)
8
+ user_locked: "Credenziali %{authentication_keys} o password non valide."
6
9
  sessions:
7
10
  invalid: "Credenziali %{authentication_keys} o password non valide."
8
11
  user:
@@ -1,3 +1,3 @@
1
1
  module ThecoreAuthCommons
2
- VERSION = "3.6.5".freeze
2
+ VERSION = "3.7.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_auth_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.5
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-24 00:00:00.000000000 Z
11
+ date: 2026-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ldap