From d3d7215c29f41f4dc87cb215641c80d6458524cb Mon Sep 17 00:00:00 2001 From: Arthur Martella Date: Fri, 15 Mar 2019 12:42:15 -0400 Subject: Initial upload of F-GPS seed code 20/21 Includes: API utils Change-Id: I1a0e8a8e32fed1de53dc74cedf0525c863aabd04 Issue-ID: OPTFRA-440 Signed-off-by: arthur.martella.1@att.com --- .../java/org/onap/fgps/api/utils/CipherUtil.java | 214 +++++++++++++++++++++ .../java/org/onap/fgps/api/utils/Constants.java | 100 ++++++++++ .../fgps/api/utils/DBInitializationRequests.java | 50 +++++ .../main/java/org/onap/fgps/api/utils/Helper.java | 48 +++++ .../org/onap/fgps/api/utils/KeyProperties.java | 122 ++++++++++++ .../org/onap/fgps/api/utils/MusicDBConstants.java | 48 +++++ .../org/onap/fgps/api/utils/SystemProperties.java | 193 +++++++++++++++++++ .../java/org/onap/fgps/api/utils/UserUtils.java | 76 ++++++++ .../onap/fgps/api/utils/YamlToJsonConverter.java | 60 ++++++ 9 files changed, 911 insertions(+) create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/CipherUtil.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/Constants.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/DBInitializationRequests.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/Helper.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/KeyProperties.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/MusicDBConstants.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/SystemProperties.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/UserUtils.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/utils/YamlToJsonConverter.java diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/CipherUtil.java b/valetapi/src/main/java/org/onap/fgps/api/utils/CipherUtil.java new file mode 100644 index 0000000..6f8f595 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/CipherUtil.java @@ -0,0 +1,214 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +import java.security.Provider; +import java.security.SecureRandom; +import java.security.Security; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang.ArrayUtils; +import org.onap.fgps.api.exception.CipherUtilException; +import org.onap.fgps.api.logging.EELFLoggerDelegate; + +public class CipherUtil { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(CipherUtil.class); + + /** + * Default key. + */ + private static final String keyString = KeyProperties.getProperty("cipher.enc.key"); + + private static final String ALGORITHM = "AES"; + private static final String ALGORYTHM_DETAILS = ALGORITHM + "/CBC/PKCS5PADDING"; + private static final int BLOCK_SIZE = 128; + @SuppressWarnings("unused") + private static SecretKeySpec secretKeySpec; + private static IvParameterSpec ivspec; + + /** + * Encrypts the text using a secret key. + * + * @param plainText + * Text to encrypt + * @return Encrypted Text + * @throws CipherUtilException + * if any decryption step fails + */ + public static String encryptPKC(String plainText) throws CipherUtilException { + return CipherUtil.encryptPKC(plainText, keyString); + } + + private static SecretKeySpec getSecretKeySpec() { + byte[] key = Base64.decodeBase64(keyString); + return new SecretKeySpec(key, ALGORITHM); + } + + private static SecretKeySpec getSecretKeySpec(String keyString) { + byte[] key = Base64.decodeBase64(keyString); + return new SecretKeySpec(key, ALGORITHM); + } + + /** + * Encrypt the text using the secret key in key.properties file + * + * @param value + * @return The encrypted string + * @throws BadPaddingException + * @throws CipherUtilException + * In case of issue with the encryption + */ + public static String encryptPKC(String value, String skey) throws CipherUtilException { + Cipher cipher = null; + byte[] iv = null, finalByte = null; + + try { + cipher = Cipher.getInstance(ALGORYTHM_DETAILS, "SunJCE"); + + SecureRandom r = SecureRandom.getInstance("SHA1PRNG"); + iv = new byte[BLOCK_SIZE / 8]; + r.nextBytes(iv); + ivspec = new IvParameterSpec(iv); + cipher.init(Cipher.ENCRYPT_MODE, getSecretKeySpec(skey), ivspec); + finalByte = cipher.doFinal(value.getBytes()); + + } catch (Exception ex) { + LOGGER.error(EELFLoggerDelegate.errorLogger,"encrypt failed", ex); + throw new CipherUtilException(ex); + } + return Base64.encodeBase64String(ArrayUtils.addAll(iv, finalByte)); + } + + /** + * Decrypts the text using the secret key in key.properties file. + * + * @param message + * The encrypted string that must be decrypted using the ecomp + * Encryption Key + * @return The String decrypted + * @throws CipherUtilException + * if any decryption step fails + */ + public static String decryptPKC(String message, String skey) throws CipherUtilException { + byte[] encryptedMessage = Base64.decodeBase64(message); + Cipher cipher; + byte[] decrypted = null; + try { + cipher = Cipher.getInstance(ALGORYTHM_DETAILS, "SunJCE"); + ivspec = new IvParameterSpec(ArrayUtils.subarray(encryptedMessage, 0, BLOCK_SIZE / 8)); + byte[] realData = ArrayUtils.subarray(encryptedMessage, BLOCK_SIZE / 8, encryptedMessage.length); + cipher.init(Cipher.DECRYPT_MODE, getSecretKeySpec(skey), ivspec); + decrypted = cipher.doFinal(realData); + + } catch (Exception ex) { + LOGGER.error(EELFLoggerDelegate.errorLogger,"decrypt failed", ex); + throw new CipherUtilException(ex); + } + + return new String(decrypted); + } + + /** + * + * Decrypts the text using the secret key in key.properties file. + * + * @param encryptedText + * Text to decrypt + * @return Decrypted text + * @throws CipherUtilException + * if any decryption step fails + */ + public static String decryptPKC(String encryptedText) throws CipherUtilException { + return CipherUtil.decryptPKC(encryptedText, keyString); + } + + public static void maine(String[] args) throws CipherUtilException { + String testValue = "vmNKzC1wHH7w8PiZf7iPTTwq4iaAJn3dRlVK1YLvwgFESCqNPj3azGvRgNpR8tx+2p+o346C9PMip8SJyle/rw=="; + String encrypted; + + String decrypted; + + encrypted=encryptPKC(testValue); + System.out.println("encrypted"+encrypted); + + decrypted=decryptPKC(testValue); + System.out.println("decrypted"+ decrypted); + + } + + public static void main (String[] args) { + Provider[] pa = Security.getProviders(); + for (Provider p : pa) { + System.out.println("Provider: " + p + ", " + p.getInfo() ); + } + + /* + String encoded = "vmNKzC1wHH7w8PiZf7iPTTwq4iaAJn3dRlVK1YLvwgFESCqNPj3azGvRgNpR8tx+2p+o346C9PMip8SJyle/rw=="; + String decoded = decryptPKC(encoded); + String reencoded = encryptPKC(decoded); + System.out.println(encoded); + System.out.println(decoded); + System.out.println(reencoded); + */ + + String plainText = "Jackdaws love my big sphinx of quartz."; + String encoded = encryptPKC(plainText); + String decoded = decryptPKC(encoded); + System.out.println(plainText); + System.out.println(encoded); + System.out.println(decoded); + + } + + public static String encodeBasicAuth(String userId, String password) { + + String plainCreds = userId + ":" + password; + byte[] plainCredsBytes = plainCreds.getBytes(); + byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + + return "Basic " +base64Creds; + } + +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/Constants.java b/valetapi/src/main/java/org/onap/fgps/api/utils/Constants.java new file mode 100644 index 0000000..71fe8b8 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/Constants.java @@ -0,0 +1,100 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +public class Constants { + public static final String HEAT_REQUEST = "heat_request"; + public static final String HEAT_REQUEST_TEMPLATE = "template"; + public static final String VALET_ENGINE_KEY = "stack"; + public static final String VALET_REQUEST_RESOURCES = "resources"; + public static final String HEAT_REQUEST_FILES = "files"; + public static final String HEAT_RESOURCE_PROPERTIES = "properties"; + public static final String HEAT_REQUEST_RESOURCES_DEF = "resource_def"; + public static final String HEAT_REQUEST_RESOURCES_TYPE = "type"; + public static final String HEAT_REQUEST_ENVIRONMENT = "environment"; + public static final String HEAT_REQUEST_PARAMETERS = "parameters"; + public static final String HEAT_REQUEST_PROPERTIES_COUNT = "count"; + public static final String HEAT_REQUEST_DATACENTER = "datacenter"; + public static final String HEAT_REQUEST_REGION_ID = "region_id"; + public static final String HEAT_REQUEST_KEYSTONE_ID = "keystone_url"; + public static final String HEAT_REQUEST_KEYSTONE_NETWORKS = "networks"; + public static final String HEAT_REQUEST_AVAILABILITY_ZONE = "availability_zone"; + public static final String HEAT_REQUEST_SCHEDULER_HINTS = "scheduler_hints"; + public static final String HEAT_REQUEST_METADATA = "metadata"; + public static final String HEAT_REQUEST_VALET_HOST_ASSIGNMENT = "$VALET_HOST_ASSIGNMENT"; + public static final String HEAT_REQUEST_AZ = "$AZ"; + public static final String HEAT_REQUEST_PROPERTIES = "properties"; + public static final String HEAT_REQUEST_NAMES = "name"; + public static final String HEAT_REQUEST_IMAGE = "image"; + public static final String HEAT_REQUEST_FLAVOR = "flavor"; + + + // MSO Request constants + public static final String HEAT_REQUEST_REQUEST_ID = "request_id"; + public static final String HEAT_REQUEST_TIMESTAMP = "timestamp"; + public static final String HEAT_REQUEST_OPERATION = "operation"; + public static final String HEAT_REQUEST_STATUS = "status"; + + // tables names + public static final String HEAT_REQUEST_REQUEST = "request"; + + // tables names + public static final String SERVICE_PLACEMENTS_REQUEST_TABLE = "requests"; + public static final String SERVICE_PLACEMENTS_RESULTS_TABLE = "results"; + public static final String TABLE_RESULT = "results"; + public static final String TABLE_GROUP_RULES = "group_rules"; + public static final String TABLE_STACKS = "stacks"; + public static final String TABLE_STACKS_ID_MAP = "stack_id_map"; + public static final String TABLE_RESOURCES = "resources"; + public static final String TABLE_REGIONS = "regions"; + public static final String TABLE_Groups = "groups"; + + public static final String GROUPS_TABLE = "groups"; + public static final String GROUP_PLACEMENTS_TABLE = "group_placements"; + + // parsing constants + public static final String OS_NOVA_SERVER_ROOT = "OS::Nova::Server"; + public static final String OS_NOVA_SERVERGROUP_ROOT = "OS::Nova::ServerGroup"; + public static final String OS_HEAT_RESOURCEGROUP = "OS::Heat::ResourceGroup"; + + public static final int WAIT_UNITL_SECONDS = 300; + + public static final int POLL_EVERY_SECONDS = 5; + + +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/DBInitializationRequests.java b/valetapi/src/main/java/org/onap/fgps/api/utils/DBInitializationRequests.java new file mode 100644 index 0000000..691546c --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/DBInitializationRequests.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +public class DBInitializationRequests { + public static final String KEYSPACE_REQUEST = "{\"replicationInfo\":{\"class\":\"NetworkTopologyStrategy\",\"DC1\":3,\"DC2\":3,\"DC3\":3},\"durabilityOfWrites\":\"true\",\"consistencyInfo\":{\"type\":\"eventual\"}}"; + public static final String KEYSPACE_WITH_RF = "{\"replicationInfo\":{\"class\":\"NetworkTopologyStrategy\",DATA_CENTER_INFO},\"durabilityOfWrites\":\"true\",\"consistencyInfo\":{\"type\":\"eventual\"}}"; + + +} + + + + + \ No newline at end of file diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/Helper.java b/valetapi/src/main/java/org/onap/fgps/api/utils/Helper.java new file mode 100644 index 0000000..ef1eec1 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/Helper.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +import java.text.MessageFormat; + +public class Helper { + + public static String getURI(String macro, Object[] params) { + MessageFormat uri = new MessageFormat(macro); + return uri.format(params); + } +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/KeyProperties.java b/valetapi/src/main/java/org/onap/fgps/api/utils/KeyProperties.java new file mode 100644 index 0000000..90b7ad0 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/KeyProperties.java @@ -0,0 +1,122 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.onap.fgps.api.logging.EELFLoggerDelegate; + +/** + * Searches the classpath for the file "key.properties". + * + * To put the file "key.properties" on the classpath, it can be in the same + * directory where the first package folder is - 'myClasses' folder in the + * following case as an example: + * + */ +public class KeyProperties { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(CipherUtil.class); + + private static Properties properties; + private static String propertyFileName = "key.properties"; + + private static final Object lockObject = new Object(); + + /** + * Constructor is private. + */ + private KeyProperties() { + } + + /** + * Gets the property value for the specified key. If a value is found, leading + * and trailing space is trimmed. + * + * @param property + * Property key + * @return Value for the named property; null if the property file was not + * loaded or the key was not found. + */ + public static String getProperty(String property) { + if (properties == null) { + synchronized (lockObject) { + try { + if (!initialize()) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName); + return null; + } + } catch (IOException e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName, e); + return null; + } + } + } + String value = properties.getProperty(property); + if (value != null) + value = value.trim(); + return value; + } + + /** + * Reads properties from a portal.properties file on the classpath. + * + * Clients do NOT need to call this method. Clients MAY call this method to test + * whether the properties file can be loaded successfully. + * + * @return True if properties were successfully loaded, else false. + * @throws IOException + * On failure + */ + private static boolean initialize() throws IOException { + if (properties != null) + return true; + InputStream in = KeyProperties.class.getClassLoader().getResourceAsStream(propertyFileName); + if (in == null) + return false; + properties = new Properties(); + try { + properties.load(in); + } finally { + in.close(); + } + return true; + } +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/MusicDBConstants.java b/valetapi/src/main/java/org/onap/fgps/api/utils/MusicDBConstants.java new file mode 100644 index 0000000..4c7a937 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/MusicDBConstants.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +public class MusicDBConstants { + public static final String CREATE_ONBOARDING = "/admin/onboardAppWithMusic"; + public static final String CREATE_KEYSPACE = "/keyspaces/{0}";// {0} is name + public static final String CREATE_TABLE = "/keyspaces/{0}/tables/{1}"; //{1} is table name + public static final String INSERT_ROWS = "/keyspaces/{0}/tables/{1}/rows"; + public static final String INDEX = "/keyspaces/{0}/tables/{1}/index/{2}"; //{2} fieldname + public static final String ONBOARDING = "/keyspaces/onboardAppWithMusic"; + public static final String MUSIC_DB_URL = "/MUSIC/rest/v2"; +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/SystemProperties.java b/valetapi/src/main/java/org/onap/fgps/api/utils/SystemProperties.java new file mode 100644 index 0000000..5ca4dd1 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/SystemProperties.java @@ -0,0 +1,193 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +import javax.servlet.ServletContext; + +import org.onap.fgps.api.logging.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; + +/** + * SystemProperties contains a list of constants used throughout portions of the + * application. Populated by Spring from multiple configuration files. + * + * Should be used like this: + * + *
+ * 
+ * @Autowired
+ * SystemProperties systemProperties;
+ * 
+ */ +@Configuration +//@PropertySource(value = { "${container.classpath:}/system.properties" }) +@PropertySource(value = { "file:opt/etc/config/system.properties" }) +public class SystemProperties { + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SystemProperties.class); + + private static Environment environment; + + private ServletContext servletContext; + + public static final String APP_DISPLAY_NAME = "app_display_name"; + public static final String APPLICATION_NAME = "application_name"; + public static final String INSTANCE_UUID = "instance_uuid"; + public static final String MDC_CLASS_NAME = "ClassName"; + public static final String MDC_LOGIN_ID = "LoginId"; + public static final String MDC_TIMER = "Timer"; + public static final String APP_NAME = "VALET_API"; + public static final String VALET_REQUEST_ID = "X-VALET-API-RequestID"; + public static final String PARTNER_NAME = "PartnerName"; + public static final String FULL_URL = "Full-URL"; + public static final String AUDITLOG_BEGIN_TIMESTAMP = "AuditLogBeginTimestamp"; + public static final String AUDITLOG_END_TIMESTAMP = "AuditLogEndTimestamp"; + public static final String METRICSLOG_BEGIN_TIMESTAMP = "MetricsLogBeginTimestamp"; + public static final String METRICSLOG_END_TIMESTAMP = "MetricsLogEndTimestamp"; + public static final String CLIENT_IP_ADDRESS = "ClientIPAddress"; + public static final String STATUS_CODE = "StatusCode"; + public static final String RESPONSE_CODE = "ResponseCode"; + // Component or sub component name + public static final String TARGET_ENTITY = "TargetEntity"; + // API or operation name + public static final String TARGET_SERVICE_NAME = "TargetServiceName"; + + // Logging Compliance + public static final String SINGLE_QUOTE = "'"; + public static final String NA = "N/A"; + public static final String UNKNOWN = "Unknown"; + public static final String SECURITY_LOG_TEMPLATE = "Protocol:{0} Security-Event-Type:{1} Login-ID:{2} {3}"; + public static final String PROTOCOL = "PROTOCOL"; + public static final String SECURIRY_EVENT_TYPE = "SECURIRY_EVENT_TYPE"; + public static final String LOGIN_ID = "LOGIN_ID"; + public static final String ADDITIONAL_INFO = "ADDITIONAL_INFO"; + public static final String USERAGENT_NAME = "user-agent"; + + // Protocols + public static final String HTTP = "HTTP"; + public static final String HTTPS = "HTTPS"; + + public enum RESULT_ENUM { + SUCCESS, FAILURE + } + + public enum SecurityEventTypeEnum { + INCOMING_REST_MESSAGE, OUTGOING_REST_MESSAGE, REST_AUTHORIZATION_CREDENTIALS_MODIFIED + } + + public SystemProperties() { + super(); + } + + protected Environment getEnvironment() { + return environment; + } + + @Autowired + public void setEnvironment(Environment environment) { + SystemProperties.environment = environment; + } + + public ServletContext getServletContext() { + return servletContext; + } + + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + + /** + * Tests whether a property value is available for the specified key. + * + * @param key + * Property key + * @return True if the key is known, otherwise false. + */ + public static boolean containsProperty(String key) { + return environment.containsProperty(key); + } + + /** + * Returns the property value associated with the given key (never + * {@code null}), after trimming any trailing space. + * + * @param key + * Property key + * @return Property value; the empty string if the environment was not + * autowired, which should never happen. + * @throws IllegalStateException + * if the key is not found + */ + public static String getProperty(String key) { + String value = ""; + if (environment == null) { + logger.error(EELFLoggerDelegate.errorLogger, "getProperty: environment is null, should never happen!"); + } else { + value = environment.getRequiredProperty(key); + // java.util.Properties preserves trailing space + if (value != null) + value = value.trim(); + } + return value; + } + + /** + * Gets the property value for the key {@link #APPLICATION_NAME}. + * + * method created to get around JSTL 1.0 limitation of not being able to access + * a static method of a bean + * + * @return Application name + */ + public String getApplicationName() { + return getProperty(APPLICATION_NAME); + } + + /** + * Gets the property value for the key {@link #APP_DISPLAY_NAME}. + * + * @return Application display name + */ + public String getAppDisplayName() { + return getProperty(APP_DISPLAY_NAME); + } + +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/UserUtils.java b/valetapi/src/main/java/org/onap/fgps/api/utils/UserUtils.java new file mode 100644 index 0000000..be46ad2 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/UserUtils.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +import javax.servlet.http.HttpServletRequest; + +import org.onap.fgps.api.logging.EELFLoggerDelegate; +import org.springframework.web.util.HtmlUtils; + +@SuppressWarnings("rawtypes") +public class UserUtils { + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserUtils.class); + + public static final String KEY_USER_ROLES_CACHE = "userRoles"; + + /** + * Gets the full URL of the request by joining the request and any query string. + * + * @param request + * @return Full URL of the request including query parameters + */ + public static String getFullURL(HttpServletRequest request) { + if (request != null) { + StringBuffer requestURL = request.getRequestURL(); + String queryString = request.getQueryString(); + + if (queryString == null) { + return requestURL.toString(); + } else { + return requestURL.append('?').append(queryString).toString(); + } + } + return ""; + } + + public static String htmlEscape(String input) { + if (input==null) return null; + return HtmlUtils.htmlEscape(input); + } +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/utils/YamlToJsonConverter.java b/valetapi/src/main/java/org/onap/fgps/api/utils/YamlToJsonConverter.java new file mode 100644 index 0000000..78c929c --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/utils/YamlToJsonConverter.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.utils; + +import org.onap.fgps.api.logging.EELFLoggerDelegate; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; + +public class YamlToJsonConverter { + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(YamlToJsonConverter.class); + public static String convertToJson(String data) { + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + try { + Object obj = mapper.readValue(data, Object.class); + ObjectMapper jsonWriter = new ObjectMapper(); + return jsonWriter.writeValueAsString(obj); + } catch (Exception e) { + e.printStackTrace(); + LOGGER.error(EELFLoggerDelegate.applicationLogger,"convertToJson : Error details : "+ e.getMessage()); + LOGGER.error(EELFLoggerDelegate.errorLogger,"convertToJson : Error details : "+ e.getMessage()); + } + return ""; + } +} -- cgit 1.2.3-korg