From 8f48d3e812fa5d1a18d1e686792ee3fabfce9bc9 Mon Sep 17 00:00:00 2001 From: Dario Ghunney Ware Date: Tue, 25 Nov 2025 21:01:56 +0000 Subject: [PATCH] adding auth types for grandfathering --- .../database/repository/UserRepository.java | 17 +++++++++++++++++ .../security/service/UserService.java | 11 ++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/database/repository/UserRepository.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/database/repository/UserRepository.java index e96d3f03f2..1a8b51bca1 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/security/database/repository/UserRepository.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/database/repository/UserRepository.java @@ -46,4 +46,21 @@ public interface UserRepository extends JpaRepository { long countByOauthGrandfatheredTrue(); List findAllBySsoProviderIsNotNull(); + + /** + * Finds all SSO users - those with sso_provider set OR authenticationType is sso/oauth2/saml2. + * This catches V1 users who were created via SSO but never signed in (sso_provider is null). + */ + @Query( + "SELECT u FROM User u WHERE u.ssoProvider IS NOT NULL " + + "OR LOWER(u.authenticationType) IN ('sso', 'oauth2', 'saml2')") + List findAllSsoUsers(); + + /** + * Counts all SSO users - those with sso_provider set OR authenticationType is sso/oauth2/saml2. + */ + @Query( + "SELECT COUNT(u) FROM User u WHERE u.ssoProvider IS NOT NULL " + + "OR LOWER(u.authenticationType) IN ('sso', 'oauth2', 'saml2')") + long countSsoUsers(); } diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/service/UserService.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/service/UserService.java index 3a641d7645..d131eb2bdc 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/security/service/UserService.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/service/UserService.java @@ -736,12 +736,13 @@ public class UserService implements UserServiceInterface { } /** - * Counts the number of OAuth/SAML users (users with SSO provider set). + * Counts the number of OAuth/SAML users. Includes users with sso_provider set OR + * authenticationType is sso/oauth2/saml2 (catches V1 users who never signed in). * * @return Count of OAuth users */ public long countOAuthUsers() { - return userRepository.countBySsoProviderIsNotNull(); + return userRepository.countSsoUsers(); } /** @@ -761,10 +762,10 @@ public class UserService implements UserServiceInterface { */ @Transactional public int grandfatherAllOAuthUsers() { - List oauthUsers = userRepository.findAllBySsoProviderIsNotNull(); + List ssoUsers = userRepository.findAllSsoUsers(); int updated = 0; - for (User user : oauthUsers) { + for (User user : ssoUsers) { if (!user.isOauthGrandfathered()) { user.setOauthGrandfathered(true); updated++; @@ -772,7 +773,7 @@ public class UserService implements UserServiceInterface { } if (updated > 0) { - userRepository.saveAll(oauthUsers); + userRepository.saveAll(ssoUsers); } return updated;