Fixed the Policy API issues and Bugfixes
[policy/engine.git] / ECOMP-PDP-REST / src / main / java / org / openecomp / policy / pdp / rest / config / PDPApiAuth.java
index ed98e54..c4573cc 100644 (file)
@@ -51,6 +51,10 @@ public class PDPApiAuth {
            private static Long oldModified = null;
            private static AAFPolicyClient aafClient = null;
            
+           private PDPApiAuth(){
+               // Private Constructor
+           }
+           
            /*
             * Set Property by reading the properties File.
             */
@@ -84,14 +88,14 @@ public class PDPApiAuth {
                    String resource) {
                try{
                    String[] userNamePass = PolicyUtils.decodeBasicEncoding(clientEncoding);
-                   if(userNamePass==null){
+                   if(userNamePass==null || userNamePass.length==0){
                        String usernameAndPassword = null;
                        byte[] decodedBytes = Base64.getDecoder().decode(clientEncoding);
                        usernameAndPassword = new String(decodedBytes, "UTF-8");
                        StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
                        String username = tokenizer.nextToken();
                        String password = tokenizer.nextToken();
-                       userNamePass=  new String[]{username, password};
+                       userNamePass=  new String[]{username,  password};
                    }
                    PolicyLogger.info("User " + userNamePass[0] + " is Accessing Policy Engine API.");
                    Boolean result = false;
@@ -160,7 +164,7 @@ public class PDPApiAuth {
                    throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Load the Properties file", e);
                }
                // Read the Properties and Load the Clients and their scopes.
-               clientMap = new HashMap<String, ArrayList<String>>();
+               clientMap = new HashMap<>();
                // 
                for (Object propKey : clientProp.keySet()) {
                    String clientID = (String)propKey; 
@@ -174,7 +178,7 @@ public class PDPApiAuth {
                        } 
                    }
                }
-               if (clientMap == null || clientMap.isEmpty()) {
+               if (clientMap.isEmpty()) {
                    PolicyLogger.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "No Clients ID , Client Key and Scopes are available. Cannot serve any Clients !!");
                    throw new PolicyEngineException("Empty Client file");
                }