some cleanup

This commit is contained in:
Andreas Penski 2020-05-03 16:52:55 +02:00
parent 1a001a1af4
commit 7dc62012a6
22 changed files with 144 additions and 50 deletions

View file

@ -1,21 +1,22 @@
package de.kosit.validationtool.api;
/**
* Tri-state describtion of a Recommendation.
* Tri-state recommendation whether to accept the {@link Input} or not.
*/
public enum AcceptRecommendation {
/**
* The evaluation of the overall validation could not be computed.
*/
UNDEFINED,
/**
* Recommendation is to accept input based on the evaluation of the overall validation.
* Recommendation is to accept {@link Input} based on the evaluation of the overall validation.
*/
ACCEPTABLE,
/**
* Recommendation is to reject input based on the evaluation of the overall validation.
* Recommendation is to reject {@link Input} based on the evaluation of the overall validation.
*/
REJECT
}

View file

@ -12,15 +12,15 @@ import de.kosit.validationtool.impl.Scenario;
/**
* Configuration of the actual {@link Check} instance. This is an interface and can be implemented by custom
* configuration classes. There are two implementations supported out of the box:
*
*
* <ol>
* <li>{@link ConfigurationLoader} implements loading {@link Check} configurations from a scenario.xml file</li>
* <li>Using a builder style api {@link de.kosit.validationtool.config.ConfigurationBuilder}to configure the
* {@link Check}</li>
* </ol>
*
* <p>
* Both methods can be used via convinience methods. See below.
*
*
* @author Andreas Penski
*/
@ -28,51 +28,57 @@ public interface Configuration {
/**
* Returns a list of configured scenarios.
*
*
* @return the list of scenarios
*/
List<Scenario> getScenarios();
/**
* Returns the configured fallback scenario to use, in case no configured scenario match.
*
*
* @return the fallback scenario
*/
Scenario getFallbackScenario();
/**
* Returns the author of this configuration.
*
*
* @return the author
*/
String getAuthor();
/**
* Returns the name of the specification
*
*
* @return the name
*/
String getName();
/**
* The creation date of the config
*
*
* @return the date
*/
String getDate();
/**
* Add some additional parameters to the validator configuration. Parameter usage depends on actual implementation of
* {@link Check}
*
* @return
*/
Map<String, Object> getAdditionalParameters();
/**
* The content repository including resolving strategies.
*
*
* @return the configured {@link ContentRepository}
*/
ContentRepository getContentRepository();
/**
* Loads an XML based scenario definition from the file specified via URI.
*
*
* @param scenarioDefinition the XML file with scenario definition
* @return the loaded configuration
*/
@ -93,7 +99,7 @@ public interface Configuration {
/**
* Creates a {@link Configuration} based on a builder style API using {@link ConfigurationBuilder}
*
*
* @return the Builder
*/
static ConfigurationBuilder create() {

View file

@ -10,12 +10,15 @@ import javax.xml.validation.Validator;
import net.sf.saxon.s9api.Processor;
/**
* Centralized construction and configuration of XML related infrastructore components. The KoSIT Validator provides out
* of the box implementaions with various security levels.
* Centralized construction and configuration of XML related infrastructure components. This interface allows to use
* custom implementations and configurations of internal xml related factories and objects.
*
* The KoSIT Validator provides out of the box implementations with various security levels based on openjdk SAX stack.
*
* If you decide to implement a custom strategy, please be aware of XML security within your stack. The validator
* components beyond this strategy asume secured implementation of the interfaces provided by this strategy. There is no
* effort to mitigate or prevent xml related security issues such as XXE, loading external sources etc.
* effort to mitigate or prevent xml related security issues such as XXE, loading external sources etc. Your would be
* responsible for this!
*
* @see de.kosit.validationtool.impl.ResolvingMode
* @author Andreas Penski
@ -35,12 +38,14 @@ public interface ResolvingConfigurationStrategy {
* leverages the saxon s9api for internal processing e.g. xml reading and writing. So this is the main object to secure
* for reading, transforming and writing xml files.
*
* Note: you need exactly one instance for all validator related processing.
*
* @return a preconfigured {@link Processor}
*/
Processor getProcessor();
/**
* Creates a specific implementation for resolving referenced objects in XML files. The URIResolver, it is used for
* Creates a specific implementation for resolving referenced objects in XML files. The URIResolver is used for
* dereferencing an absolute URI (after resolution) to return a {@link javax.xml.transform.Source}. It <b>can</b> be
* used for resolving relative URIs against a base URI or restrict access to certain URIs.
* <p>
@ -48,6 +53,7 @@ public interface ResolvingConfigurationStrategy {
* <code>xsl:import-schema</code> declarations.
* </p>
*
* @param scenarioRepository an optional repository, your implementation might not need this
* @return a preconfigured {@link URIResolver}
*/
URIResolver createResolver(URI scenarioRepository);

View file

@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;

View file

@ -64,12 +64,17 @@ public class ConfigurationBuilder {
private String description;
/**
* Add a specific author name to this configuration.
*
* @param authorName the name of the author
* @return this
*/
public ConfigurationBuilder author(final String authorName) {
this.author = authorName;
return this;
}
public ConfigurationBuilder name(final String name) {
this.name = name;
return this;
@ -135,6 +140,12 @@ public class ConfigurationBuilder {
throw new NotImplementedException("Not yet defined");
}
/**
* Create a named schematron configuration.
*
* @param name the name of the schematron configuration
* @return new {@link SchemaBuilder}
*/
public static SchematronBuilder schematron(final String name) {
return new SchematronBuilder().name(name);
}

View file

@ -175,11 +175,27 @@ public class ConfigurationLoader {
return s;
}
/**
* Sets actual {@link ResolvingMode}, when the validator needs to resolve stuff on startup.
* @param mode the resolving mode
* @return this
*/
public ConfigurationLoader setResolvingMode(final ResolvingMode mode) {
this.resolvingMode = mode;
return this;
}
public ConfigurationLoader setResolvingStrategy(final ResolvingConfigurationStrategy strategy){
this.resolvingConfigurationStrategy = strategy;
return this;
}
/**
* Add a parameter to the configuration.
* @param name the name of the parameter
* @param value the parameter value object
* @return this
*/
public ConfigurationLoader addParameter(final String name, final Object value) {
this.parameters.put(name, value);
return this;

View file

@ -13,6 +13,8 @@ import de.kosit.validationtool.model.scenarios.CreateReportType;
import de.kosit.validationtool.model.scenarios.ScenarioType;
/**
* Create a fallback {@link Scenario} configuration.
*
* @author Andreas Penski
*/
public class FallbackBuilder implements Builder<Scenario> {

View file

@ -72,7 +72,7 @@ class XPathBuilder implements Builder<XPathExecutable> {
extractNamespaces();
}
} catch (final IllegalStateException e) {
final String msg = String.format("Error creating %s xpath", this.name, e);
final String msg = String.format("Error creating %s xpath: %s", this.name, e.getMessage());
log.error(msg, e);
return new Result<>(Collections.singletonList(msg));

View file

@ -1,5 +1,7 @@
package de.kosit.validationtool.impl;
import lombok.SneakyThrows;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@ -65,6 +67,10 @@ public class EngineInformation {
return getFrameworkVersion().substring(0, 1);
}
public static String getBuild() {
return PROPERTIES.getProperty("build_number");
}
/**
* Gibt den Namespace des eingesetzten Frameworks zurück.
*

View file

@ -60,7 +60,7 @@ public class ComputeAcceptanceAction implements CheckAction {
} catch (final SaxonApiException e) {
final String msg = String.format("Error evaluating accept recommendation: %s", selector.getUnderlyingXPathContext().toString());
log.error(msg, e);
results.addProcessingError(msg);
results.stopProcessing(msg);
}
}

View file

@ -28,6 +28,7 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.util.JAXBSource;
import javax.xml.transform.URIResolver;
import lombok.extern.slf4j.Slf4j;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
@ -64,6 +65,7 @@ import net.sf.saxon.s9api.XsltTransformer;
* @author Andreas Penski
*/
@RequiredArgsConstructor
@Slf4j
public class CreateReportAction implements CheckAction {
/**
@ -206,7 +208,8 @@ public class CreateReportAction implements CheckAction {
results.setReport(destination.getXdmNode());
} catch (final SaxonApiException | SAXException | JAXBException e) {
throw new IllegalStateException("Can not create final report", e);
log.error("Error creating final report", e);
results.stopProcessing("Can not create final report: " + e.getMessage());
}
}

View file

@ -94,16 +94,5 @@ public class RelativeUriResolver implements URIResolver {
}
public Reader resolve(final URI absoluteURI, final String encoding, final Configuration config) throws XPathException {
if (isUnderBaseUri(absoluteURI)) {
try {
return new InputStreamReader(absoluteURI.toURL().openStream(), encoding);
} catch (final IOException e) {
throw new IllegalStateException(String.format("Can not resolve required %s", absoluteURI), e);
}
} else {
throw new IllegalStateException(String.format(
"The resolved transformation artifact %s is not within the configured repository %s", absoluteURI, this.baseUri));
}
}
}

View file

@ -0,0 +1,7 @@
package de.kosit.validationtool.impl.xml;
public class RemoteResolvingStrategy extends StrictLocalResolvingStrategy {
}

View file

@ -10,7 +10,9 @@ import javax.xml.validation.Validator;
import lombok.extern.slf4j.Slf4j;
/**
*
* This is a slightly more open implementation that allows resolving artifacts from local filesystems. Your are not
* bound to a specific 'repository'. But your validation artifacts (schema, xsl, etc.) must be available locally. This
* implementation does not allow loading from http sources
*
* @author Andreas Penski
*/
@ -18,16 +20,23 @@ import lombok.extern.slf4j.Slf4j;
public class StrictLocalResolvingStrategy extends StrictRelativeResolvingStrategy {
/**
* e.g. don't allow any scheme
* Allow loading schema files from any local location.
*
* @return a configured {@link SchemaFactory}
*/
@Override
public SchemaFactory createSchemaFactory() {
final SchemaFactory schemaFactory = super.createSchemaFactory();
allowExternalSchema(schemaFactory, "file", "jar");
allowExternalSchema(schemaFactory, "file");
return schemaFactory;
}
/**
* The default resolver is able to resolve locally and relative.
*
* @param repository the repository is not used by this strategy
* @return null!
*/
@Override
public URIResolver createResolver(final URI repository) {
// intentionally return 'null', since all resolving is configured with the other objects
@ -37,7 +46,7 @@ public class StrictLocalResolvingStrategy extends StrictRelativeResolvingStrateg
@Override
public Validator createValidator(final Schema schema) {
final Validator validator = super.createValidator(schema);
allowExternalSchema(validator, "file", "jar");
allowExternalSchema(validator, "file");
return validator;
}

View file

@ -95,6 +95,7 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(FEATURE_SECURE_PROCESSING), true);
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(DISSALLOW_DOCTYPE_DECL_FEATURE), true);
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(LOAD_EXTERNAL_DTD_FEATURE), false);
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false);
return processor;
}

View file

@ -16,7 +16,6 @@
<complexType name="HealthType">
<sequence>
<element name="status">
<simpleType>
<restriction base="string">
<enumeration value="UP"></enumeration>