-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/shibui-1788 (pull request #484)
Feature/shibui 1788 Approved-by: Ryan Mathis
- Loading branch information
Showing
44 changed files
with
773 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 63 additions & 11 deletions
74
...a/edu/internet2/tier/shibboleth/admin/ui/configuration/CustomPropertiesConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,88 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.configuration; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.domain.IRelyingPartyOverrideProperty; | ||
import edu.internet2.tier.shibboleth.admin.ui.domain.RelyingPartyOverrideProperty; | ||
import edu.internet2.tier.shibboleth.admin.ui.service.CustomEntityAttributesDefinitionService; | ||
import edu.internet2.tier.shibboleth.admin.ui.service.events.CustomEntityAttributeDefinitionChangeEvent; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Bill Smith (wsmith@unicon.net) | ||
*/ | ||
@Configuration | ||
@ConfigurationProperties(prefix="custom") | ||
public class CustomPropertiesConfiguration { | ||
import javax.annotation.PostConstruct; | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "custom") | ||
public class CustomPropertiesConfiguration implements ApplicationListener<CustomEntityAttributeDefinitionChangeEvent> { | ||
private List<? extends Map<String, String>> attributes = new ArrayList<>(); | ||
private List<RelyingPartyOverrideProperty> overrides = new ArrayList<>(); | ||
|
||
private CustomEntityAttributesDefinitionService ceadService; | ||
|
||
private HashMap<String, IRelyingPartyOverrideProperty> overrides = new HashMap<>(); | ||
|
||
private List<RelyingPartyOverrideProperty> overridesFromConfigFile = new ArrayList<>(); | ||
|
||
private void buildRelyingPartyOverrides() { | ||
// Start over with a clean map and get the CustomEntityAttributesDefinitions from the DB | ||
HashMap<String, IRelyingPartyOverrideProperty> reloaded = new HashMap<>(); | ||
ceadService.getAllDefinitions().forEach(def -> { | ||
def.updateExamplesList(); // totally non-ooo, but @PostLoad wasn't working and JPA/Hibernate is doing some reflection crap | ||
reloaded.put(def.getName(), def); | ||
}); | ||
|
||
// We only want to add to an override from the config file if the incoming override (by name) isn't already in | ||
// the list of overrides (ie DB > file config) | ||
for (RelyingPartyOverrideProperty rpop : this.overridesFromConfigFile) { | ||
if (!reloaded.containsKey(rpop.getName())) { | ||
reloaded.put(rpop.getName(), rpop); | ||
} | ||
} | ||
|
||
this.overrides = reloaded; | ||
} | ||
|
||
public List<? extends Map<String, String>> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
public List<IRelyingPartyOverrideProperty> getOverrides() { | ||
return new ArrayList<>(overrides.values()); | ||
} | ||
|
||
/** | ||
* We don't know what change occurred, so the easiest thing to do is just rebuild our map of overrides. | ||
* (especially since the small occurrence of this and number of items makes doing this ok perf-wise). | ||
*/ | ||
@Override | ||
public void onApplicationEvent(CustomEntityAttributeDefinitionChangeEvent arg0) { | ||
buildRelyingPartyOverrides(); | ||
} | ||
|
||
@PostConstruct | ||
public void postConstruct() { | ||
// Make sure we have the right data | ||
buildRelyingPartyOverrides(); | ||
} | ||
|
||
public void setAttributes(List<? extends Map<String, String>> attributes) { | ||
this.attributes = attributes; | ||
} | ||
|
||
public List<RelyingPartyOverrideProperty> getOverrides() { | ||
return overrides; | ||
@Autowired | ||
public void setCeadService(CustomEntityAttributesDefinitionService ceadService) { | ||
this.ceadService = ceadService; | ||
} | ||
|
||
public void setOverrides(List<RelyingPartyOverrideProperty> overrides) { | ||
this.overrides = overrides; | ||
/** | ||
* This setter will get used by Spring's property system to create objects from a config file (should the properties exist) | ||
*/ | ||
public void setOverrides(List<RelyingPartyOverrideProperty> overridesFromConfigFile) { | ||
this.overridesFromConfigFile = overridesFromConfigFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.