thecore_auth_commons 3.6.2 → 3.6.4
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/README.md +1 -1
- data/app/models/ldap_server.rb +18 -5
- data/lib/thecore_auth_commons/version.rb +1 -1
- data/lib/thecore_auth_commons.rb +14 -10
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 12a1ac91347e483964693a18bb413a7029d8c7ef01883d870c58d9e14d09f881
|
|
4
|
+
data.tar.gz: 38f53bb70f70e1cd161ee5b747eccc13d429a76dc39f0da30fb933c03574e86d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1f222792185d7a252a1f9f914708562c4fd6d218247c701f847295a6c3ae935c8646b1690f66a8c684f1185521a65ed4a3eb4f870d49bf480e3cb670ec5451f
|
|
7
|
+
data.tar.gz: 84af957ff1d399bac491a9a38f6c94036f5450084f85baa5494d019f84ac148f3771d6878a2482f1bcaaafdd3648388cec06336891d7601f00dc0ae1bf447bc0
|
data/README.md
CHANGED
|
@@ -112,7 +112,7 @@ Deleting a `LdapServer` record keeps all users whose `auth_source` is `"ldap #{i
|
|
|
112
112
|
|
|
113
113
|
### OAuth2 (Entra ID / Google)
|
|
114
114
|
|
|
115
|
-
Handled by `Users::OmniauthCallbacksController`. On callback, `ThecoreAuthCommons.check_user` finds
|
|
115
|
+
Handled by `Users::OmniauthCallbacksController`. On callback, `ThecoreAuthCommons.check_user` finds the user by the provider-verified email or creates them (random secure password, `auth_source` `'google'` or `'microsoft'`, no admin, no roles: an administrator assigns those). An existing user's password, admin flag and `auth_source` are never changed by an OAuth login.
|
|
116
116
|
|
|
117
117
|
## Password policy
|
|
118
118
|
|
data/app/models/ldap_server.rb
CHANGED
|
@@ -14,8 +14,18 @@ class LdapServer < ApplicationRecord
|
|
|
14
14
|
# and need a local password set by hand to log in again.
|
|
15
15
|
after_destroy :turn_users_into_local_users
|
|
16
16
|
|
|
17
|
+
# The outcome of #test_connection: success? and, when it failed, the reason in message.
|
|
18
|
+
ConnectionResult = Data.define(:success, :message) do
|
|
19
|
+
def success? = success
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Binds as the admin user and reports whether that worked, and why not. Never raises for a
|
|
23
|
+
# server it cannot reach or bind to: the RailsAdmin test_ldap_server action shows the result.
|
|
17
24
|
def test_connection
|
|
18
|
-
|
|
25
|
+
if admin_user.blank? || admin_password.blank?
|
|
26
|
+
return ConnectionResult.new(success: false, message: "No admin user and password are configured for this server")
|
|
27
|
+
end
|
|
28
|
+
|
|
19
29
|
ldap = Net::LDAP.new(
|
|
20
30
|
host: host,
|
|
21
31
|
port: port,
|
|
@@ -26,14 +36,17 @@ class LdapServer < ApplicationRecord
|
|
|
26
36
|
password: admin_password
|
|
27
37
|
}
|
|
28
38
|
)
|
|
29
|
-
# Perform a simple bind to check the connection
|
|
30
39
|
if ldap.bind
|
|
31
|
-
# Connection successful
|
|
32
40
|
Rails.logger.info "Connection to LDAP server #{host} successful."
|
|
41
|
+
ConnectionResult.new(success: true, message: nil)
|
|
33
42
|
else
|
|
34
|
-
|
|
35
|
-
Rails.logger.info "Connection to LDAP server #{host} failed: #{
|
|
43
|
+
reason = ldap.get_operation_result.message
|
|
44
|
+
Rails.logger.info "Connection to LDAP server #{host} failed: #{reason}"
|
|
45
|
+
ConnectionResult.new(success: false, message: reason)
|
|
36
46
|
end
|
|
47
|
+
rescue Net::LDAP::Error => e
|
|
48
|
+
Rails.logger.info "Connection to LDAP server #{host} failed: #{e.message}"
|
|
49
|
+
ConnectionResult.new(success: false, message: e.message)
|
|
37
50
|
end
|
|
38
51
|
|
|
39
52
|
private
|
data/lib/thecore_auth_commons.rb
CHANGED
|
@@ -30,18 +30,22 @@ module ThecoreAuthCommons
|
|
|
30
30
|
ENV["GOOGLE_CLIENT_ID"].present? && ENV["GOOGLE_CLIENT_SECRET"].present?
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
|
|
33
|
+
# Restituisce l'utente con l'email verificata dal provider OAuth, creandolo se non esiste:
|
|
34
|
+
# password casuale, auth_source = provider, nessun admin e nessun ruolo (si assegnano a mano).
|
|
35
|
+
# Di un utente esistente aggiorna solo nome e cognome: password, admin e auth_source restano,
|
|
36
|
+
# così chi ha anche una password locale può continuare a usarla. nil se l'utente non è salvabile.
|
|
36
37
|
def self.check_user(email, name, surname, provider)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
u
|
|
40
|
-
u.
|
|
41
|
-
u.
|
|
42
|
-
u.
|
|
38
|
+
return if email.blank?
|
|
39
|
+
|
|
40
|
+
u = User.find_or_initialize_by(email: email.to_s.strip.downcase)
|
|
41
|
+
u.name = name if u.respond_to?(:name=)
|
|
42
|
+
u.surname = surname if u.respond_to?(:surname=)
|
|
43
|
+
if u.new_record?
|
|
44
|
+
u.password = u.password_confirmation = generate_secure_password
|
|
45
|
+
u.auth_source = provider # 'google' or 'microsoft'
|
|
46
|
+
end
|
|
43
47
|
u.save if u.changed?
|
|
44
|
-
u
|
|
48
|
+
u if u.persisted?
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
INITIAL_ADMIN_PASSWORD_FILE = "admin_initial_password".freeze
|
metadata
CHANGED
|
@@ -1,13 +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.
|
|
4
|
+
version: 3.6.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gabriele Tassoni
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: net-ldap
|
|
@@ -319,6 +320,7 @@ metadata:
|
|
|
319
320
|
homepage_uri: https://github.com/gabrieletassoni/thecore_auth_commons
|
|
320
321
|
source_code_uri: https://github.com/gabrieletassoni/thecore_auth_commons
|
|
321
322
|
changelog_uri: https://github.com/gabrieletassoni/thecore_auth_commons/blob/master/CHANGELOG.md
|
|
323
|
+
post_install_message:
|
|
322
324
|
rdoc_options: []
|
|
323
325
|
require_paths:
|
|
324
326
|
- lib
|
|
@@ -333,7 +335,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
333
335
|
- !ruby/object:Gem::Version
|
|
334
336
|
version: '0'
|
|
335
337
|
requirements: []
|
|
336
|
-
rubygems_version: 3.
|
|
338
|
+
rubygems_version: 3.5.22
|
|
339
|
+
signing_key:
|
|
337
340
|
specification_version: 4
|
|
338
341
|
summary: Common Auth methods and models to be used in thecore components.
|
|
339
342
|
test_files: []
|