X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fvalidation%2FValidator.java;h=fcbccb12da4b3d0b778f29d8563003e9504ff646;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=c0f2f530c5cac305b44eeab5b3a653cdbb889bed;hpb=ba989d05eca8d2a98c51ed9d38c4c3345db23349;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/validation/Validator.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/validation/Validator.java index c0f2f530..fcbccb12 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/validation/Validator.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/validation/Validator.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -64,7 +64,7 @@ public class Validator { actionChars = ACTION_CHARS; instChars = INST_CHARS; } - + public final String errs() { return msgs.toString(); } @@ -86,10 +86,17 @@ public class Validator { } protected final boolean noMatch(String str, Pattern p) { - return !p.matcher(str).matches(); + return str==null || !p.matcher(str).matches(); } + + protected final void match(String text, String str, Pattern p) { + if(str==null || !p.matcher(str).matches()) { + msg(text); + } + } + protected final boolean nob(String str, Pattern p) { - return str==null || !p.matcher(str).matches(); + return str==null || !p.matcher(str).matches(); } protected final void msg(String ... strs) { @@ -149,15 +156,15 @@ public class Validator { } else if (user==null) { msg("User is null"); } else { - if(!(type.startsWith(user) && type.endsWith(":id"))) { - if(nob(type,NAME_CHARS)) { - msg("Perm Type [" + type + "] is invalid."); - } - } + if(!(type.startsWith(user) && type.endsWith(":id"))) { + if(nob(type,NAME_CHARS)) { + msg("Perm Type [" + type + "] is invalid."); + } + } } return this; } - + public final Validator permType(String type, String ns) { if (type==null) { msg("Perm Type is null"); @@ -170,7 +177,7 @@ public class Validator { } public final Validator permInstance(String instance) { - if(!"/".equals(instance) && nob(instance,instChars)) { + if(!"/".equals(instance) && nob(instance,instChars)) { msg("Perm Instance [" + instance + "] is invalid."); } return this; @@ -185,21 +192,24 @@ public class Validator { } public final Validator role(String user, String role) { - if(role==null) { - msg("Role is null"); - } - if(user==null) { - msg("User is null"); - } - if(!err()) { - if(role.startsWith(user) && role.endsWith(":user")) { - if(!(role.length() == user.length() + 5)) { - msg("Role [" + role + "] is invalid."); - } - } else if (nob(role, NAME_CHARS)) { - msg("Role [" + role + "] is invalid."); - } - } + boolean quit = false; + if(role==null) { + msg("Role is null"); + quit = true; + } + if(user==null) { + msg("User is null"); + quit = true; + } + if(!quit) { + if(role.startsWith(user) && role.endsWith(":user")) { + if(!(role.length() == user.length() + 5)) { + msg("Role [" + role + "] is invalid."); + } + } else if (nob(role, NAME_CHARS)) { + msg("Role [" + role + "] is invalid."); + } + } return this; } @@ -217,7 +227,7 @@ public class Validator { return this; } else if (nob(ns,NAME_CHARS)) { msg("NS [" + ns + "] is invalid."); - } + } for (String s : nsKeywords) { if (ns.endsWith(s)) { msg("NS [" + ns + "] may not be named with NS keywords");