From c2c601cd9c1bd76790f23277752f9f418e201527 Mon Sep 17 00:00:00 2001 From: chasegawa Date: Wed, 17 Aug 2022 15:20:59 -0700 Subject: [PATCH] SHIBUI-2268 load custom properties to database from application.yml file Former-commit-id: 70e9420d876c96b23f48bf7d0459bffb5c0d8ef0 --- .../CustomPropertiesConfiguration.java | 28 ++++++++++++++++++- .../ui/service/ShibConfigurationService.java | 2 ++ .../service/ShibConfigurationServiceImpl.java | 5 ++++ backend/src/main/resources/application.yml | 25 ++++++++--------- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/CustomPropertiesConfiguration.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/CustomPropertiesConfiguration.java index 9a85e48a2..c2a032f36 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/CustomPropertiesConfiguration.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/CustomPropertiesConfiguration.java @@ -4,6 +4,7 @@ import edu.internet2.tier.shibboleth.admin.ui.domain.RelyingPartyOverrideProperty; import edu.internet2.tier.shibboleth.admin.ui.domain.ShibConfigurationProperty; import edu.internet2.tier.shibboleth.admin.ui.service.CustomEntityAttributesDefinitionService; +import edu.internet2.tier.shibboleth.admin.ui.service.ShibConfigurationService; import edu.internet2.tier.shibboleth.admin.ui.service.events.CustomEntityAttributeDefinitionChangeEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -29,6 +30,8 @@ public class CustomPropertiesConfiguration implements ApplicationListener shibprops = new ArrayList<>(); + private ShibConfigurationService shibConfigurationService; + private void buildRelyingPartyOverrides() { // Start over with a clean map and get the CustomEntityAttributesDefinitions from the DB HashMap reloaded = new HashMap<>(); @@ -81,13 +84,36 @@ public void setCeadService(CustomEntityAttributesDefinitionService ceadService) this.ceadService = ceadService; } + @Autowired + public void setShibConfigurationService(ShibConfigurationService service) { + this.shibConfigurationService = service; + } + /** - * This setter will get used by Spring's property system to create objects from a config file (should the properties exist) + * This setter will get used by Spring's property system to create objects from application.yml (should the properties exist) */ public void setOverrides(List overridesFromConfigFile) { this.overridesFromConfigFile = overridesFromConfigFile; } + /** + * This setter will get used by Spring's property system to create objects from application.yml (should the properties exist) + */ + public void setShibprops(List props) { + this.shibprops = props; + } + + /** + * Add any custom properties from the application.yml - any incoming property with the same name as an existing property will be + * ignored (ie this will not update/replace information for existing properties). This shouldn't be considered standard, but + * offers users the ability to add properties to their system from an addon module, new feature etc. + */ private void updateShibPropsDatabase() { + List existingPropNames = shibConfigurationService.getExistingPropertyNames(); + shibprops.forEach(prop -> { + if (!existingPropNames.contains(prop.getPropertyName())) { + shibConfigurationService.save(prop); + } + }); } } \ No newline at end of file diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationService.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationService.java index 504c60956..b6c39ec44 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationService.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationService.java @@ -9,4 +9,6 @@ public interface ShibConfigurationService { void addAll(Collection newProperties); List getExistingPropertyNames(); + + void save(ShibConfigurationProperty prop); } \ No newline at end of file diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationServiceImpl.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationServiceImpl.java index d9d29c37f..8456940aa 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationServiceImpl.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationServiceImpl.java @@ -22,4 +22,9 @@ public void addAll(Collection newProperties) { public List getExistingPropertyNames() { return repository.getPropertyNames(); } + + @Override + public void save(ShibConfigurationProperty prop) { + repository.save(prop); + } } \ No newline at end of file diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 09d922b1c..31e5eeb5a 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -163,16 +163,15 @@ custom: helpText: tooltip.ignore-request-signatures attributeName: http://shibboleth.net/ns/profiles/ignoreRequestSignatures attributeFriendlyName: ignoreRequestSignatures - shibprops: - - category: asd # required - configFile: kj # required - defaultValue: foo - description: blak - idpVersion: 4.1 # required - module: h - moduleVersion: 1 - note: nnn - propertyName: dddd # required - propertyType: dddd # required as one of: BOOLEAN, DURATION, INTEGER, SELECTION_LIST, SPRING_BEAN_ID, STRING - propertyValue: dddd - selectionItems: dddd,dddd # required if propertyType is SELECTION_LIST - comma seperated values \ No newline at end of file +# shibprops: +# - category: main # required +# configFile: random.properties # required +# defaultValue: foo +# description: whatever +# idpVersion: 4.1 # required +# module: some random module +# moduleVersion: 1 +# note: this is an example for the application.yml file +# propertyName: example.property.name # required +# propertyType: SELECTION_LIST # required as one of: BOOLEAN, DURATION, INTEGER, SELECTION_LIST, SPRING_BEAN_ID, STRING +# selectionItems: dddd,eeee # required if propertyType is SELECTION_LIST - comma seperated values \ No newline at end of file