Skip to content

Commit

Permalink
SHIBUI-2380
Browse files Browse the repository at this point in the history
Incremental commit:
- added ability to get metadata schema by type (oidc | saml)
- unit tests and code corrections
  • Loading branch information
chasegawa committed Sep 23, 2022
1 parent 361a34d commit 2369e03
Show file tree
Hide file tree
Showing 11 changed files with 1,127 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

import javax.annotation.PostConstruct

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.metadataSourcesSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.metadataSourcesOIDCSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.metadataSourcesSAMLSchema
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR

/**
Expand All @@ -30,13 +32,13 @@ import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
@RequestMapping('/api/ui/MetadataSources')
@Tags(value = [@Tag(name = "ui")])
class MetadataSourcesUiDefinitionController {

private static final Logger logger = LoggerFactory.getLogger(MetadataSourcesUiDefinitionController.class);
private static final Logger log = LoggerFactory.getLogger(MetadataSourcesUiDefinitionController.class);

@Autowired
JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry

JsonSchemaResourceLocation jsonSchemaLocation
private JsonSchemaResourceLocation oidcJsonSchemaLocation
private JsonSchemaResourceLocation samlJsonSchemaLocation

@Autowired
ObjectMapper jacksonObjectMapper
Expand All @@ -45,26 +47,25 @@ class MetadataSourcesUiDefinitionController {
JsonSchemaBuilderService jsonSchemaBuilderService

@GetMapping
// TODO - CHARLES add type ( SAML|OIDC ) variable to return the correct one - default to saml...
ResponseEntity<?> getUiDefinitionJsonSchema() {
ResponseEntity<?> getUiDefinitionJsonSchema(@RequestParam(defaultValue = "saml") String protocol) {
URL url = protocol.equals("oidc") ? oidcJsonSchemaLocation.url : samlJsonSchemaLocation.url
try {
def parsedJson = jacksonObjectMapper.readValue(this.jsonSchemaLocation.url, Map)
def parsedJson = jacksonObjectMapper.readValue(url, Map)
jsonSchemaBuilderService.hideServiceEnabledFromNonAdmins(parsedJson)
jsonSchemaBuilderService.addReleaseAttributesToJson(parsedJson['properties']['attributeRelease']['items'])
jsonSchemaBuilderService.addRelyingPartyOverridesToJson(parsedJson['properties']['relyingPartyOverrides'])
jsonSchemaBuilderService.addRelyingPartyOverridesCollectionDefinitionsToJson(parsedJson["definitions"])
return ResponseEntity.ok(parsedJson)
}
catch (IOException e) {
logger.error("An error occurred while attempting to get json schema for metadata sources!", e)
return ResponseEntity.status(INTERNAL_SERVER_ERROR)
.body([jsonParseError : e.getMessage(),
sourceUiSchemaDefinitionFile: this.jsonSchemaLocation.url])
log.error("An error occurred while attempting to get json schema for metadata sources!", e)
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body([jsonParseError : e.getMessage(), sourceUiSchemaDefinitionFile: this.samlJsonSchemaLocation.url])
}
}

@PostConstruct
void init() {
this.jsonSchemaLocation = metadataSourcesSchema(this.jsonSchemaResourceLocationRegistry);
this.samlJsonSchemaLocation = metadataSourcesSAMLSchema(this.jsonSchemaResourceLocationRegistry);
this.oidcJsonSchemaLocation = metadataSourcesOIDCSchema(this.jsonSchemaResourceLocationRegistry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAd
import javax.annotation.PostConstruct
import java.lang.reflect.Type

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.metadataSourcesSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.metadataSourcesSAMLSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.LowLevelJsonSchemaValidator.validatePayloadAgainstSchema

/**
Expand Down Expand Up @@ -44,6 +44,6 @@ class EntityDescriptorSchemaValidatingControllerAdvice extends RequestBodyAdvice

@PostConstruct
void init() {
this.jsonSchemaLocation = metadataSourcesSchema(this.jsonSchemaResourceLocationRegistry)
this.jsonSchemaLocation = metadataSourcesSAMLSchema(this.jsonSchemaResourceLocationRegistry)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.EXTERNAL_METADATA_RESOLVER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.FILESYSTEM_METADATA_RESOLVER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.LOCAL_DYNAMIC_METADATA_RESOLVER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES_OIDC;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES_SAML;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.NAME_ID_FORMAT_FILTER;

/**
Expand All @@ -27,10 +28,15 @@
@ConfigurationProperties("shibui")
public class JsonSchemaComponentsConfiguration {

//Configured via @ConfigurationProperties (using setter method) with 'shibui.metadata-sources-oidc-ui-schema-location' property and default
//value set here if that property is not explicitly set in application.properties
@Setter
private String metadataSourcesOidcUiSchemaLocation = "classpath:metadata-sources-ui-schema-oidc.json";

//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
@Setter
private String metadataSourcesUiSchemaLocation = "classpath:metadata-sources-ui-schema.json";
private String metadataSourcesSamlUiSchemaLocation = "classpath:metadata-sources-ui-schema-saml.json";

//Configured via @ConfigurationProperties (using setter method) with 'shibui.entity-attributes-filters-ui-schema-location' property and
// default value set here if that property is not explicitly set in application.properties
Expand Down Expand Up @@ -70,8 +76,14 @@ public class JsonSchemaComponentsConfiguration {
@Bean
public JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry(ResourceLoader resourceLoader, ObjectMapper jacksonMapper) {
return JsonSchemaResourceLocationRegistry.inMemory()
.register(METADATA_SOURCES, JsonSchemaLocationBuilder.with()
.jsonSchemaLocation(metadataSourcesUiSchemaLocation)
.register(METADATA_SOURCES_OIDC, JsonSchemaLocationBuilder.with()
.jsonSchemaLocation(metadataSourcesOidcUiSchemaLocation)
.resourceLoader(resourceLoader)
.jacksonMapper(jacksonMapper)
.detectMalformedJson(true)
.build())
.register(METADATA_SOURCES_SAML, JsonSchemaLocationBuilder.with()
.jsonSchemaLocation(metadataSourcesSamlUiSchemaLocation)
.resourceLoader(resourceLoader)
.jacksonMapper(jacksonMapper)
.detectMalformedJson(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.EXTERNAL_METADATA_RESOLVER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.FILESYSTEM_METADATA_RESOLVER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.LOCAL_DYNAMIC_METADATA_RESOLVER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES_OIDC;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES_SAML;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.NAME_ID_FORMAT_FILTER;

/**
Expand All @@ -23,9 +24,22 @@ public abstract class JsonSchemaLocationLookup {
* @return metadata sources JSON schema resource location object
* @throws IllegalStateException if schema is not found in the given registry
*/
public static JsonSchemaResourceLocation metadataSourcesSchema(JsonSchemaResourceLocationRegistry resourceLocationRegistry) {
public static JsonSchemaResourceLocation metadataSourcesOIDCSchema(JsonSchemaResourceLocationRegistry resourceLocationRegistry) {
return resourceLocationRegistry
.lookup(METADATA_SOURCES)
.lookup(METADATA_SOURCES_OIDC)
.orElseThrow(() -> new IllegalStateException("JSON schema resource location for metadata sources is not registered."));
}

/**
* Searches metadata sources JSON schema resource location object in the given location registry.
*
* @param resourceLocationRegistry
* @return metadata sources JSON schema resource location object
* @throws IllegalStateException if schema is not found in the given registry
*/
public static JsonSchemaResourceLocation metadataSourcesSAMLSchema(JsonSchemaResourceLocationRegistry resourceLocationRegistry) {
return resourceLocationRegistry
.lookup(METADATA_SOURCES_SAML)
.orElseThrow(() -> new IllegalStateException("JSON schema resource location for metadata sources is not registered."));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public static JsonSchemaResourceLocation newSchemaLocation(String jsonSchemaLoca

public enum SchemaType {
// common types
METADATA_SOURCES("MetadataSources"),
METADATA_SOURCES_SAML("MetadataSourcesSAML"),
METADATA_SOURCES_OIDC("MetadataSourcesOIDC"),

// filter types
ENTITY_ATTRIBUTES_FILTERS("EntityAttributesFilters"),
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ shibui.logout-url=/dashboard
#shibui.default-password={noop}somepassword
shibui.default-rootuser=root

shibui.metadata-sources-ui-schema-location=classpath:metadata-sources-ui-schema.json
shibui.metadata-sources-saml-ui-schema-location=classpath:metadata-sources-ui-schema-saml.json
shibui.metadata-sources-oidc-ui-schema-location=classpath:metadata-sources-ui-schema-oidc.json
shibui.entity-attributes-filters-ui-schema-location=classpath:entity-attributes-filters-ui-schema.json
shibui.nameid-filter-ui-schema-location=classpath:nameid-filter.schema.json

Expand Down
Loading

0 comments on commit 2369e03

Please sign in to comment.