Skip to content

Commit

Permalink
[SHIBUI-701]
Browse files Browse the repository at this point in the history
Adding support for provider schemas. Added new controller. This is a WIP.
  • Loading branch information
Bill Smith committed Nov 7, 2018
1 parent 8223c52 commit b46699d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package edu.internet2.tier.shibboleth.admin.ui.controller

import com.fasterxml.jackson.databind.ObjectMapper
import edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation
import edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocationRegistry
import edu.internet2.tier.shibboleth.admin.ui.service.JsonSchemaBuilderService
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.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

import javax.annotation.PostConstruct

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.dynamicHttpMetadataProviderSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.filesystemMetadataProviderSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.localDynamicMetadataProviderSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.metadataSourcesSchema
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType

/**
* 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
@RequestMapping('/api/ui/MetadataProvider')
class MetadataProviderUiDefinitionController {

@Autowired
JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry

JsonSchemaResourceLocation jsonSchemaLocation

@Autowired
ObjectMapper jacksonObjectMapper

@GetMapping(value = "/{providerType}")
ResponseEntity<?> getUiDefinitionJsonSchema(@PathVariable String providerType) {
switch (JsonSchemaResourceLocation.SchemaType.valueOf(providerType)) {
case SchemaType.LOCAL_DYNAMIC_METADATA_PROVIDER:
jsonSchemaLocation = localDynamicMetadataProviderSchema(this.jsonSchemaResourceLocationRegistry)
break
case SchemaType.FILESYSTEM_METADATA_PROVIDER:
jsonSchemaLocation = filesystemMetadataProviderSchema(this.jsonSchemaResourceLocationRegistry)
break
case SchemaType.DYNAMIC_HTTP_METADATA_PROVIDER:
jsonSchemaLocation = dynamicHttpMetadataProviderSchema(this.jsonSchemaResourceLocationRegistry)
break
default:
throw new UnsupportedOperationException("Json schema for an unsupported metadata provider (" + providerType + ") was requested")
}
try {
def parsedJson = jacksonObjectMapper.readValue(this.jsonSchemaLocation.url, Map)
return ResponseEntity.ok(parsedJson)
}
catch (Exception e) {
e.printStackTrace()
return ResponseEntity.status(INTERNAL_SERVER_ERROR)
.body([jsonParseError : e.getMessage(),
sourceUiSchemaDefinitionFile: this.jsonSchemaLocation.url])
}
}

@PostConstruct
void init() {
this.jsonSchemaLocation = metadataSourcesSchema(this.jsonSchemaResourceLocationRegistry)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.*;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.ENTITY_ATTRIBUTES_FILTERS;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.FILESYSTEM_METADATA_PROVIDER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES;

/**
Expand All @@ -30,6 +31,9 @@ public class JsonSchemaComponentsConfiguration {
@Setter
private String entityAttributesFiltersUiSchemaLocation = "classpath:entity-attributes-filters-ui-schema.json";

@Setter
private String filesystemMetadtaProviderUiSchemaLocation = "classpath:file-system-metadata-provider.schema.json";

@Bean
public JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry(ResourceLoader resourceLoader, ObjectMapper jacksonMapper) {
return JsonSchemaResourceLocationRegistry.inMemory()
Expand All @@ -44,6 +48,12 @@ public JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry(Res
.resourceLoader(resourceLoader)
.jacksonMapper(jacksonMapper)
.detectMalformedJson(true)
.build())
.register(FILESYSTEM_METADATA_PROVIDER, JsonSchemaLocationBuilder.with()
.jsonSchemaLocation(filesystemMetadtaProviderUiSchemaLocation)
.resourceLoader(resourceLoader)
.jacksonMapper(jacksonMapper)
.detectMalformedJson(true)
.build());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.ENTITY_ATTRIBUTES_FILTERS;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.METADATA_SOURCES;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.FILESYSTEM_METADATA_PROVIDER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.LOCAL_DYNAMIC_METADATA_PROVIDER;
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaResourceLocation.SchemaType.DYNAMIC_HTTP_METADATA_PROVIDER;

/**
* Utility methods for common JSON schema types lookups.
Expand Down Expand Up @@ -35,4 +38,22 @@ public static JsonSchemaResourceLocation entityAttributesFiltersSchema(JsonSchem
.lookup(ENTITY_ATTRIBUTES_FILTERS)
.orElseThrow(() -> new IllegalStateException("JSON schema resource location for metadata sources is not registered."));
}

public static JsonSchemaResourceLocation filesystemMetadataProviderSchema(JsonSchemaResourceLocationRegistry resourceLocationRegistry) {
return resourceLocationRegistry
.lookup(FILESYSTEM_METADATA_PROVIDER)
.orElseThrow(() -> new IllegalStateException("JSON schema resource location for metadata sources is not registered."));
}

public static JsonSchemaResourceLocation localDynamicMetadataProviderSchema(JsonSchemaResourceLocationRegistry resourceLocationRegistry) {
return resourceLocationRegistry
.lookup(LOCAL_DYNAMIC_METADATA_PROVIDER)
.orElseThrow(() -> new IllegalStateException("JSON schema resource location for metadata sources is not registered."));
}

public static JsonSchemaResourceLocation dynamicHttpMetadataProviderSchema(JsonSchemaResourceLocationRegistry resourceLocationRegistry) {
return resourceLocationRegistry
.lookup(DYNAMIC_HTTP_METADATA_PROVIDER)
.orElseThrow(() -> new IllegalStateException("JSON schema resource location for metadata sources is not registered."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static JsonSchemaResourceLocation newSchemaLocation(String jsonSchemaLoca
}

public enum SchemaType {
METADATA_SOURCES, ENTITY_ATTRIBUTES_FILTERS
METADATA_SOURCES, ENTITY_ATTRIBUTES_FILTERS,
FILESYSTEM_METADATA_PROVIDER, LOCAL_DYNAMIC_METADATA_PROVIDER, DYNAMIC_HTTP_METADATA_PROVIDER
}
}

0 comments on commit b46699d

Please sign in to comment.