Skip to content

Commit

Permalink
SHIBUI-2268
Browse files Browse the repository at this point in the history
load custom properties to database from application.yml file


Former-commit-id: 70e9420
  • Loading branch information
chasegawa committed Aug 17, 2022
1 parent 4683ce1 commit c2c601c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,8 @@ public class CustomPropertiesConfiguration implements ApplicationListener<Custom

private List<ShibConfigurationProperty> shibprops = new ArrayList<>();

private ShibConfigurationService shibConfigurationService;

private void buildRelyingPartyOverrides() {
// Start over with a clean map and get the CustomEntityAttributesDefinitions from the DB
HashMap<String, IRelyingPartyOverrideProperty> reloaded = new HashMap<>();
Expand Down Expand Up @@ -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<RelyingPartyOverrideProperty> 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<ShibConfigurationProperty> 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<String> existingPropNames = shibConfigurationService.getExistingPropertyNames();
shibprops.forEach(prop -> {
if (!existingPropNames.contains(prop.getPropertyName())) {
shibConfigurationService.save(prop);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface ShibConfigurationService {
void addAll(Collection<ShibConfigurationProperty> newProperties);

List<String> getExistingPropertyNames();

void save(ShibConfigurationProperty prop);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public void addAll(Collection<ShibConfigurationProperty> newProperties) {
public List<String> getExistingPropertyNames() {
return repository.getPropertyNames();
}

@Override
public void save(ShibConfigurationProperty prop) {
repository.save(prop);
}
}
25 changes: 12 additions & 13 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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

0 comments on commit c2c601c

Please sign in to comment.