-
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.
Merge branch 'feature/shibui-2270' of bitbucket.org:unicon/shib-idp-u…
…i into feature/SHIBUI-2270-property-list
- Loading branch information
Showing
12 changed files
with
1,628 additions
and
8 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...main/groovy/edu/internet2/tier/shibboleth/admin/ui/service/ShibPropertiesBootstrap.groovy
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.service | ||
|
|
||
| import com.opencsv.CSVReader | ||
| import edu.internet2.tier.shibboleth.admin.ui.domain.ShibConfigurationProperty | ||
| import groovy.util.logging.Slf4j | ||
| import org.springframework.beans.factory.annotation.Autowired | ||
| import org.springframework.boot.context.event.ApplicationStartedEvent | ||
| import org.springframework.context.event.EventListener | ||
| import org.springframework.core.io.ClassPathResource | ||
| import org.springframework.core.io.Resource | ||
| import org.springframework.stereotype.Component | ||
|
|
||
| import javax.transaction.Transactional | ||
|
|
||
| @Component | ||
| @Slf4j | ||
| class ShibPropertiesBootstrap { | ||
| @Autowired | ||
| private ShibConfigurationService service | ||
|
|
||
| ShibPropertiesBootstrap(ShibConfigurationService service) { | ||
| this.service = service | ||
| } | ||
|
|
||
| @Transactional | ||
| @EventListener | ||
| void bootstrapUsersAndRoles(ApplicationStartedEvent e) { | ||
| log.info("Ensuring base Shibboleth properties configuration has loaded") | ||
|
|
||
| Resource resource = new ClassPathResource('shib_configuration_prop.csv') | ||
| final HashMap<String, ShibConfigurationProperty> propertiesMap = new HashMap<>() | ||
|
|
||
| // Read in the defaults in the configuration file | ||
| new CSVReader(new InputStreamReader(resource.inputStream)).each { fields -> | ||
| def (resource_id,category,config_file,description,idp_version,module,module_version,note,default_value,property_name,property_type,selection_items,property_value) = fields | ||
| ShibConfigurationProperty prop = new ShibConfigurationProperty().with { | ||
| it.resourceId = resource_id | ||
| it.category = category | ||
| it.configFile = config_file | ||
| it.description = description | ||
| it.idpVersion = idp_version | ||
| it.module = module | ||
| it.moduleVersion = module_version | ||
| it.note = note | ||
| it.defaultValue = default_value | ||
| it.description = description | ||
| it.propertyName = property_name | ||
| def pt = property_type | ||
| it.setPropertyType(pt) | ||
| it.selectionItems = selection_items | ||
| // we shouldn't have property values coming in from the config... | ||
| it | ||
| } | ||
| propertiesMap.put(prop.getPropertyName(), prop) | ||
| } | ||
|
|
||
| // If we already have the property in the db, ignore the configuration setup for that property | ||
| service.getExistingPropertyNames().each { | ||
| propertiesMap.remove(it) | ||
| } | ||
|
|
||
| // Save anything that's left | ||
| if (propertiesMap.size() > 0) { | ||
| log.info("Saving/loading [" + propertiesMap.size() + "] properties to the database") | ||
| service.addAll(propertiesMap.values()) | ||
| } | ||
|
|
||
| log.info("COMPLETED: ensuring base Shibboleth properties configuration has loaded") | ||
| } | ||
| } |
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
25 changes: 25 additions & 0 deletions
25
...main/java/edu/internet2/tier/shibboleth/admin/ui/controller/ShibPropertiesController.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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.controller; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.service.ShibConfigurationService; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import io.swagger.v3.oas.annotations.tags.Tags; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping(value = "/api/shib") | ||
| @Tags(value = {@Tag(name = "Shibboleth Properties")}) | ||
| public class ShibPropertiesController { | ||
| @Autowired | ||
| private ShibConfigurationService service; | ||
|
|
||
| @GetMapping("/properties") | ||
| @Transactional(readOnly = true) | ||
| public ResponseEntity<?> getAll() { | ||
| return ResponseEntity.ok(service.getAll()); | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
...rc/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/ShibConfigurationProperty.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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.domain; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import edu.internet2.tier.shibboleth.admin.util.EmptyStringToNullConverter; | ||
| import lombok.Data; | ||
| import org.hibernate.envers.Audited; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Convert; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.Id; | ||
| import java.util.UUID; | ||
|
|
||
| @Entity(name = "shib_configuration_prop") | ||
| @Audited | ||
| @Data | ||
| public class ShibConfigurationProperty { | ||
| @Id | ||
| @Column(name = "resource_id", nullable = false) | ||
| String resourceId = UUID.randomUUID().toString(); | ||
|
|
||
| @Column(name = "category", nullable = false) | ||
| String category; | ||
|
|
||
| @Column(name = "config_file", nullable = false) | ||
| String configFile; | ||
|
|
||
| @Column(name = "default_value") | ||
| @Convert(converter = EmptyStringToNullConverter.class) | ||
| String defaultValue; | ||
|
|
||
| @Column(name = "description") | ||
| @Convert(converter = EmptyStringToNullConverter.class) | ||
| String description; | ||
|
|
||
| @Column(name = "idp_version", nullable = false) | ||
| String idpVersion; | ||
|
|
||
| @Column(name = "module") | ||
| @Convert(converter = EmptyStringToNullConverter.class) | ||
| String module; | ||
|
|
||
| @Column(name = "module_version") | ||
| @Convert(converter = EmptyStringToNullConverter.class) | ||
| String moduleVersion; | ||
|
|
||
| @Column(name = "note") | ||
| @Convert(converter = EmptyStringToNullConverter.class) | ||
| String note; | ||
|
|
||
| @Column(name = "property_name", nullable = false) | ||
| String propertyName; | ||
|
|
||
| @Column(name = "property_type", nullable = false) | ||
| @JsonIgnore // display type is sent to the ui instead | ||
| PropertyType propertyType; | ||
|
|
||
| @Column(name = "selection_items") | ||
| @Convert(converter = EmptyStringToNullConverter.class) | ||
| String selectionItems; | ||
|
|
||
| public String getDisplayType() { | ||
| switch (propertyType) { | ||
| case BOOLEAN: | ||
| return propertyType.name().toLowerCase(); | ||
| case INTEGER: | ||
| return "number"; | ||
| case SELECTION_LIST: | ||
| return "list"; | ||
| default: // DURATION, SPRING_BEAN_ID, STRING | ||
| return "string"; | ||
| } | ||
| } | ||
|
|
||
| public void setPropertyType(String val) { | ||
| this.propertyType = PropertyType.valueOf(val); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| enum PropertyType { | ||
| BOOLEAN, DURATION, INTEGER, SELECTION_LIST, SPRING_BEAN_ID, STRING | ||
| } |
15 changes: 15 additions & 0 deletions
15
...n/java/edu/internet2/tier/shibboleth/admin/ui/repository/ShibConfigurationRepository.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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.repository; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.domain.ShibConfigurationProperty; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Repository to manage {@link ShibConfigurationProperty} instances. | ||
| */ | ||
| public interface ShibConfigurationRepository extends JpaRepository<ShibConfigurationProperty, String> { | ||
| @Query(value = "select property_name from shib_configuration_prop", nativeQuery = true) | ||
| List<String> getPropertyNames(); | ||
| } |
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
16 changes: 16 additions & 0 deletions
16
...rc/main/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationService.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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.domain.ShibConfigurationProperty; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| public interface ShibConfigurationService { | ||
| void addAll(Collection<ShibConfigurationProperty> newProperties); | ||
|
|
||
| List<String> getExistingPropertyNames(); | ||
|
|
||
| void save(ShibConfigurationProperty prop); | ||
|
|
||
| List<ShibConfigurationProperty> getAll(); | ||
| } |
35 changes: 35 additions & 0 deletions
35
...ain/java/edu/internet2/tier/shibboleth/admin/ui/service/ShibConfigurationServiceImpl.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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.domain.ShibConfigurationProperty; | ||
| import edu.internet2.tier.shibboleth.admin.ui.repository.ShibConfigurationRepository; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| public class ShibConfigurationServiceImpl implements ShibConfigurationService { | ||
| @Autowired | ||
| private ShibConfigurationRepository repository; | ||
|
|
||
| @Override | ||
| public void addAll(Collection<ShibConfigurationProperty> newProperties) { | ||
| repository.saveAll(newProperties); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getExistingPropertyNames() { | ||
| return repository.getPropertyNames(); | ||
| } | ||
|
|
||
| @Override | ||
| public void save(ShibConfigurationProperty prop) { | ||
| repository.save(prop); | ||
| } | ||
|
|
||
| @Override | ||
| public List<ShibConfigurationProperty> getAll() { | ||
| return repository.findAll(); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...nd/src/main/java/edu/internet2/tier/shibboleth/admin/util/EmptyStringToNullConverter.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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package edu.internet2.tier.shibboleth.admin.util; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import javax.persistence.AttributeConverter; | ||
| import javax.persistence.Converter; | ||
|
|
||
| @Converter | ||
| public class EmptyStringToNullConverter implements AttributeConverter<String, String> { | ||
| @Override | ||
| public String convertToDatabaseColumn(String string) { | ||
| // if whitespace is set on a value, send null to the db | ||
| return StringUtils.defaultIfBlank(string, null); | ||
| } | ||
|
|
||
| @Override | ||
| public String convertToEntityAttribute(String dbData) { | ||
| // keep nulls from the db as nulls | ||
| return dbData; | ||
| } | ||
| } |
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.