Skip to content

Commit

Permalink
Merge pull request #20 from 42BV/feature/VA-7741-refresh
Browse files Browse the repository at this point in the history
VA-7741 properties are now refreshed automatically
  • Loading branch information
jeroenvs authored Sep 19, 2023
2 parents 64fcf27 + cb7a893 commit 1fb273a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/main/java/nl/_42/boot/onelogin/saml/Saml2Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

}

0 comments on commit 1fb273a

Please sign in to comment.