thecore_auth_commons 3.6.5 → 3.7.0
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50add36032057f0024e7af81e7055804e02e4eb61f90d176c699edc74992fddc
|
|
4
|
+
data.tar.gz: cfc23a269d4db8c23ea42dcf75497d8d29e3787d3cf400253e7469d393ee11ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ebba7a86ee0066b17941a455ee6ea4c9f492b6d40b30af9a815a2964e5ede52cfc844c61803f4ebcf4e434b1b2cbe78c93f0ae51eaad57ec7b9d9ec6ae11a26
|
|
7
|
+
data.tar.gz: ae818e334a2b1e04e8420d68f2eecc2c281ec88507442dcd46ce1e59ba5092a32c6c9d2e6058c4d69db0407d7cfb1325d4ee4a9cf49e81746fccba2c1d95168a
|
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:
|
|
@@ -1,17 +1,14 @@
|
|
|
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 = local_user
|
|
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 =
|
|
12
|
-
email: params[:user][:email],
|
|
13
|
-
password: params[:user][:password],
|
|
14
|
-
).authenticate
|
|
11
|
+
user = ldap_user
|
|
15
12
|
|
|
16
13
|
if user
|
|
17
14
|
sign_in_and_redirect(user)
|
|
@@ -27,6 +24,23 @@ class Users::SessionsController < Devise::SessionsController
|
|
|
27
24
|
|
|
28
25
|
private
|
|
29
26
|
|
|
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)
|
|
34
|
+
end
|
|
35
|
+
|
|
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?
|
|
42
|
+
end
|
|
43
|
+
|
|
30
44
|
def sign_in_and_redirect(resource)
|
|
31
45
|
set_flash_message!(:notice, :signed_in)
|
|
32
46
|
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:
|
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.
|
|
4
|
+
version: 3.7.0
|
|
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-
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: net-ldap
|