Skip to content

Commit

Permalink
Merge branch 'master' into feature/SHIBUI-1364-QA
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Smith committed Sep 26, 2019
2 parents 20a0534 + 7e9638c commit 80ca193
Show file tree
Hide file tree
Showing 31 changed files with 1,427 additions and 170 deletions.
9 changes: 1 addition & 8 deletions backend/src/integration/resources/SHIBUI-1392.side
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,13 @@
["xpath=//p", "xpath:position"]
],
"value": ""
}, {
"id": "84be6a98-5739-42e8-b7ca-06a6c86e9f40",
"comment": "",
"command": "editContent",
"target": "id=/nameIdFormatFilterTarget.target",
"targets": [],
"value": "(true);"
}, {
"id": "05870356-d3db-4540-bb3f-db34b1cf65f1",
"comment": "",
"command": "sendKeys",
"target": "id=/nameIdFormatFilterTarget.target",
"targets": [],
"value": "eval"
"value": "eval(true);"
}, {
"id": "d7721254-68c9-4140-af2a-1757cce99da7",
"comment": "",
Expand Down
7 changes: 7 additions & 0 deletions backend/src/integration/resources/SHIBUI-1407-1.side
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,13 @@
"target": "5000",
"targets": [],
"value": ""
}, {
"id": "c2fcb197-7e0d-4b64-82a5-ad24cf24126b",
"comment": "",
"command": "waitForElementEditable",
"target": "id=/serviceProviderName",
"targets": [],
"value": "30000"
}, {
"id": "99731068-2016-4a7f-8a38-febfb711d027",
"comment": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package edu.internet2.tier.shibboleth.admin.ui.jsonschema


import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation
import mjson.Json
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.MethodParameter
import org.springframework.http.HttpInputMessage
Expand All @@ -14,6 +13,7 @@ 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.LowLevelJsonSchemaValidator.validatePayloadAgainstSchema

/**
* Controller advice implementation for validating relying party overrides payload coming from UI layer
Expand All @@ -22,7 +22,7 @@ import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocati
* @author Dmitriy Kopylenko
*/
@ControllerAdvice
class RelyingPartyOverridesJsonSchemaValidatingControllerAdvice extends RequestBodyAdviceAdapter {
class EntityDescriptorSchemaValidatingControllerAdvice extends RequestBodyAdviceAdapter {

@Autowired
JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry
Expand All @@ -38,22 +38,12 @@ class RelyingPartyOverridesJsonSchemaValidatingControllerAdvice extends RequestB
HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
throws IOException {
def bytes = inputMessage.body.bytes
def schema = Json.schema(this.jsonSchemaLocation.uri)

def stream = new ByteArrayInputStream(bytes)
def validationResult = schema.validate(Json.read(stream.getText()))
if (!validationResult.at('ok')) {
throw new JsonSchemaValidationFailedException(validationResult.at('errors').asList())
}
return [
getBody: { new ByteArrayInputStream(bytes) },
getHeaders: { inputMessage.headers }
] as HttpInputMessage

return validatePayloadAgainstSchema(inputMessage, this.jsonSchemaLocation.uri)
}

@PostConstruct
void init() {
this.jsonSchemaLocation = metadataSourcesSchema(this.jsonSchemaResourceLocationRegistry);
this.jsonSchemaLocation = metadataSourcesSchema(this.jsonSchemaResourceLocationRegistry)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package edu.internet2.tier.shibboleth.admin.ui.jsonschema

import mjson.Json
import org.springframework.http.HttpInputMessage

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.dynamicHttpMetadataProviderSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.entityAttributesFiltersSchema
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.nameIdFormatFilterSchema

/**
* Currently uses mjson library.
*
* @author Dmitriy Kopylenko
*/
class LowLevelJsonSchemaValidator {

static HttpInputMessage validatePayloadAgainstSchema(HttpInputMessage inputMessage, URI schemaUri) {
def origInput = [inputMessage.body.bytes, inputMessage.headers]
def json = extractJsonPayload(origInput)
def schema = Json.schema(schemaUri)
doValidate(origInput, schema, json)
}

static HttpInputMessage validateMetadataResolverTypePayloadAgainstSchema(HttpInputMessage inputMessage,
JsonSchemaResourceLocationRegistry schemaRegistry) {

def origInput = [inputMessage.body.bytes, inputMessage.headers]
def json = extractJsonPayload(origInput)
def schemaUri = null
switch (json.asMap()['@type']) {
case 'LocalDynamicMetadataResolver':
schemaUri = localDynamicMetadataProviderSchema(schemaRegistry).uri
break
case 'DynamicHttpMetadataResolver':
schemaUri = dynamicHttpMetadataProviderSchema(schemaRegistry).uri
break
case 'FilesystemMetadataResolver':
schemaUri = filesystemMetadataProviderSchema(schemaRegistry).uri
break
default:
break
}
if (!schemaUri) {
return newInputMessage(origInput)
}
doValidate(origInput, Json.schema(schemaUri), json)
}

static HttpInputMessage validateMetadataFilterTypePayloadAgainstSchema(HttpInputMessage inputMessage,
JsonSchemaResourceLocationRegistry schemaRegistry) {
def origInput = [inputMessage.body.bytes, inputMessage.headers]
def json = extractJsonPayload(origInput)
def schemaUri = null
switch (json.asMap()['@type']) {
case 'EntityAttributes':
schemaUri = entityAttributesFiltersSchema(schemaRegistry).uri
break
case 'NameIDFormat':
schemaUri = nameIdFormatFilterSchema(schemaRegistry).uri
break
default:
break
}
if (!schemaUri) {
return newInputMessage(origInput)
}
doValidate(origInput, Json.schema(schemaUri), json)
}

private static Json extractJsonPayload(List origInput) {
Json.read(new ByteArrayInputStream(origInput[0]).getText())
}

private static HttpInputMessage doValidate(List origInput, Json.Schema schema, Json json) {
def validationResult = schema.validate(json)
if (!validationResult.at('ok')) {
throw new JsonSchemaValidationFailedException(validationResult.at('errors').asList())
}
newInputMessage(origInput)
}

private static newInputMessage(origInput) {
[
getBody : { new ByteArrayInputStream(origInput[0]) },
getHeaders: { origInput[1] }
] as HttpInputMessage
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package edu.internet2.tier.shibboleth.admin.ui.jsonschema

import edu.internet2.tier.shibboleth.admin.ui.domain.filters.MetadataFilter
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.MethodParameter
import org.springframework.http.HttpInputMessage
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter

import java.lang.reflect.Type

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.LowLevelJsonSchemaValidator.validateMetadataFilterTypePayloadAgainstSchema

/**
* Controller advice implementation for validating metadata filters payload coming from UI layer
* against pre-defined JSON schema for their respected types. Choosing of the appropriate schema based on incoming
* resolver types is delegated to @{LowLevelJsonSchemaValidator}.
*
* @author Dmitriy Kopylenko
*/
@ControllerAdvice
class MetadataFiltersSchemaValidatingControllerAdvice extends RequestBodyAdviceAdapter {

@Autowired
JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry

@Override
boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
targetType.typeName == MetadataFilter.typeName
}

@Override
HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
throws IOException {

validateMetadataFilterTypePayloadAgainstSchema(inputMessage, jsonSchemaResourceLocationRegistry)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package edu.internet2.tier.shibboleth.admin.ui.jsonschema


import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolver
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.MethodParameter
import org.springframework.http.HttpInputMessage
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter

import java.lang.reflect.Type

import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.LowLevelJsonSchemaValidator.validateMetadataResolverTypePayloadAgainstSchema

/**
* Controller advice implementation for validating metadata resolvers payload coming from UI layer
* against pre-defined JSON schema for their respected types. Choosing of the appropriate schema based on incoming
* resolver types is delegated to @{LowLevelJsonSchemaValidator}.
*
* @author Dmitriy Kopylenko
*/
@ControllerAdvice
class MetadataResolversSchemaValidatingControllerAdvice extends RequestBodyAdviceAdapter {

@Autowired
JsonSchemaResourceLocationRegistry jsonSchemaResourceLocationRegistry

@Override
boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
targetType.typeName == MetadataResolver.typeName
}

@Override
HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
throws IOException {

validateMetadataResolverTypePayloadAgainstSchema(inputMessage, jsonSchemaResourceLocationRegistry)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DynamicMetadataResolverAttributes {

private String taskTimerRef;

private Double refreshDelayFactor = 0.75;
private Float refreshDelayFactor = 0.75F;

private String minCacheDuration = "PT10M";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void updateOpenSamlMetadataResolverFromDynamicMetadataResolverAttr
}

if (attributes.getRefreshDelayFactor() != null) {
dynamicMetadataResolver.setRefreshDelayFactor(attributes.getRefreshDelayFactor().floatValue());
dynamicMetadataResolver.setRefreshDelayFactor(attributes.getRefreshDelayFactor());
}

if (attributes.getRemoveIdleEntityData() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"name",
"@type",
"xmlId",
"metadataURL",
"metadataRequestURLConstructionScheme"
],
"properties": {
Expand Down Expand Up @@ -147,14 +146,15 @@
"refreshDelayFactor": {
"title": "label.refresh-delay-factor",
"description": "tooltip.refresh-delay-factor",
"type": "string",
"type": "number",
"widget": {
"id": "string",
"help": "message.real-number"
"id": "float",
"help": "message.real-number",
"step": 0.01
},
"placeholder": "label.real-number",
"default": "",
"pattern": "^(?:([0]*(\\.[0-9]+)?|[0]*\\.[0-9]*[1-9][0-9]*)|)$"
"minimum": 0.001,
"maximum": 0.999
},
"minCacheDuration": {
"title": "label.min-cache-duration",
Expand Down Expand Up @@ -576,11 +576,14 @@
}
},
"metadataFilters": {
"$id": "metadataFilters",
"title": "",
"description": "",
"type": "object",
"properties": {
"RequiredValidUntil": {
"type": "array",
"additionalItems": true,
"items": [
{
"$id": "RequiredValidUntil",
"title": "label.required-valid-until",
"type": "object",
"widget": {
Expand Down Expand Up @@ -611,7 +614,8 @@
}
}
},
"SignatureValidation": {
{
"$id": "SignatureValidation",
"title": "label.signature-validation-filter",
"type": "object",
"widget": {
Expand Down Expand Up @@ -654,7 +658,8 @@
}
]
},
"EntityRoleWhiteList": {
{
"$id": "EntityRoleWhiteList",
"title": "label.entity-role-whitelist",
"type": "object",
"widget": {
Expand Down Expand Up @@ -700,7 +705,7 @@
}
}
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@
"refreshDelayFactor": {
"title": "label.refresh-delay-factor",
"description": "tooltip.refresh-delay-factor",
"type": "string",
"type": "number",
"widget": {
"id": "string",
"help": "message.real-number"
"id": "float",
"help": "message.real-number",
"step": 0.01
},
"placeholder": "label.real-number",
"default": "",
"pattern": "^(?:([0]*(\\.[0-9]+)?|[0]*\\.[0-9]*[1-9][0-9]*)|)$"
"minimum": 0.001,
"maximum": 0.999
}
}
}
Expand Down
Loading

0 comments on commit 80ca193

Please sign in to comment.