Merge "added test cases in EPRoleTest.java"
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / utils / EcompPortalUtils.java
index efd84b9..f8d1116 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START==========================================
  * ONAP Portal
  * ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  *
  * ============LICENSE_END============================================
  *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * 
  */
 package org.onap.portalapp.portal.utils;
 
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.nio.charset.Charset;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Base64;
 import java.util.Date;
 import java.util.List;
 
@@ -56,7 +58,6 @@ import org.onap.portalapp.portal.logging.format.EPAppMessagesEnum;
 import org.onap.portalapp.portal.logging.logic.EPLogUtil;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
-import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
 import org.onap.portalsdk.core.util.SystemProperties;
 import org.slf4j.MDC;
 import org.springframework.http.HttpHeaders;
@@ -85,7 +86,7 @@ public class EcompPortalUtils {
         *         otherwise
         */
        public static boolean legitimateUserId(String orgUserId) {
-               return orgUserId.matches("^[a-zA-Z0-9]+$");
+               return orgUserId.matches("^[a-zA-Z0-9/_/-/@]+$");
        }
 
        /**
@@ -269,7 +270,7 @@ public class EcompPortalUtils {
 
        public static String getFEErrorString(Boolean internal, int responseCode) {
                // Return a String like the following:
-               // "Internal Ecomp Error: 500 internal_server_error" or
+               // "Internal Onap Error: 500 internal_server_error" or
                // "External App Error: 404 not_found"
                // TODO: create our own Ecomp error codes, starting with 1000 and up.
                String internalExternalString = internal ? "Ecomp Error: " : "App Error: ";
@@ -513,7 +514,7 @@ public class EcompPortalUtils {
        
        /**
         * 
-        * It check whether the external auth namespace is matching with current namepsace exists in local DB
+        * It check whether the external auth namespace is matching with current namespace exists in local DB
         * 
         * @param permTypeVal
         * @param appNamespaceVal
@@ -523,9 +524,13 @@ public class EcompPortalUtils {
                String[] typeNamespace = permTypeVal.split("\\.");
                String[] appNamespace = appNamespaceVal.split("\\.");
                boolean isNamespaceMatching = true;
-               for (int k = 0; k < appNamespace.length; k++) {
-                       if (!appNamespace[k].equals(typeNamespace[k]))
-                               isNamespaceMatching = false;
+               if (appNamespace.length <= typeNamespace.length) {
+                       for (int k = 0; k < appNamespace.length; k++) {
+                               if (!appNamespace[k].equals(typeNamespace[k]))
+                                       isNamespaceMatching = false;
+                       }
+               } else {
+                       isNamespaceMatching = false;
                }
                return isNamespaceMatching;
        }
@@ -560,4 +565,18 @@ public class EcompPortalUtils {
                       return false;
                    }
                  }
+         /**
+          * 
+          *  It retrieves account information from input String
+          * 
+          * @param authValue
+          * @return Array of Account information
+          * 
+          */
+         public static String[] getUserNamePassword(String authValue) {
+                       String base64Credentials = authValue.substring("Basic".length()).trim();
+                       String credentials = new String(Base64.getDecoder().decode(base64Credentials), Charset.forName("UTF-8"));
+                       final String[] values = credentials.split(":", 2);
+                       return values;
+               }
 }