-
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 SHIBUI-905 (pull request #212)
SHIBUI-905 Approved-by: Ryan Mathis <rmathis@unicon.net>
- Loading branch information
Showing
204 changed files
with
5,423 additions
and
5,031 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...nternet2/tier/shibboleth/admin/ui/controller/MetadataSourcesUiDefinitionController.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,53 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.controller | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import edu.internet2.tier.shibboleth.admin.ui.configuration.CustomAttributesConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.jsonschema.MetadataSourcesJsonSchemaResourceLocation | ||
import org.springframework.beans.factory.BeanInitializationException | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.core.io.ResourceLoader | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
import javax.annotation.PostConstruct | ||
|
||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR | ||
|
||
/** | ||
* Controller implementing REST resource responsible for exposing structure definition for metadata sources user | ||
* interface in terms of JSON schema. | ||
* | ||
* @author Dmitriy Kopylenko | ||
* @author Bill Smith (wsmith@unicon.net) | ||
*/ | ||
@RestController('/api/ui/MetadataSources') | ||
class MetadataSourcesUiDefinitionController { | ||
|
||
@Autowired | ||
MetadataSourcesJsonSchemaResourceLocation jsonSchemaLocation | ||
|
||
@Autowired | ||
ObjectMapper jacksonObjectMapper | ||
|
||
@Autowired | ||
CustomAttributesConfiguration customAttributesConfiguration | ||
|
||
@GetMapping | ||
ResponseEntity<?> getUiDefinitionJsonSchema() { | ||
try { | ||
def parsedJson = jacksonObjectMapper.readValue(this.jsonSchemaLocation.url, Map) | ||
parsedJson['properties']['attributeRelease']['widget']['data'] = | ||
customAttributesConfiguration.getAttributes().collect { | ||
[key: it['name'], label: it['displayName']] | ||
} | ||
return ResponseEntity.ok(parsedJson) | ||
} | ||
catch (Exception e) { | ||
return ResponseEntity.status(INTERNAL_SERVER_ERROR) | ||
.body([jsonParseError : e.getMessage(), | ||
sourceUiSchemaDefinitionFile: this.jsonSchemaLocation.url]) | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...2/tier/shibboleth/admin/ui/configuration/JsonSchemaValidationComponentsConfiguration.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,30 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.configuration; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import edu.internet2.tier.shibboleth.admin.ui.jsonschema.MetadataSourcesJsonSchemaResourceLocation; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ResourceLoader; | ||
|
||
/** | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
@Configuration | ||
@ConfigurationProperties("shibui") | ||
public class JsonSchemaValidationComponentsConfiguration { | ||
|
||
//Configured via @ConfigurationProperties (using setter method) with 'shibui.metadata-sources-ui-schema-location' property and default | ||
//value set here if that property is not explicitly set in application.properties | ||
private String metadataSourcesUiSchemaLocation ="classpath:metadata-sources-ui-schema.json"; | ||
|
||
//This setter is used by Boot's @ConfiguratonProperties binding machinery | ||
public void setMetadataSourcesUiSchemaLocation(String metadataSourcesUiSchemaLocation) { | ||
this.metadataSourcesUiSchemaLocation = metadataSourcesUiSchemaLocation; | ||
} | ||
|
||
@Bean | ||
public MetadataSourcesJsonSchemaResourceLocation metadataSourcesJsonSchemaResourceLocation(ResourceLoader resourceLoader, ObjectMapper jacksonMapper) { | ||
return new MetadataSourcesJsonSchemaResourceLocation(metadataSourcesUiSchemaLocation, resourceLoader, jacksonMapper); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...ernet2/tier/shibboleth/admin/ui/jsonschema/MetadataSourcesJsonSchemaResourceLocation.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,77 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.jsonschema; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.beans.factory.BeanInitializationException; | ||
import org.springframework.core.io.ResourceLoader; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
/** | ||
* Encapsulates metadata sources JSON schema location. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
public class MetadataSourcesJsonSchemaResourceLocation { | ||
|
||
private final String metadataSourcesUiSchemaLocation; | ||
|
||
private URL jsonSchemaUrl; | ||
|
||
private final ResourceLoader resourceLoader; | ||
|
||
private final ObjectMapper jacksonMapper; | ||
|
||
private boolean detectMalformedJsonDuringInit = true; | ||
|
||
public MetadataSourcesJsonSchemaResourceLocation(String metadataSourcesUiSchemaLocation, ResourceLoader resourceLoader, ObjectMapper jacksonMapper) { | ||
this.metadataSourcesUiSchemaLocation = metadataSourcesUiSchemaLocation; | ||
this.resourceLoader = resourceLoader; | ||
this.jacksonMapper = jacksonMapper; | ||
} | ||
|
||
//This constructor is used in tests | ||
public MetadataSourcesJsonSchemaResourceLocation(String metadataSourcesUiSchemaLocation, | ||
ResourceLoader resourceLoader, | ||
ObjectMapper jacksonMapper, | ||
boolean detectMalformedJsonDuringInit) { | ||
this.metadataSourcesUiSchemaLocation = metadataSourcesUiSchemaLocation; | ||
this.resourceLoader = resourceLoader; | ||
this.jacksonMapper = jacksonMapper; | ||
this.detectMalformedJsonDuringInit = detectMalformedJsonDuringInit; | ||
} | ||
|
||
public URL getUrl() { | ||
return this.jsonSchemaUrl; | ||
} | ||
|
||
public URI getUri() { | ||
try { | ||
return this.jsonSchemaUrl.toURI(); | ||
} | ||
catch (URISyntaxException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
try { | ||
this.jsonSchemaUrl = this.resourceLoader.getResource(this.metadataSourcesUiSchemaLocation).getURL(); | ||
if(this.detectMalformedJsonDuringInit) { | ||
//Detect malformed JSON schema early, during application start up and fail fast with useful exception message | ||
this.jacksonMapper.readValue(this.jsonSchemaUrl, Map.class); | ||
} | ||
} | ||
catch (Exception ex) { | ||
StringBuilder msg = | ||
new StringBuilder(String.format("An error is detected during JSON parsing => [%s]", ex.getMessage())); | ||
msg.append(String.format("Offending resource => [%s]", this.metadataSourcesUiSchemaLocation)); | ||
|
||
throw new BeanInitializationException(msg.toString(), ex); | ||
} | ||
} | ||
} |
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.