2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.locate.validation;
24 import org.onap.aaf.auth.validation.Validator;
26 import locate.v1_0.Endpoint;
27 import locate.v1_0.Endpoints;
28 import locate.v1_0.MgmtEndpoint;
29 import locate.v1_0.MgmtEndpoint.SpecialPorts;
30 import locate.v1_0.MgmtEndpoints;
34 * Consistently apply content rules for content (incoming)
36 * Note: We restrict content for usability in URLs (because RESTful service), and avoid
37 * issues with Regular Expressions, and other enabling technologies.
41 public class LocateValidator extends Validator {
42 private LocateValidator endpoint_key(Endpoint e) {
44 msg("Endpoint Data is null.");
46 nullOrBlank("Endpoint Name", e.getName());
47 if(e.getName()!=null) {
48 int idx = e.getName().indexOf('.');
50 msg("Endpoint Name must prefixed by Namespace");
53 nullOrBlank("Endpoint Hostname", e.getHostname());
54 intRange("Endpoint Port",e.getPort(),0,1000000);
60 public LocateValidator endpoint(Endpoint e) {
63 intRange("Endpoint Major Version",e.getMajor(),0,2000);
64 intRange("Endpoint Minor Version",e.getMinor(),0,2000);
65 intRange("Endpoint Patch Version",e.getPatch(),0,2000);
66 intRange("Endpoint Pkg Version",e.getPkg(),0,2000);
67 floatRange("Endpoint Latitude",e.getLatitude(),-90f,90f);
68 floatRange("Endpoint Longitude",e.getLongitude(),-180f,180f);
69 nullOrBlank("Endpoint Protocol", e.getProtocol());
70 for(String s : e.getSubprotocol()) {
71 nullOrBlank("Endpoint Subprotocol", s);
77 public LocateValidator endpoints(Endpoints e, boolean emptyNotOK) {
79 msg("Endpoints Data is null.");
81 if(emptyNotOK && e.getEndpoint().size()==0) {
82 msg("Endpoints contains no endpoints");
84 for(Endpoint ep : e.getEndpoint()) {
92 public LocateValidator mgmt_endpoint_key(MgmtEndpoints meps) {
94 msg("MgmtEndpoints Data is null.");
96 for(MgmtEndpoint ep : meps.getMgmtEndpoint()) {
103 public LocateValidator mgmt_endpoints(MgmtEndpoints me, boolean emptyOK) {
105 msg("MgmtEndpoints Data is null.");
107 if(!emptyOK && me.getMgmtEndpoint().size()==0) {
108 msg("MgmtEndpoints contains no data");
110 for(MgmtEndpoint ep : me.getMgmtEndpoint()) {
118 private LocateValidator mgmt_endpoint(MgmtEndpoint ep) {
120 for(SpecialPorts sp : ep.getSpecialPorts()) {
126 private LocateValidator specialPorts(SpecialPorts sp) {
128 msg("Special Ports is null.");
130 nullOrBlank("Special Port Name",sp.getName());
131 nullOrBlank("Special Port Protocol",sp.getProtocol());
132 intRange("Special Port",sp.getPort(),0,1000000);
134 for(String s : sp.getProtocolVersions()) {
135 nullOrBlank("Special Port Protocol Version", s);