From 35c6bda8ced4143b4fc1731727ee9bbe76b34c96 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Mon, 5 Mar 2018 16:03:25 +0100 Subject: Remove the clds-reference.properties Remove clds-reference.properties and merge it into application.properties Issue-ID: CLAMP-136 Change-Id: I8dc6deffdca47dc50d1473ccbe9a94dc91d7d5d9 Signed-off-by: Determe, Sebastien (sd378r) --- .../clamp/clds/client/DcaeDispatcherServices.java | 4 +- .../clamp/clds/client/DcaeInventoryServices.java | 4 +- .../clamp/clds/client/HolmesPolicyDelegate.java | 4 +- .../clds/client/OperationalPolicyDelegate.java | 4 +- .../onap/clamp/clds/client/SdcSendReqDelegate.java | 4 +- .../onap/clamp/clds/client/TcaPolicyDelegate.java | 4 +- .../client/req/policy/OperationalPolicyReq.java | 12 +- .../clamp/clds/client/req/policy/PolicyClient.java | 4 +- .../clds/client/req/sdc/SdcCatalogServices.java | 4 +- .../clamp/clds/client/req/sdc/SdcRequests.java | 4 +- .../clds/client/req/tca/TcaRequestFormatter.java | 10 +- .../onap/clamp/clds/config/ClampProperties.java | 154 ++++++++++++++++++ .../clamp/clds/config/CldsReferenceProperties.java | 173 --------------------- .../config/spring/CldsSecurityConfigUsers.java | 20 +-- .../org/onap/clamp/clds/service/CldsService.java | 16 +- .../clamp/clds/service/CldsTemplateService.java | 4 +- 16 files changed, 199 insertions(+), 226 deletions(-) create mode 100644 src/main/java/org/onap/clamp/clds/config/ClampProperties.java delete mode 100644 src/main/java/org/onap/clamp/clds/config/CldsReferenceProperties.java (limited to 'src/main/java/org/onap') diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java index f92405813..9226604a1 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java @@ -31,7 +31,7 @@ import java.util.Date; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.exception.dcae.DcaeDeploymentException; import org.onap.clamp.clds.util.LoggingUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -47,7 +47,7 @@ public class DcaeDispatcherServices { protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeDispatcherServices.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; private static final String STATUS_URL_LOG = "Status URL extracted: "; private static final String DCAE_URL_PREFIX = "/dcae-deployments/"; private static final String DCAE_URL_PROPERTY_NAME = "dcae.dispatcher.url"; diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java index 4a2f32e6e..c4abebdcd 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java @@ -41,7 +41,7 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsModel; @@ -63,7 +63,7 @@ public class DcaeInventoryServices { protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); private static final String DCAE_INVENTORY_URL = "dcae.inventory.url"; @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; @Autowired private CldsDao cldsDao; diff --git a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java index 4e165e141..37259cdfe 100644 --- a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java @@ -31,7 +31,7 @@ import java.util.UUID; import org.apache.camel.Exchange; import org.apache.camel.Handler; import org.onap.clamp.clds.client.req.policy.PolicyClient; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.model.properties.Holmes; import org.onap.clamp.clds.model.properties.ModelProperties; import org.springframework.beans.factory.annotation.Autowired; @@ -48,7 +48,7 @@ public class HolmesPolicyDelegate { @Autowired private PolicyClient policyClient; @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; /** * Perform activity. Send Holmes info to policy api. diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java index ec83db9de..ae2880567 100644 --- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java @@ -33,7 +33,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Handler; import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq; import org.onap.clamp.clds.client.req.policy.PolicyClient; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.model.properties.Policy; import org.onap.clamp.clds.model.properties.PolicyChain; @@ -61,7 +61,7 @@ public class OperationalPolicyDelegate { * Automatically injected by Spring, define in CldsConfiguration as a bean. */ @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; /** * Perform activity. Send Operational Policy info to policy api. diff --git a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java index 438ea4727..64e19f922 100644 --- a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java @@ -35,7 +35,7 @@ import org.apache.camel.Handler; import org.apache.commons.codec.DecoderException; import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; import org.onap.clamp.clds.client.req.sdc.SdcRequests; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.model.DcaeEvent; import org.onap.clamp.clds.model.properties.Global; import org.onap.clamp.clds.model.properties.ModelProperties; @@ -55,7 +55,7 @@ public class SdcSendReqDelegate { @Autowired private SdcRequests sdcReq; @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; /** * Perform activity. Send to sdc proxy. diff --git a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java index 55fe2c571..e16e8c35a 100644 --- a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java @@ -32,7 +32,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Handler; import org.onap.clamp.clds.client.req.policy.PolicyClient; import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.model.properties.Tca; import org.springframework.beans.factory.annotation.Autowired; @@ -47,7 +47,7 @@ public class TcaPolicyDelegate { protected static final EELFLogger logger = EELFManager.getInstance().getLogger(TcaPolicyDelegate.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; @Autowired private PolicyClient policyClient; diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java index 434da4b65..d3e8a5418 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java @@ -39,7 +39,7 @@ import java.util.Map; import javax.ws.rs.BadRequestException; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.model.properties.Global; import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.model.properties.PolicyChain; @@ -80,7 +80,7 @@ public class OperationalPolicyReq { * @throws BuilderException * @throws UnsupportedEncodingException */ - public static Map> formatAttributes(CldsReferenceProperties refProp, ModelProperties prop, + public static Map> formatAttributes(ClampProperties refProp, ModelProperties prop, String modelElementId, PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { Global global = prop.getGlobal(); prop.setCurrentModelElementId(modelElementId); @@ -163,7 +163,7 @@ public class OperationalPolicyReq { * @throws BuilderException * @throws UnsupportedEncodingException */ - protected static String formatOpenLoopYaml(CldsReferenceProperties refProp, ModelProperties prop, String modelElementId, + protected static String formatOpenLoopYaml(ClampProperties refProp, ModelProperties prop, String modelElementId, PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { // get property objects Global global = prop.getGlobal(); @@ -193,7 +193,7 @@ public class OperationalPolicyReq { * @throws BuilderException * @throws UnsupportedEncodingException */ - protected static String formatYaml(CldsReferenceProperties refProp, ModelProperties prop, String modelElementId, + protected static String formatYaml(ClampProperties refProp, ModelProperties prop, String modelElementId, PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { // get property objects Global global = prop.getGlobal(); @@ -251,7 +251,7 @@ public class OperationalPolicyReq { * @throws BuilderException * @throws UnsupportedEncodingException */ - protected static String formateNodeBYaml(CldsReferenceProperties refProp, ModelProperties prop, String modelElementId, + protected static String formateNodeBYaml(ClampProperties refProp, ModelProperties prop, String modelElementId, PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { // get property objects Global global = prop.getGlobal(); @@ -329,7 +329,7 @@ public class OperationalPolicyReq { * @param inOrigList * @return */ - private static List addAOTSActorRecipe(CldsReferenceProperties refProp, String service, List inOrigList) { + private static List addAOTSActorRecipe(ClampProperties refProp, String service, List inOrigList) { List outList = new ArrayList<>(); try { PolicyItem policyItem = inOrigList.get(0); diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java index 06eff4ef7..5160d04a8 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java @@ -37,7 +37,7 @@ import java.util.UUID; import javax.ws.rs.BadRequestException; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.exception.policy.PolicyClientException; import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.util.LoggingUtils; @@ -76,7 +76,7 @@ public class PolicyClient { @Autowired protected ApplicationContext appContext; @Autowired - protected CldsReferenceProperties refProp; + protected ClampProperties refProp; /** * Perform BRMS policy type. diff --git a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java index c01fe6a3c..5664653bf 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java +++ b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java @@ -58,7 +58,7 @@ import org.apache.commons.csv.CSVRecord; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpHeaders; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.exception.sdc.SdcCommunicationException; import org.onap.clamp.clds.model.CldsAlarmCondition; import org.onap.clamp.clds.model.CldsServiceData; @@ -93,7 +93,7 @@ public class SdcCatalogServices { private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool"; private static final String RESOURCE_URL_PREFIX = "resources"; @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; /** * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic diff --git a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcRequests.java b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcRequests.java index 214933d49..e34b7e907 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcRequests.java +++ b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcRequests.java @@ -41,7 +41,7 @@ import java.util.Map.Entry; import org.apache.commons.codec.DecoderException; import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.model.properties.Global; import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.model.properties.Tca; @@ -61,7 +61,7 @@ public class SdcRequests { @Autowired private SdcCatalogServices sdcCatalogServices; @Autowired - protected CldsReferenceProperties refProp; + protected ClampProperties refProp; /** * Format the Blueprint from a Yaml diff --git a/src/main/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatter.java b/src/main/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatter.java index 73355a7a4..f51469159 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatter.java +++ b/src/main/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatter.java @@ -32,7 +32,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; import java.util.Map; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.exception.TcaRequestFormatterException; import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.model.properties.Tca; @@ -64,7 +64,7 @@ public class TcaRequestFormatter { * The Model Prop created from BPMN JSON and BPMN properties JSON * @return The Json string containing that should be sent to policy */ - public static String createPolicyJson(CldsReferenceProperties refProp, ModelProperties modelProperties) { + public static String createPolicyJson(ClampProperties refProp, ModelProperties modelProperties) { try { String service = modelProperties.getGlobal().getService(); Tca tca = modelProperties.getType(Tca.class); @@ -103,7 +103,7 @@ public class TcaRequestFormatter { * modelProperties.setCurrentModelElementId will be used * @return The Json node containing what should be sent to policy */ - public static JsonNode createPolicyContent(CldsReferenceProperties refProp, ModelProperties modelProperties, String service, + public static JsonNode createPolicyContent(ClampProperties refProp, ModelProperties modelProperties, String service, String policyName, Tca tca) { try { String serviceToUse = service; @@ -153,7 +153,7 @@ public class TcaRequestFormatter { * The Model Properties created from BPMN JSON and BPMN * properties JSON */ - private static void addThresholds(CldsReferenceProperties refProp, String service, ObjectNode appendToNode, TcaItem tcaItem, + private static void addThresholds(ClampProperties refProp, String service, ObjectNode appendToNode, TcaItem tcaItem, ModelProperties modelProperties) { ArrayNode tcaNodes = appendToNode.withArray("thresholds"); ObjectNode tcaNode; @@ -185,7 +185,7 @@ public class TcaRequestFormatter { * The yaml string received from the UI * @return The updated YAML as a string */ - public static String updatedBlueprintWithConfiguration(CldsReferenceProperties refProp, ModelProperties modelProperties, + public static String updatedBlueprintWithConfiguration(ClampProperties refProp, ModelProperties modelProperties, String yamlValue) { String jsonPolicy = ((ObjectNode) createPolicyContent(refProp, modelProperties, null, null, null)).toString(); logger.info("Yaml that will be updated:" + yamlValue); diff --git a/src/main/java/org/onap/clamp/clds/config/ClampProperties.java b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java new file mode 100644 index 000000000..66f35acc6 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java @@ -0,0 +1,154 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.config; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +/** + * Holds Clamp properties and add some functionalities. + */ +@Component +public class ClampProperties { + + @Autowired + private ApplicationContext appContext; + @Autowired + private Environment env; + public static final String CONFIG_PREFIX = "clamp.config."; + + /** + * get property value. + * + * @param key + * The first key + * @return The string with the value + */ + public String getStringValue(String key) { + return env.getProperty(CONFIG_PREFIX + key); + } + + /** + * get property value for a combo key (key1 + "." + key2). If not found just + * use key1. + * + * @param key1 + * The first key + * @param key2 + * The second key after a dot + * @return The string with the value + */ + public String getStringValue(String key1, String key2) { + String value = getStringValue(key1 + "." + key2); + if (value == null || value.length() == 0) { + value = getStringValue(key1); + } + return value; + } + + /** + * Return json as objects that can be updated. The value obtained from the + * clds-reference file will be used as a filename. + * + * @param key + * The key that will be used to access the clds-reference file + * @return A jsonNode + * @throws IOException + * In case of issues with the JSON parser + */ + public JsonNode getJsonTemplate(String key) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + String fileReference = getStringValue(key); + return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class) + : null; + } + + /** + * Return json as objects that can be updated. First try with combo key + * (key1 + "." + key2), otherwise default to just key1. The value obtained + * from the clds-reference file will be used as a filename. + * + * @param key1 + * The first key + * @param key2 + * The second key after a dot + * @return A JsonNode + * @throws IOException + * In case of issues with the JSON parser + */ + public JsonNode getJsonTemplate(String key1, String key2) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + String fileReference = getStringValue(key1, key2); + return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class) + : null; + } + + /** + * Return the file content. The value obtained from the clds-reference file + * will be used as a filename. + * + * @param key + * The key that will be used to access the clds-reference file + * @return File content in String + * @throws IOException + * In case of issues with the JSON parser + */ + public String getFileContent(String key) throws IOException { + String fileReference = getStringValue(key); + return (fileReference != null) ? getFileContentFromPath(fileReference) : null; + } + + /** + * Return the file content. First try with combo key (key1 + "." + key2), + * otherwise default to just key1. The value obtained from the + * clds-reference file will be used as a filename. + * + * @param key1 + * The first key + * @param key2 + * The second key after a dot + * @return File content in String + * @throws IOException + * In case of issues with the JSON parser + */ + public String getFileContent(String key1, String key2) throws IOException { + String fileReference = getStringValue(key1, key2); + return (fileReference != null) ? getFileContentFromPath(fileReference) : null; + } + + private String getFileContentFromPath(String filepath) throws IOException { + URL url = appContext.getResource(filepath).getURL(); + return IOUtils.toString(url, StandardCharsets.UTF_8); + } +} diff --git a/src/main/java/org/onap/clamp/clds/config/CldsReferenceProperties.java b/src/main/java/org/onap/clamp/clds/config/CldsReferenceProperties.java deleted file mode 100644 index b234b9329..000000000 --- a/src/main/java/org/onap/clamp/clds/config/CldsReferenceProperties.java +++ /dev/null @@ -1,173 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.config; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import java.io.IOException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.Properties; - -import javax.annotation.PostConstruct; - -import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationContext; -import org.springframework.core.io.Resource; -import org.springframework.stereotype.Component; - -/** - * Holds reference properties. - */ -@Component -public class CldsReferenceProperties { - - @Autowired - private ApplicationContext appContext; - private Properties prop; - @Value("${org.onap.clamp.config.files.cldsReference:'classpath:/clds/clds-reference.properties'}") - private String cldsReferenceValuesFile; - - @PostConstruct - public void loadConfiguration() throws IOException { - prop = new Properties(); - Resource resource = appContext.getResource(cldsReferenceValuesFile); - prop.load(resource.getInputStream()); - } - - public CldsReferenceProperties(String referenceValuesFile) throws IOException { - cldsReferenceValuesFile = referenceValuesFile; - loadConfiguration(); - } - - public CldsReferenceProperties() { - } - - /** - * get property value. - * - * @param key - * The first key - * @return The string with the value - */ - public String getStringValue(String key) { - return prop.getProperty(key); - } - - /** - * get property value for a combo key (key1 + "." + key2). If not found just - * use key1. - * - * @param key1 - * The first key - * @param key2 - * The second key after a dot - * @return The string with the value - */ - public String getStringValue(String key1, String key2) { - String value = getStringValue(key1 + "." + key2); - if (value == null || value.length() == 0) { - value = getStringValue(key1); - } - return value; - } - - /** - * Return json as objects that can be updated. The value obtained from the - * clds-reference file will be used as a filename. - * - * @param key - * The key that will be used to access the clds-reference file - * @return A jsonNode - * @throws IOException - * In case of issues with the JSON parser - */ - public JsonNode getJsonTemplate(String key) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - String fileReference = getStringValue(key); - return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class) - : null; - } - - /** - * Return json as objects that can be updated. First try with combo key - * (key1 + "." + key2), otherwise default to just key1. The value obtained - * from the clds-reference file will be used as a filename. - * - * @param key1 - * The first key - * @param key2 - * The second key after a dot - * @return A JsonNode - * @throws IOException - * In case of issues with the JSON parser - */ - public JsonNode getJsonTemplate(String key1, String key2) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - String fileReference = getStringValue(key1, key2); - return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class) - : null; - } - - /** - * Return the file content. The value obtained from the clds-reference file - * will be used as a filename. - * - * @param key - * The key that will be used to access the clds-reference file - * @return File content in String - * @throws IOException - * In case of issues with the JSON parser - */ - public String getFileContent(String key) throws IOException { - String fileReference = getStringValue(key); - return (fileReference != null) ? getFileContentFromPath(fileReference) : null; - } - - /** - * Return the file content. First try with combo key (key1 + "." + key2), - * otherwise default to just key1. The value obtained from the - * clds-reference file will be used as a filename. - * - * @param key1 - * The first key - * @param key2 - * The second key after a dot - * @return File content in String - * @throws IOException - * In case of issues with the JSON parser - */ - public String getFileContent(String key1, String key2) throws IOException { - String fileReference = getStringValue(key1, key2); - return (fileReference != null) ? getFileContentFromPath(fileReference) : null; - } - - private String getFileContentFromPath(String filepath) throws IOException { - URL url = appContext.getResource(filepath).getURL(); - return IOUtils.toString(url, StandardCharsets.UTF_8); - } -} diff --git a/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java b/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java index 12dc36418..51bd69540 100644 --- a/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java +++ b/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java @@ -45,28 +45,22 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur * This class is used to enable the HTTP authentication to login. It requires a * specific JSON file containing the user definition * (classpath:etc/config/clds/clds-users.json). - * */ @Configuration @EnableWebSecurity @Profile("clamp-spring-authentication") public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter { - protected static final EELFLogger logger = EELFManager.getInstance() - .getLogger(CldsSecurityConfigUsers.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSecurityConfigUsers.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - @Autowired - private ApplicationContext appContext; - + private ApplicationContext appContext; @Value("${org.onap.clamp.config.files.cldsUsers:'classpath:etc/config/clds/clds-users.json'}") - private String cldsUsersFile; - - @Value("${CLDS_PERMISSION_TYPE_CL:permission-type-cl}") - private String cldsPersmissionTypeCl; - + private String cldsUsersFile; + @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") + private String cldsPersmissionTypeCl; @Value("${CLDS_PERMISSION_INSTANCE:dev}") - private String cldsPermissionInstance; + private String cldsPermissionInstance; /** * This method configures on which URL the authorization will be enabled. @@ -93,13 +87,11 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter { public void configureGlobal(AuthenticationManagerBuilder auth) { try { CldsUser[] usersList = loadUsers(); - // no users defined if (null == usersList) { logger.warn("No users defined. Users should be defined under " + cldsUsersFile); return; } - for (CldsUser user : usersList) { auth.inMemoryAuthentication().withUser(user.getUser()).password(user.getPassword()) .roles(user.getPermissionsString()); diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index a9b1b771a..3b6bc3778 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -62,7 +62,7 @@ import org.onap.clamp.clds.camel.CamelProxy; import org.onap.clamp.clds.client.DcaeDispatcherServices; import org.onap.clamp.clds.client.DcaeInventoryServices; import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.exception.CldsConfigException; import org.onap.clamp.clds.exception.policy.PolicyClientException; @@ -105,17 +105,17 @@ public class CldsService extends SecureServiceBase { @Autowired private ApplicationContext appContext; private static final String RESOURCE_NAME = "clds-version.properties"; - @Value("${CLDS_PERMISSION_TYPE_CL:permission-type-cl}") + @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") private String cldsPersmissionTypeCl; - @Value("${CLDS_PERMISSION_TYPE_CL_MANAGE:permission-type-cl-manage}") + @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") private String cldsPermissionTypeClManage; - @Value("${CLDS_PERMISSION_TYPE_CL_EVENT:permission-type-cl-event}") + @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") private String cldsPermissionTypeClEvent; - @Value("${CLDS_PERMISSION_TYPE_FILTER_VF:permission-type-filter-vf}") + @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") private String cldsPermissionTypeFilterVf; - @Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}") + @Value("${clamp.config.security.permission.type.template:permission-type-template}") private String cldsPermissionTypeTemplate; - @Value("${CLDS_PERMISSION_INSTANCE:dev}") + @Value("${clamp.config.security.permission.instance:dev}") private String cldsPermissionInstance; private SecureServicePermission permissionReadCl; private SecureServicePermission permissionUpdateCl; @@ -140,7 +140,7 @@ public class CldsService extends SecureServiceBase { @Autowired private XslTransformer cldsBpmnTransformer; @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; @Autowired private SdcCatalogServices sdcCatalogServices; @Autowired diff --git a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java index e64f74bb2..1b03922d1 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java @@ -55,9 +55,9 @@ import org.springframework.stereotype.Component; @Path("/cldsTempate") public class CldsTemplateService extends SecureServiceBase { - @Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}") + @Value("${clamp.config.security.permission.type.template:permission-type-template}") private String cldsPermissionTypeTemplate; - @Value("${CLDS_PERMISSION_INSTANCE:dev}") + @Value("${clamp.config.security.permission.instance:dev}") private String cldsPermissionInstance; private SecureServicePermission permissionReadTemplate; private SecureServicePermission permissionUpdateTemplate; -- cgit 1.2.3-korg