diff options
Diffstat (limited to 'src/main/java/org')
5 files changed, 28 insertions, 22 deletions
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 5160d04a8..144a48c92 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 @@ -71,7 +71,7 @@ public class PolicyClient { protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); protected static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type"; protected static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name"; - @Value("${org.onap.clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}") + @Value("${clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}") protected String cldsPolicyConfigFile; @Autowired protected ApplicationContext appContext; diff --git a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java index 15d06b9af..bb1b9d139 100644 --- a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java +++ b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java @@ -27,11 +27,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.apache.commons.io.IOUtils; import org.onap.clamp.clds.exception.CldsUsersException; import org.onap.clamp.clds.service.CldsUser; public class CldsUserJsonDecoder { + /** * This method decodes the JSON file provided to a CldsUser Array. The * stream is closed after this call, this is not possible to reuse it. @@ -43,9 +46,17 @@ public class CldsUserJsonDecoder { */ public static CldsUser[] decodeJson(InputStream cldsUsersFile) { try { + return decodeJson(IOUtils.toString(cldsUsersFile, StandardCharsets.UTF_8.name())); + } catch (IOException e) { + throw new CldsUsersException("Exception occurred during the decoding of the clds-users.json", e); + } + } + + public static CldsUser[] decodeJson(String cldsUsersString) { + try { // the ObjectMapper readValue method closes the stream no need to do // it - return new ObjectMapper().readValue(cldsUsersFile, CldsUser[].class); + return new ObjectMapper().readValue(cldsUsersString, CldsUser[].class); } catch (IOException e) { throw new CldsUsersException("Exception occurred during the decoding of the clds-users.json", e); } diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java index c99dd21fd..5b5490426 100644 --- a/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java @@ -56,7 +56,7 @@ public class SdcControllersConfiguration { /** * The file name that will be loaded by Spring. */ - @Value("${org.onap.clamp.config.files.sdcController:'classpath:/clds/sdc-controllers-config.json'}") + @Value("${clamp.config.files.sdcController:'classpath:/clds/sdc-controllers-config.json'}") protected String sdcControllerFile; /** * The root of the JSON. 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 51bd69540..d9e5ef298 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 @@ -28,12 +28,12 @@ import com.att.eelf.configuration.EELFManager; import java.io.IOException; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.config.CldsUserJsonDecoder; import org.onap.clamp.clds.exception.CldsUsersException; import org.onap.clamp.clds.service.CldsUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; @@ -44,7 +44,7 @@ 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). + * (classpath:clds/clds-users.json). */ @Configuration @EnableWebSecurity @@ -54,9 +54,7 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter { protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSecurityConfigUsers.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); @Autowired - private ApplicationContext appContext; - @Value("${org.onap.clamp.config.files.cldsUsers:'classpath:etc/config/clds/clds-users.json'}") - private String cldsUsersFile; + private ClampProperties refProp; @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") private String cldsPersmissionTypeCl; @Value("${CLDS_PERMISSION_INSTANCE:dev}") @@ -89,7 +87,7 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter { CldsUser[] usersList = loadUsers(); // no users defined if (null == usersList) { - logger.warn("No users defined. Users should be defined under " + cldsUsersFile); + logger.warn("No users defined. Users should be defined under clds-users.json"); return; } for (CldsUser user : usersList) { @@ -107,14 +105,11 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter { * CldsUser. * * @return The array of CldsUser + * @throws IOException + * In case of the file is not found */ - private CldsUser[] loadUsers() { - try { - logger.info("Load from clds-users.properties"); - return CldsUserJsonDecoder.decodeJson(appContext.getResource(cldsUsersFile).getInputStream()); - } catch (IOException e) { - logger.error("Unable to decode the User Json file", e); - throw new CldsUsersException("Load from clds-users.properties", e); - } + private CldsUser[] loadUsers() throws IOException { + logger.info("Load from clds-users.properties"); + return CldsUserJsonDecoder.decodeJson(refProp.getFileContent("files.cldsUsers")); } } 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 2968f60a4..9bd9c4173 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -472,19 +472,19 @@ public class CldsService extends SecureServiceBase { throw new CldsConfigException(e.getMessage(), e); } // refresh model info from db (get fresh event info) - CldsModel retreivedModel = CldsModel.retrieve(cldsDao, modelName, false); + CldsModel retrievedModel = CldsModel.retrieve(cldsDao, modelName, false); if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT) || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT) || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) { // To verify inventory status and modify model status to distribute - dcaeInventoryServices.setEventInventory(retreivedModel, getUserId()); - retreivedModel.save(cldsDao, getUserId()); + dcaeInventoryServices.setEventInventory(retrievedModel, getUserId()); + retrievedModel.save(cldsDao, getUserId()); } // audit log LoggingUtils.setTimeContext(startTime, new Date()); LoggingUtils.setResponseContext("0", "Process model action success", this.getClass().getName()); auditLogger.info("Process model action completed"); - return retreivedModel; + return retrievedModel; } /** @@ -853,7 +853,7 @@ public class CldsService extends SecureServiceBase { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public CldsModel unDeployModel(@PathParam("action") String action, @PathParam("modelName") String modelName, - @QueryParam("test") String test, CldsModel model) throws IOException { + @QueryParam("test") String test, CldsModel model) { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName()); String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(), |