1414@ Slf4j
1515public class SamlRelyingPartyRegistrationRepository implements RelyingPartyRegistrationRepository {
1616
17- private final Map <String , RelyingPartyRegistration > registrations = new ConcurrentHashMap <>();
17+ private volatile Map <String , RelyingPartyRegistration > registrations = new ConcurrentHashMap <>();
1818 private final SamlProvidersLoader providersLoader ;
1919
2020 public SamlRelyingPartyRegistrationRepository (IdentityProviderConfigRepository jpaProviderRepository ) {
@@ -24,7 +24,6 @@ public SamlRelyingPartyRegistrationRepository(IdentityProviderConfigRepository j
2424 SamlRegistrationBuilder registrationBuilder = new SamlRegistrationBuilder (encryptionKey , metadataFetcher );
2525 this .providersLoader = new SamlProvidersLoader (registrationBuilder );
2626
27- // Load providers on initialization
2827 loadProviders (jpaProviderRepository );
2928 }
3029
@@ -34,22 +33,30 @@ public RelyingPartyRegistration findByRegistrationId(String registrationId) {
3433 }
3534
3635 public void reloadProviders (IdentityProviderConfigRepository jpaProviderRepository ) {
37- registrations .clear ();
38- loadProviders (jpaProviderRepository );
36+ try {
37+ registrations = loadActiveProviders (jpaProviderRepository );
38+ log .info ("SAML providers reloaded successfully: {} providers loaded" , registrations .size ());
39+ } catch (Exception e ) {
40+ log .error ("Failed to reload SAML providers - keeping previous configuration" , e );
41+ }
3942 }
4043
4144 /**
4245 * Loads SAML providers using the specialized loader.
4346 * Delegates all async loading logic to SamlProvidersLoader.
47+ * App will start without providers if loading fails.
4448 */
4549 private void loadProviders (IdentityProviderConfigRepository jpaProviderRepository ) {
4650 try {
47- List <IdentityProviderConfig > activeProviders = jpaProviderRepository .findAllByActiveTrue ();
48- Map <String , RelyingPartyRegistration > loadedRegistrations =
49- providersLoader .loadProvidersAsync (activeProviders );
50- registrations .putAll (loadedRegistrations );
51+ registrations = loadActiveProviders (jpaProviderRepository );
52+ if (registrations .isEmpty ()) {
53+ log .warn ("No active SAML2 providers found. SAML2 authentication will not be available." );
54+ } else {
55+ log .info ("Successfully loaded {} SAML2 provider(s) on startup" , registrations .size ());
56+ }
5157 } catch (Exception e ) {
52- log .error ("Error during SAML provider loading: {}" , e .getMessage (), e );
58+ log .error ("Error during SAML provider loading - app will start without SAML2 authentication: {}" ,
59+ e .getMessage (), e );
5360 }
5461 }
5562
@@ -68,4 +75,11 @@ private String getValidatedEncryptionKey() {
6875 return encryptionKey ;
6976 }
7077
78+ private Map <String , RelyingPartyRegistration > loadActiveProviders (IdentityProviderConfigRepository repo ) {
79+ List <IdentityProviderConfig > activeProviders = repo .findAllByActiveTrue ();
80+ Map <String , RelyingPartyRegistration > loaded = providersLoader .loadProvidersAsync (activeProviders );
81+ return new ConcurrentHashMap <>(loaded );
82+ }
83+
84+
7185}
0 commit comments