* ============LICENSE_START=======================================================
* PolicyEngineAPI
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* 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.
import static org.onap.policy.std.utils.PolicyConfigConstants.UNAUTHORIZED_STATUS_CODE;
import static org.onap.policy.std.utils.PolicyConfigConstants.UPDATE_DICTIONARY_ITEM_RESOURCE_NAME;
import static org.onap.policy.std.utils.PolicyConfigConstants.UPDATE_POLICY_RESOURCE_NAME;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.onap.policy.api.AttributeType;
+import org.onap.policy.api.ConfigNameRequest;
import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.DecisionRequestParameters;
import org.onap.policy.api.DecisionResponse;
import org.onap.policy.models.APIPolicyConfigResponse;
import org.onap.policy.std.utils.PolicyCommonConfigConstants;
import org.onap.policy.utils.AAFEnvironment;
+import org.onap.policy.utils.PeCryptoUtils;
import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.springframework.core.io.FileSystemResource;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.xml.sax.InputSource;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
/**
* PolicyEngine Implementation class
- *
+ *
* @version 1.0
*/
public class StdPolicyEngine {
private static final String UNIQUEID = UUID.randomUUID().toString();
private static final Logger LOGGER = FlexLogger.getLogger(StdPolicyConfig.class.getName());
+ private static final String LIST_POLICY_RESOURCE_NAME = "listPolicy";
/*
* Taking the Property file even if it null.
public StdPolicyEngine(final String propertyFilePath, final String clientKey) throws PolicyEngineException {
setProperty(propertyFilePath, clientKey);
}
-
+
/*
* Taking the Property structure even if it null.
*/
return listConfigImpl(listPolicyRequestParameters);
}
+ /*
+ * listPolicies from PDP using ConfigNameRequest Implementation
+ */
+ public Collection<String> listPolicy(final ConfigNameRequest listPolicyRequestParameters)
+ throws PolicyConfigException {
+ return listPolicyImpl(listPolicyRequestParameters);
+ }
+
/*
* getDecision using the decision Attributes.
*/
return policyEngineImportImpl(importParameters);
}
- private PolicyChangeResponse policyEngineImportImpl(final ImportParameters importParameters) throws PolicyException {
+ private PolicyChangeResponse policyEngineImportImpl(final ImportParameters importParameters)
+ throws PolicyException {
final LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
// Create Request.
try {
return policyList;
}
+ public Collection<String> listPolicyImpl(final ConfigNameRequest listPolicyRequestParameters)
+ throws PolicyConfigException {
+ final Collection<String> policyList = new ArrayList<>();
+ if (junit) {
+ policyList.add(TEST_POLICY_NAME);
+ return policyList;
+ }
+ String body = null;
+ // Create Request.
+ try {
+ body = PolicyUtils.objectToJsonString(listPolicyRequestParameters);
+ } catch (final JsonProcessingException e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID, e);
+ throw new PolicyConfigException(XACMLErrorConstants.ERROR_SCHEMA_INVALID, e);
+ }
+ // Get Response.
+ try {
+ final ResponseEntity<String[]> result =
+ callNewPDP(LIST_POLICY_RESOURCE_NAME, HttpMethod.POST, body, String[].class);
+ for (final String policy : result.getBody()) {
+ policyList.add(policy);
+ }
+ } catch (final Exception exception) {
+ final String defaulMessage = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_INVALID_PDPS + pdps;
+ final String message = getErrorMessage(exception, defaulMessage, LIST_POLICY_RESOURCE_NAME);
+ LOGGER.error(message, exception);
+ throw new PolicyConfigException(message, exception);
+ }
+
+ return policyList;
+ }
+
private Collection<PolicyResponse> sendEventImpl(final Map<String, String> eventAttributes, final UUID requestID)
throws PolicyEventException {
String body = null;
XACMLErrorConstants.ERROR_DATA_ISSUE + "Error NO PropertyFile Path provided");
}
final Properties prop = getProperties(propertyFilePath);
- setProperty(prop,clientKey);
+ setProperty(prop, clientKey);
}
-
+
private void setProperty(final Properties properties, String clientKey) throws PolicyEngineException {
if (properties == null) {
throw new PolicyEngineException(
private void readPDPPropertyURL(Properties prop, String propertyKey) throws PolicyEngineException {
final String propertyValue = prop.getProperty(propertyKey);
if (propertyValue == null) {
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
- + "Properties file doesn't have the PDP_URL parameter");
+ throw new PolicyEngineException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Properties file doesn't have the PDP_URL parameter");
}
if (propertyValue.contains(SEMICOLLON)) {
final List<String> pdpDefault = Arrays.asList(propertyValue.split(REGEX));
}
private String getClientKeyFromProperties(final Properties prop) {
- final String clientKeyValue = prop.getProperty(CLIENT_KEY_PROP_NAME);
+ final String clientKeyValue = PeCryptoUtils.decrypt(prop.getProperty(CLIENT_KEY_PROP_NAME));
try {
return PolicyUtils.decode(clientKeyValue);
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
pdps.add(pdpValues.get(0));
// 1:2 will be UserID:Password
final String userID = pdpValues.get(1);
- final String userPas = pdpValues.get(2);
+ final String userPas = PeCryptoUtils.decrypt(pdpValues.get(2));
final Base64.Encoder encoder = Base64.getEncoder();
encoding.add(encoder.encodeToString((userID + ":" + userPas).getBytes(StandardCharsets.UTF_8)));
} else {