X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fportalapp%2Fportal%2Futils%2FEcompPortalUtils.java;h=0284452ad0fa619a6f928158c986af0b8d3c707a;hb=978dbcf0a196acbafad72fe1e2478ec0e384f02f;hp=d471d90b18a5a4da08934bc6f836bb9e51014e44;hpb=bc7350dce5b7b1dcd1c472a3922b42c4ea99809d;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/utils/EcompPortalUtils.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/utils/EcompPortalUtils.java index d471d90b..0284452a 100644 --- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/utils/EcompPortalUtils.java +++ b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/utils/EcompPortalUtils.java @@ -29,6 +29,7 @@ import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.DatatypeConverter; import org.hibernate.Session; import org.hibernate.Transaction; @@ -36,8 +37,11 @@ import org.openecomp.portalapp.portal.domain.EPUser; import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum; import org.openecomp.portalapp.portal.logging.logic.EPLogUtil; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.util.CipherUtil; import org.openecomp.portalsdk.core.util.SystemProperties; import org.slf4j.MDC; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -369,5 +373,45 @@ public class EcompPortalUtils { } } + /** + * It returns headers where username and password of external central auth + * is encoded to base64 + * + * @return header which contains external central auth username and password + * base64 encoded + * @throws Exception + * if unable to decrypt the password + */ + public static HttpHeaders base64encodeKeyForAAFBasicAuth() throws Exception { + + String userName = ""; + String decryptedPass = ""; + if (EPCommonSystemProperties + .containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_AUTH_USER_NAME) && EPCommonSystemProperties + .containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_AUTH_PASSWORD)) { + decryptedPass = SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_AUTH_PASSWORD); + userName = SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_AUTH_USER_NAME); + } + String decPass = decrypted(decryptedPass); + String usernamePass = userName + ":" + decPass; + String encToBase64 = String.valueOf((DatatypeConverter.printBase64Binary(usernamePass.getBytes()))); + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + encToBase64); + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } + + private static String decrypted(String encrypted) throws Exception { + String result = ""; + if (encrypted != null && encrypted.length() > 0) { + try { + result = CipherUtil.decrypt(encrypted, SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed", e); + throw e; + } + } + return result; + } }