diff --git a/src/main/java/nl/_42/boot/onelogin/saml/Saml2Properties.java b/src/main/java/nl/_42/boot/onelogin/saml/Saml2Properties.java index 82fca1d..016642a 100644 --- a/src/main/java/nl/_42/boot/onelogin/saml/Saml2Properties.java +++ b/src/main/java/nl/_42/boot/onelogin/saml/Saml2Properties.java @@ -155,4 +155,23 @@ private static String getLoginUrl(String baseUrl, String id) { return String.format("%s/saml2/login/%s", basePath, id); } + /** + * Refresh properties after context change, done programmatically + * because not every library user has cloud libraries available. + * @param properties the refreshed properties + */ + public void refresh(Saml2Properties properties) { + this.enabled = properties.isEnabled(); + this.baseUrl = properties.getBaseUrl(); + this.defaultLoginUrl = properties.getDefaultLoginUrl(); + this.defaultLoginSkipRedirect = properties.isDefaultLoginSkipRedirect(); + this.successUrl = properties.getSuccessUrl(); + this.failureUrl = properties.getFailureUrl(); + this.sessionTimeout = properties.getSessionTimeout(); + this.properties = new Properties(properties.getProperties()); + this.registrations = new HashMap<>(properties.getRegistrations()); + + afterPropertiesSet(); + } + } diff --git a/src/main/java/nl/_42/boot/onelogin/saml/Saml2RefreshEventListener.java b/src/main/java/nl/_42/boot/onelogin/saml/Saml2RefreshEventListener.java index 1a20956..96c29b5 100644 --- a/src/main/java/nl/_42/boot/onelogin/saml/Saml2RefreshEventListener.java +++ b/src/main/java/nl/_42/boot/onelogin/saml/Saml2RefreshEventListener.java @@ -1,6 +1,7 @@ package nl._42.boot.onelogin.saml; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.ApplicationContext; import org.springframework.context.event.EventListener; @@ -22,7 +23,9 @@ public Saml2RefreshEventListener(ApplicationContext applicationContext, Saml2Pro @EventListener public void handleContextRefresh(org.springframework.cloud.endpoint.event.RefreshEvent event) { log.info("Refreshing SAML2 properties after event '{}'...", event.getEvent()); - applicationContext.getAutowireCapableBeanFactory().autowireBean(properties); + AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory(); + Saml2Properties refreshed = beanFactory.createBean(Saml2Properties.class); + properties.refresh(refreshed); } }