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;
25 import java.util.regex.Pattern;
27 import org.onap.aaf.auth.dao.cass.ArtiDAO;
28 import org.onap.aaf.auth.dao.cass.ArtiDAO.Data;
29 import org.onap.aaf.auth.validation.Validator;
33 * Consistently apply content rules for content (incoming)
35 * Note: We restrict content for usability in URLs (because RESTful service), and avoid
36 * issues with Regular Expressions, and other enabling technologies.
40 public class CertmanValidator extends Validator{
41 // Repeated Msg fragments
42 private static final String MECHID = "mechid";
43 private static final String MACHINE = "machine";
44 private static final String ARTIFACT_LIST_IS_NULL = "Artifact List is null.";
45 private static final String Y = "y.";
46 private static final String IES = "ies.";
47 private static final String ENTR = " entr";
48 private static final String MUST_HAVE_AT_LEAST = " must have at least ";
49 private static final String IS_NULL = " is null.";
50 private static final String ARTIFACTS_MUST_HAVE_AT_LEAST = "Artifacts must have at least ";
51 private static final Pattern ALPHA_NUM = Pattern.compile("[a-zA-Z0-9]*");
53 private static boolean disallowTmp = true;
54 public static void allowTmp() {
58 public CertmanValidator nullBlankMin(String name, List<String> list, int min) {
62 if (list.size()<min) {
63 msg(name + MUST_HAVE_AT_LEAST + min + ENTR + (min==1?Y:IES));
65 for (String s : list) {
66 nullOrBlank("List Item",s);
73 public CertmanValidator artisRequired(List<ArtiDAO.Data> list, int min) {
75 msg(ARTIFACT_LIST_IS_NULL);
77 if (list.size()<min) {
78 msg(ARTIFACTS_MUST_HAVE_AT_LEAST + min + ENTR + (min==1?Y:IES));
80 for (ArtiDAO.Data a : list) {
82 if(disallowTmp && a.dir!=null && a.dir.startsWith("/tmp")) {
83 msg("Certificates may not be deployed into /tmp directory (they will be removed at a random time by O/S)");
91 public CertmanValidator keys(ArtiDAO.Data add) {
93 msg("Artifact is null.");
95 nullOrBlank(MECHID, add.mechid);
96 nullOrBlank(MACHINE, add.machine);
101 private CertmanValidator allRequired(Data a) {
103 msg("Artifact is null.");
105 nullOrBlank(MECHID, a.mechid);
106 nullOrBlank(MACHINE, a.machine);
107 nullOrBlank("ca",a.ca);
108 nullOrBlank("dir",a.dir);
109 match("NS must be dot separated AlphaNumeric",a.ns,NAME_CHARS);
110 match("O/S User must be AlphaNumeric",a.os_user,ALPHA_NUM);
111 // Note: AppName, Notify & Sponsor are currently not required