1 /*******************************************************************************
2 * Copyright (c) 2017 Politecnico di Torino and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Apache License, Version 2.0
6 * which accompanies this distribution, and is available at
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *******************************************************************************/
10 package it.polito.escape.verify.validation;
12 import com.fasterxml.jackson.databind.JsonNode;
14 import it.polito.escape.verify.model.Configuration;
15 import it.polito.escape.verify.model.Graph;
16 import it.polito.escape.verify.model.Node;
17 import it.polito.escape.verify.validation.exception.ValidationException;
19 public class VpnaccessValidator implements ValidationInterface {
22 public void validate(Graph graph, Node node, Configuration configuration) throws ValidationException {
23 JsonNode configurationNode = configuration.getConfiguration();
25 if (!configurationNode.isArray())
26 throw new ValidationException("configuration must be an array");
28 for (JsonNode object : configurationNode) {
29 JsonNode vpnexit = object.get("vpnexit");
30 if (!vpnexit.isTextual())
31 throw new ValidationException("value corresponding to the key 'vpnexit' must be a string");
32 validateObject(graph, node, vpnexit.asText());
37 private void validateObject(Graph g, Node node, String field) throws ValidationException {
38 boolean isValid = false;
39 for (Node n : g.getNodes().values()) {
40 if ((n.getFunctional_type().equals("vpnexit")) && (n.getName().equals(field)))
45 throw new ValidationException("'" + field + "' is not a valid value for the configuration of a type '"
46 + node.getFunctional_type()
47 + "'. Please use the name of an existing node of type 'vpnexit'.");