import java.util.List;
import javax.servlet.http.HttpServletResponse;
+import javax.xml.bind.DatatypeConverter;
import org.hibernate.Session;
import org.hibernate.Transaction;
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;
}
}
}
+
+ public static String widgetMsProtocol(){
+ final String protocol;
+ try{
+ protocol = SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL);
+ return (protocol == null || protocol.trim().equals("")) ? "https" : protocol ;
+ }
+ catch(IllegalStateException ese){
+ //looks like SystemProperties.getProperty throws IllegalStateException if it cannot find a property you are looking for
+ //In order to not break the code if a non-required property is missing from system.properties, returning https as default
+ //when this exception is caught.
+ return "https";
+ }
+ }
+
+ public static String localOrDockerHost(){
+ final String effectiveHost;
+ try{
+ effectiveHost = SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_HOSTNAME);
+ return (effectiveHost == null || effectiveHost.trim().equals("")) ? "localhost" : effectiveHost ;
+ }
+ catch(IllegalStateException ese){
+ //looks like SystemProperties.getProperty throws IllegalStateException if it cannot find a property you are looking for
+ //In order to not break the code if a non-required property is missing from system.properties, returning https as default
+ //when this exception is caught.
+ return "localhost";
+ }
+ }
+ /**
+ * 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;
+ }
+
+ public static String truncateString(String originString, int size){
+ if(originString.length()>=size){
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(originString);
+ stringBuilder.setLength(size);
+ stringBuilder.append("...");
+ return stringBuilder.toString();
+ }
+ return originString;
+ }
}