+ /**
+ * 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;
+ }