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.cm.validation;
24 import java.util.List;
26 import org.onap.aaf.auth.dao.cass.ArtiDAO;
27 import org.onap.aaf.auth.dao.cass.ArtiDAO.Data;
28 import org.onap.aaf.auth.validation.Validator;
32 * Consistently apply content rules for content (incoming)
34 * Note: We restrict content for usability in URLs (because RESTful service), and avoid
35 * issues with Regular Expressions, and other enabling technologies.
39 public class CertmanValidator extends Validator{
40 // Repeated Msg fragments
41 private static final String MECHID = "mechid";
42 private static final String MACHINE = "machine";
43 private static final String ARTIFACT_LIST_IS_NULL = "Artifact List is null.";
44 private static final String Y = "y.";
45 private static final String IES = "ies.";
46 private static final String ENTR = " entr";
47 private static final String MUST_HAVE_AT_LEAST = " must have at least ";
48 private static final String IS_NULL = " is null.";
49 private static final String ARTIFACTS_MUST_HAVE_AT_LEAST = "Artifacts must have at least ";
51 public CertmanValidator nullBlankMin(String name, List<String> list, int min) {
55 if (list.size()<min) {
56 msg(name + MUST_HAVE_AT_LEAST + min + ENTR + (min==1?Y:IES));
58 for (String s : list) {
59 nullOrBlank("List Item",s);
66 public CertmanValidator artisRequired(List<ArtiDAO.Data> list, int min) {
68 msg(ARTIFACT_LIST_IS_NULL);
70 if (list.size()<min) {
71 msg(ARTIFACTS_MUST_HAVE_AT_LEAST + min + ENTR + (min==1?Y:IES));
73 for (ArtiDAO.Data a : list) {
81 public CertmanValidator keys(ArtiDAO.Data add) {
83 msg("Artifact is null.");
85 nullOrBlank(MECHID, add.mechid);
86 nullOrBlank(MACHINE, add.machine);
91 private CertmanValidator allRequired(Data a) {
93 msg("Artifact is null.");
95 nullOrBlank(MECHID, a.mechid);
96 nullOrBlank(MACHINE, a.machine);
97 nullOrBlank("ca",a.ca);
98 nullOrBlank("dir",a.dir);
99 nullOrBlank("os_user",a.os_user);
100 // Note: AppName, Notify & Sponsor are currently not required