Sonar Fixes: Variable name changes
[aaf/authz.git] / auth / auth-core / src / main / java / org / onap / aaf / auth / validation / Validator.java
index 6d519c6..1e40604 100644 (file)
@@ -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.
@@ -47,7 +47,9 @@ public class Validator {
     private final Pattern actionChars;
     private final Pattern instChars;
     private StringBuilder msgs;
-
+    public static final String PERM_TYPE = "Perm Type [";
+    public static final String IS_INVALID = "] is invalid.";
+    public static final String ROLE_STR = "Role [";
     static {
         nsKeywords = new ArrayList<>();
         nsKeywords.add(".access");
@@ -64,7 +66,7 @@ public class Validator {
         actionChars = ACTION_CHARS;
         instChars = INST_CHARS;
     }
-    
+
     public final String errs() {
         return msgs.toString();
     }
@@ -90,13 +92,13 @@ public class Validator {
     }
 
     protected final void match(String text, String str, Pattern p) {
-       if(str==null || !p.matcher(str).matches()) {
-               msg(text);
-       }
+        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) {
@@ -145,7 +147,7 @@ public class Validator {
 
     public final Validator permType(String type) {
         if (nob(type,NAME_CHARS)) {
-            msg("Perm Type [" +type + "] is invalid.");
+            msg(PERM_TYPE +type + IS_INVALID);
         }
         return this;
     }
@@ -156,29 +158,29 @@ 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");
         } else if (ns==null) {
             msg("Perm NS is null");
         } else if (nob(type,NAME_CHARS)) {
-            msg("Perm Type [" + (ns+(type.length()==0?"":'.')) + type + "] is invalid.");
+            msg(PERM_TYPE + (ns+(type.length()==0?"":'.')) + type + IS_INVALID);
         }
         return this;
     }
 
     public final Validator permInstance(String instance) {
-       if(!"/".equals(instance) && nob(instance,instChars)) {
-            msg("Perm Instance [" + instance + "] is invalid.");
+        if(!"/".equals(instance) && nob(instance,instChars)) {
+            msg("Perm Instance [" + instance + IS_INVALID);
         }
         return this;
     }
@@ -186,37 +188,37 @@ public class Validator {
     public final Validator permAction(String action) {
         // TODO check for correct Splits?  Type|Instance|Action ?
         if (nob(action, actionChars)) {
-            msg("Perm Action [" + action + "] is invalid.");
+            msg("Perm Action [" + action + IS_INVALID);
         }
         return this;
     }
 
     public final Validator role(String user, String role) {
-       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.");
-               }
-       }
+        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_STR + role + IS_INVALID);
+                }
+            } else if (nob(role, NAME_CHARS)) {
+                msg(ROLE_STR + role + IS_INVALID);
+            }
+        }
         return this;
     }
 
 
     public final Validator role(String role) {
         if (nob(role, NAME_CHARS)) {
-            msg("Role [" + role + "] is invalid.");
+            msg(ROLE_STR + role + IS_INVALID);
         }
         return this;
     }
@@ -226,8 +228,8 @@ public class Validator {
             msg("NS is null");
             return this;
         } else if (nob(ns,NAME_CHARS)) {
-            msg("NS [" + ns + "] is invalid.");
-        } 
+            msg("NS [" + ns + IS_INVALID);
+        }
         for (String s : nsKeywords) {
             if (ns.endsWith(s)) {
                 msg("NS [" + ns + "] may not be named with NS keywords");