diff options
Diffstat (limited to 'ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java')
-rw-r--r-- | ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java index 6f4ff29a..dc6559ab 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java @@ -38,6 +38,8 @@ package org.onap.portalsdk.external.authorization.util; import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.xml.bind.DatatypeConverter; @@ -65,11 +67,11 @@ public class EcompExternalAuthUtils { public static final String EXT_ROLE_FIELD_OWNER = ".owner"; public static final String EXT_ROLE_FIELD_ADMIN = ".admin"; - public static HttpHeaders base64encodeKeyForAAFBasicAuth() throws Exception { - String userName = EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_NAME); - String encryptedPass = EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD); - String decryptedPass = decryptPass(encryptedPass); - String usernamePass = userName + ":" + decryptedPass; + public static final Pattern VALID_USER_DOMAIN_ADDRESS_REGEX = + Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE); + + public static HttpHeaders base64encodeKeyForAAFBasicAuth(String username, String password) throws Exception { + String usernamePass = username + ":" + password; String encToBase64 = String.valueOf((DatatypeConverter.printBase64Binary(usernamePass.getBytes()))); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + encToBase64); @@ -77,7 +79,7 @@ public class EcompExternalAuthUtils { return headers; } - private static String decryptPass(String encrypted) throws Exception { + public static String decryptPass(String encrypted) throws Exception { String result = ""; if (encrypted != null && encrypted.length() > 0) { try { @@ -92,6 +94,16 @@ public class EcompExternalAuthUtils { } /** + * Validates, if given username has fully domain address + * @param String + * @return true or false + */ + public static boolean validate(String username) { + Matcher matcher = VALID_USER_DOMAIN_ADDRESS_REGEX.matcher(username); + return matcher.find(); + } + + /** * * It checks whether the namespace is matching or not * |