import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
public class StdPolicyEngine {
private static final String ERROR_AUTH_GET_PERM = "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to: ";
private static final String DEFAULT_NOTIFICATION = "websocket";
-
- private String clientEncoding = null;
+ private static final String ERROR_DATA_ISSUE = "Invalid Data is given.";
+ private static final String DMAAP = "dmaap";
+ private static final String ERROR_INVALID_PDPS = "Unable to get valid Response from PDP(s) ";
+ private static final String ERROR_WHILE_CONNECTING = "Error while connecting to ";
+
+ private static String clientEncoding = null;
private String contentType = null;
private static List<String> pdps = null;
private static String environment = null;
private static String pass = null;
private static List<String> encoding = null;
private static boolean junit = false;
- private List<String> pdpDefault = null;
- private List<String> typeDefault = null;
private List<String> notificationType = new ArrayList<>();
private List<String> notificationURLList = new ArrayList<>();
private NotificationScheme scheme = null;
setProperty(propertyFilePath, null);
this.scheme = scheme;
this.handler = handler;
- if ((!"ueb".equals(notificationType.get(0))) || (!"dmaap".equals(notificationType.get(0)))) {
+ if ((!"ueb".equals(notificationType.get(0))) || (!DMAAP.equals(notificationType.get(0)))) {
AutoClientEnd.setAuto(scheme, handler);
}
notification(scheme, handler);
return response;
}
if (exception.getCause().getMessage().contains("400")) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Data is given.";
+ String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
response.setResponseMessage(message);
response.setResponseCode(400);
return response;
}
- String message = XACMLErrorConstants.ERROR_PERMISSIONS + "Unable to get valid Response from PDP(s) "
+ String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_INVALID_PDPS
+ pdps;
LOGGER.error(message, exception);
response.setResponseMessage(message);
public PolicyChangeResponse policyEngineImportImpl(ImportParameters importParameters) throws PolicyException {
StdPolicyChangeResponse response = new StdPolicyChangeResponse();
String resource = "policyEngineImport";
- LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
+ LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
// Create Request.
try {
String body = PolicyUtils.objectToJsonString(importParameters);
public DecisionResponse getDecisionImpl(String onapName, Map<String, String> decisionAttributes, UUID requestID)
throws PolicyDecisionException {
String resource = "getDecision";
- StdDecisionResponse response = new StdDecisionResponse();
+ StdDecisionResponse response;
String body = null;
// Create Request.
try {
throw new PolicyDecisionException(message, exception);
}
if (exception.getCause().getMessage().contains("400")) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Data is given.";
+ String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
LOGGER.error(message);
throw new PolicyDecisionException(message, exception);
}
- String message = XACMLErrorConstants.ERROR_PERMISSIONS + "Unable to get valid Response from PDP(s) "
+ String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_INVALID_PDPS
+ pdps;
LOGGER.error(message, exception);
throw new PolicyDecisionException(message, exception);
public Collection<PolicyConfig> getConfigImpl(ConfigRequestParameters configRequestParameters)
throws PolicyConfigException {
String resource = "getConfig";
- ArrayList<PolicyConfig> response = new ArrayList<>();
+ ArrayList<PolicyConfig> response;
String body = null;
// Create Request.
try {
throw new PolicyConfigException(message, exception);
}
if (exception.getCause().getMessage().contains("400")) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Data is given.";
+ String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
LOGGER.error(message);
throw new PolicyConfigException(message, exception);
}
- String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to get valid Response from PDP(s) "
+ String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_INVALID_PDPS
+ pdps;
LOGGER.error(message, exception);
throw new PolicyConfigException(message, exception);
policyConfig.setPolicyName(policyConfigResponse.getPolicyName());
policyConfig.setPolicyType(policyConfigResponse.getType());
policyConfig.setPolicyVersion(policyConfigResponse.getPolicyVersion());
+ policyConfig.setPolicyType(policyConfigResponse.getPolicyType());
policyConfig.setResponseAttributes(policyConfigResponse.getResponseAttributes());
setMatches(policyConfig.getMatchingConditions());
if (policyConfigResponse.getType() != null) {
try {
switch (policyConfigResponse.getType()) {
case JSON:
- JsonReader jsonReader = Json
- .createReader(new StringReader(policyConfigResponse.getConfig()));
- JsonObject object = jsonReader.readObject();
- jsonReader.close();
- policyConfig.setJsonObject(object);
+ try (JsonReader jsonReader = Json
+ .createReader(new StringReader(policyConfigResponse.getConfig())) ) {
+ JsonObject object = jsonReader.readObject();
+ policyConfig.setJsonObject(object);
+ }
break;
case OTHER:
policyConfig.setOther(policyConfigResponse.getConfig());
Matches match = new Matches();
HashMap<String, String> configAttributes = new HashMap<>();
try {
- for (String key : matchingConditions.keySet()) {
- if (key.equalsIgnoreCase("ONAPName")) {
- match.setOnapName(matchingConditions.get(key));
- } else if (key.equalsIgnoreCase("ConfigName")) {
- match.setConfigName(matchingConditions.get(key));
+ for (Map.Entry<String,String> entry : matchingConditions.entrySet()) {
+ if ("ONAPName".equalsIgnoreCase(entry.getKey())) {
+ match.setOnapName(entry.getValue());
+ } else if ("ConfigName".equalsIgnoreCase(entry.getKey())) {
+ match.setConfigName(entry.getValue());
} else {
- configAttributes.put(key, matchingConditions.get(key));
+ configAttributes.put(entry.getKey(), entry.getValue());
}
}
if (!configAttributes.isEmpty()) {
try {
result = restTemplate.exchange(pdps.get(0) + "/api/" + resource, method, requestEntity, responseType);
} catch (HttpClientErrorException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while connecting to " + pdps.get(0), e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps.get(0), e);
exception = e;
} catch (Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while connecting to " + pdps.get(0), e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps.get(0), e);
exception = new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
if (result == null) {
break;
}
}
- if (exception != null && exception.getStatusCode() != null) {
- if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
- String message = XACMLErrorConstants.ERROR_PERMISSIONS + ":" + exception.getStatusCode() + ":"
- + ERROR_AUTH_GET_PERM + resource;
- LOGGER.error(message);
- throw new PolicyException(message, exception);
- }
- if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ":" + exception.getStatusCode() + ":"
- + exception.getResponseBodyAsString();
- LOGGER.error(message);
- throw new PolicyException(message, exception);
- }
- if (exception.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
- String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while connecting to " + pdps
- + exception;
- LOGGER.error(message);
- throw new PolicyException(message, exception);
- }
- String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + exception.getStatusCode() + ":"
+ if (exception == null || exception.getStatusCode() == null) {
+ return result;
+ }
+ if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
+ String message = XACMLErrorConstants.ERROR_PERMISSIONS + ":" + exception.getStatusCode() + ":"
+ + ERROR_AUTH_GET_PERM + resource;
+ LOGGER.error(message);
+ throw new PolicyException(message, exception);
+ }
+ if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
+ String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ":" + exception.getStatusCode() + ":"
+ exception.getResponseBodyAsString();
LOGGER.error(message);
throw new PolicyException(message, exception);
}
- return result;
+ if (exception.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
+ String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps
+ + exception;
+ LOGGER.error(message);
+ throw new PolicyException(message, exception);
+ }
+ String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + exception.getStatusCode() + ":"
+ + exception.getResponseBodyAsString();
+ LOGGER.error(message);
+ throw new PolicyException(message, exception);
}
private HttpHeaders getHeaders() {
headers.set("ClientAuth", "Basic " + clientEncoding);
headers.set("Authorization", "Basic " + encoding.get(0));
if (contentType != null) {
- headers.set("Content-Type", contentType.toString());
+ headers.set("Content-Type", contentType);
} else {
headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
}
return headers;
}
- private void setClientEncoding() {
+ private static void setClientEncoding() {
Base64.Encoder encoder = Base64.getEncoder();
clientEncoding = encoder.encodeToString((userName + ":" + pass).getBytes(StandardCharsets.UTF_8));
}
public Collection<PolicyResponse> sendEventImpl(Map<String, String> eventAttributes, UUID requestID)
throws PolicyEventException {
String resource = "sendEvent";
- ArrayList<PolicyResponse> response = new ArrayList<PolicyResponse>();
- String body = new String();
+ ArrayList<PolicyResponse> response;
+ String body = null;
// Create Request.
try {
// Long way here, can be shortened and will be done.
throw new PolicyEventException(message, exception);
}
if (exception.getCause().getMessage().contains("400")) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Data is given.";
+ String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
LOGGER.error(message);
throw new PolicyEventException(message, exception);
}
- String message = XACMLErrorConstants.ERROR_PERMISSIONS + "Unable to get valid Response from PDP(s) "
+ String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_INVALID_PDPS
+ pdps;
LOGGER.error(message, exception);
throw new PolicyEventException(message, exception);
return response;
}
- private ArrayList<PolicyResponse> eventResult(StdPolicyResponse[] response) throws PolicyEventException {
+ private ArrayList<PolicyResponse> eventResult(StdPolicyResponse[] response){
ArrayList<PolicyResponse> eventResult = new ArrayList<>();
if (response != null && response.length > 0) {
for (StdPolicyResponse policyConfigResponse : response) {
if (propertyFilePath == null) {
throw new PolicyEngineException(
XACMLErrorConstants.ERROR_DATA_ISSUE + "Error NO PropertyFile Path provided");
+ }
+
+ // Adding logic for remote Properties file.
+ Properties prop = new Properties();
+ if (propertyFilePath.startsWith("http")) {
+ URL configURL;
+ try {
+ configURL = new URL(propertyFilePath);
+ URLConnection connection;
+ connection = configURL.openConnection();
+ prop.load(connection.getInputStream());
+ } catch (IOException e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ throw new PolicyEngineException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL " + e.getMessage());
+ }
} else {
- // Adding logic for remote Properties file.
- Properties prop = new Properties();
- if (propertyFilePath.startsWith("http")) {
- URL configURL;
+ Path file = Paths.get(propertyFilePath);
+ if (!file.toFile().exists()) {
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "File doesn't exist in the specified Path " + file.toString());
+ }
+ if (file.toString().endsWith(".properties")) {
+ InputStream in;
+ prop = new Properties();
try {
- configURL = new URL(propertyFilePath);
- URLConnection connection = null;
- connection = configURL.openConnection();
- prop.load(connection.getInputStream());
+ in = new FileInputStream(file.toFile());
+ prop.load(in);
} catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
throw new PolicyEngineException(
- XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL " + e.getMessage());
+ XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e);
}
} else {
- Path file = Paths.get(propertyFilePath);
- if (Files.notExists(file)) {
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
- + "File doesn't exist in the specified Path " + file.toString());
- }
- if (file.toString().endsWith(".properties")) {
- InputStream in;
- prop = new Properties();
- try {
- in = new FileInputStream(file.toFile());
- prop.load(in);
- } catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
- throw new PolicyEngineException(
- XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e);
- }
- } else {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath);
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file");
- }
+ LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath);
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file");
}
- // UEB and DMAAP Settings
- String checkType = prop.getProperty("NOTIFICATION_TYPE");
- String serverList = prop.getProperty("NOTIFICATION_SERVERS");
- topic = prop.getProperty("NOTIFICATION_TOPIC");
- apiKey = prop.getProperty("UEB_API_KEY");
- apiSecret = prop.getProperty("UEB_API_SECRET");
-
- if (checkType == null) {
- notificationType.add(DEFAULT_NOTIFICATION);
- LOGGER.info(
- "Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets");
+ }
+ // UEB and DMAAP Settings
+ String checkType = prop.getProperty("NOTIFICATION_TYPE");
+ String serverList = prop.getProperty("NOTIFICATION_SERVERS");
+ topic = prop.getProperty("NOTIFICATION_TOPIC");
+ apiKey = prop.getProperty("UEB_API_KEY");
+ apiSecret = prop.getProperty("UEB_API_SECRET");
+
+ if (checkType == null) {
+ notificationType.add(DEFAULT_NOTIFICATION);
+ LOGGER.info(
+ "Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets");
+ } else {
+ checkType = checkType.trim();
+ if (checkType.contains(",")) {
+ notificationType = new ArrayList<>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(",")));
} else {
- checkType = checkType.trim();
- if (checkType.contains(",")) {
- typeDefault = new ArrayList<>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(",")));
- notificationType = typeDefault;
- } else {
- notificationType = new ArrayList<>();
- notificationType.add(checkType);
- }
+ notificationType = new ArrayList<>();
+ notificationType.add(checkType);
}
- if (serverList == null) {
- notificationType.clear();
- notificationType.add(DEFAULT_NOTIFICATION);
- LOGGER.info(
- "Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets");
+ }
+ if (serverList == null) {
+ notificationType.clear();
+ notificationType.add(DEFAULT_NOTIFICATION);
+ LOGGER.info(
+ "Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets");
+ } else {
+ serverList = serverList.trim();
+ if (serverList.contains(",")) {
+ notificationURLList = new ArrayList<>(Arrays.asList(serverList.split(",")));
} else {
- serverList = serverList.trim();
- if (serverList.contains(",")) {
- notificationURLList = new ArrayList<String>(Arrays.asList(serverList.split(",")));
- } else {
- notificationURLList = new ArrayList<>();
- notificationURLList.add(serverList);
- }
+ notificationURLList = new ArrayList<>();
+ notificationURLList.add(serverList);
}
+ }
- if (topic != null) {
- topic = topic.trim();
- } else {
- LOGGER.error("Properties file doesn't have the NOTIFICATION_TOPIC parameter.");
- }
+ if (topic != null) {
+ topic = topic.trim();
+ } else {
+ LOGGER.error("Properties file doesn't have the NOTIFICATION_TOPIC parameter.");
+ }
- // Client ID Authorization Settings.
- String clientID = prop.getProperty("CLIENT_ID");
- if (clientKey == null) {
- clientKey = prop.getProperty("CLIENT_KEY");
- try {
- clientKey = PolicyUtils.decode(clientKey);
- } catch (UnsupportedEncodingException | IllegalArgumentException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
- + " Cannot Decode the given Password Proceeding with given Password!!", e);
- }
- }
- if (clientID == null || clientKey == null || clientID.isEmpty() || clientKey.isEmpty()) {
+ // Client ID Authorization Settings.
+ String clientID = prop.getProperty("CLIENT_ID");
+ if (clientKey == null) {
+ clientKey = prop.getProperty("CLIENT_KEY");
+ try {
+ clientKey = PolicyUtils.decode(clientKey);
+ } catch (UnsupportedEncodingException | IllegalArgumentException e) {
LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
- + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_PERMISSIONS
- + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
- } else {
- setClientId(clientID.trim());
- setClientKey(clientKey.trim());
+ + " Cannot Decode the given Password Proceeding with given Password!!", e);
}
- setEnvironment(prop);
- // Initializing the values.
- init();
- // Check the Keys for PDP_URLs
- Collection<Object> unsorted = prop.keySet();
- @SuppressWarnings({ "rawtypes", "unchecked" })
- List<String> sorted = new ArrayList(unsorted);
- Collections.sort(sorted);
- for (String propKey : sorted) {
- if (propKey.startsWith("PDP_URL")) {
- String checkVal = prop.getProperty(propKey);
- if (checkVal == null) {
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
- + "Properties file doesn't have the PDP_URL parameter");
- }
- if (checkVal.contains(";")) {
- pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*")));
- int pdpCount = 0;
- while (pdpCount < pdpDefault.size()) {
- String pdpVal = pdpDefault.get(pdpCount);
- readPDPParam(pdpVal);
- pdpCount++;
- }
- } else {
- readPDPParam(checkVal);
+ }
+ if (clientID == null || clientKey == null || clientID.isEmpty() || clientKey.isEmpty()) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
+ + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_PERMISSIONS
+ + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
+ } else {
+ setClientId(clientID.trim());
+ setClientKey(clientKey.trim());
+ }
+ setEnvironment(prop);
+ // Initializing the values.
+ init();
+ // Check the Keys for PDP_URLs
+ Collection<Object> unsorted = prop.keySet();
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ List<String> sorted = new ArrayList(unsorted);
+ Collections.sort(sorted);
+ for (String propKey : sorted) {
+ if (propKey.startsWith("PDP_URL")) {
+ String checkVal = prop.getProperty(propKey);
+ if (checkVal == null) {
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "Properties file doesn't have the PDP_URL parameter");
+ }
+ if (checkVal.contains(";")) {
+ List<String> pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*")));
+ int pdpCount = 0;
+ while (pdpCount < pdpDefault.size()) {
+ String pdpVal = pdpDefault.get(pdpCount);
+ readPDPParam(pdpVal);
+ pdpCount++;
}
+ } else {
+ readPDPParam(checkVal);
}
}
- if (pdps == null || pdps.isEmpty()) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
- throw new PolicyEngineException(
- XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
- }
- // Get JUNIT property from properties file when running tests
- checkJunit(prop);
}
+ if (pdps == null || pdps.isEmpty()) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
+ throw new PolicyEngineException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
+ }
+ // Get JUNIT property from properties file when running tests
+ checkJunit(prop);
}
private static void checkJunit(Properties prop) {
if (junitFlag == null || junitFlag.isEmpty()) {
LOGGER.info("No JUNIT property provided, this will not be executed as a test.");
} else {
- if (junitFlag.equalsIgnoreCase("test")) {
+ if ("test".equalsIgnoreCase(junitFlag)) {
StdPolicyEngine.junit = true;
} else {
StdPolicyEngine.junit = false;
*/
private void readPDPParam(String pdpVal) throws PolicyEngineException {
if (pdpVal.contains(",")) {
- List<String> pdpValues = new ArrayList<String>(Arrays.asList(pdpVal.split("\\s*,\\s*")));
+ List<String> pdpValues = new ArrayList<>(Arrays.asList(pdpVal.split("\\s*,\\s*")));
if (pdpValues.size() == 3) {
// 0 - PDPURL
pdps.add(pdpValues.get(0));
// 1:2 will be UserID:Password
String userID = pdpValues.get(1);
- String pass = pdpValues.get(2);
+ String userPas = pdpValues.get(2);
Base64.Encoder encoder = Base64.getEncoder();
- encoding.add(encoder.encodeToString((userID + ":" + pass).getBytes(StandardCharsets.UTF_8)));
+ encoding.add(encoder.encodeToString((userID + ":" + userPas).getBytes(StandardCharsets.UTF_8)));
} else {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Credentials to send Request: " + pdpValues);
throw new PolicyEngineException(
LOGGER.debug("Scheme is : " + scheme.toString());
LOGGER.debug("Handler is : " + handler.getClass().getName());
- if (notificationType.get(0).equals("ueb")) {
+ if ("ueb".equals(notificationType.get(0))) {
if (this.uebThread) {
AutoClientUEB.setAuto(scheme, handler);
this.uebThread = registerUEBThread.isAlive();
}
- } else if (notificationType.get(0).equals("dmaap")) {
+ } else if (notificationType.get(0).equals(DMAAP)) {
if (this.dmaapThread) {
AutoClientDMAAP.setAuto(scheme, handler);
this.dmaapThread = registerDMAAPThread.isAlive();
}
if (pdps != null) {
- if (notificationType.get(0).equals("ueb") && !this.uebThread) {
+ if ("ueb".equals(notificationType.get(0)) && !this.uebThread) {
this.uebClientThread = new AutoClientUEB(pdps.get(0), notificationURLList, apiKey, apiSecret);
AutoClientUEB.setAuto(scheme, handler);
this.registerUEBThread = new Thread(this.uebClientThread);
this.registerUEBThread.start();
this.uebThread = true;
- } else if (notificationType.get(0).equals("dmaap") && !this.dmaapThread) {
+ } else if (notificationType.get(0).equals(DMAAP) && !this.dmaapThread) {
this.dmaapClientThread = new AutoClientDMAAP(notificationURLList, topic, userName, pass);
AutoClientDMAAP.setAuto(scheme, handler);
this.registerDMAAPThread = new Thread(this.dmaapClientThread);
*/
public PDPNotification getNotification() {
// Check if there is proper scheme..
- PDPNotification notification = null;
+ PDPNotification notification;
if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)
|| this.scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
if (notificationType.get(0).equals("ueb")) {
ManualClientEndUEB.start(pdps.get(0), notificationURLList, UNIQUEID);
notification = ManualClientEndUEB.result(scheme);
- } else if (notificationType.get(0).equals("dmaap")) {
+ } else if (notificationType.get(0).equals(DMAAP)) {
ManualClientEndDMAAP.start(notificationURLList, topic, UNIQUEID, userName, pass);
notification = ManualClientEndDMAAP.result(scheme);
} else {
if (notification == null) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Notification yet..");
return null;
- } else {
- return notification;
}
- } else {
- return null;
+ return notification;
}
+ return null;
}
/*
*/
public void setScheme(NotificationScheme scheme) {
this.scheme = scheme;
- if (notificationType.get(0).equals("ueb")) {
+ if ("ueb".equals(notificationType.get(0))) {
AutoClientUEB.setScheme(this.scheme);
if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
ManualClientEndUEB.createTopic(pdps.get(0), UNIQUEID, notificationURLList);
}
- } else if (notificationType.get(0).equals("dmaap")) {
+ } else if (notificationType.get(0).equals(DMAAP)) {
AutoClientDMAAP.setScheme(this.scheme);
if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
ManualClientEndDMAAP.createTopic(topic, UNIQUEID, notificationURLList, userName, pass);
* Stop the Notification Service if its running.
*/
public void stopNotification() {
- if (this.scheme != null && this.handler != null) {
- if (this.scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)
- || this.scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
- LOGGER.info("Clear Notification called.. ");
- if (notificationType.get(0).equals("ueb")) {
- this.uebClientThread.terminate();
- this.uebThread = false;
- } else if (notificationType.get(0).equals("dmaap")) {
- this.dmaapClientThread.terminate();
- this.dmaapThread = false;
- } else {
- AutoClientEnd.stop();
- }
+ if (this.scheme != null && this.handler != null && (this.scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)
+ || this.scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS))) {
+ LOGGER.info("Clear Notification called.. ");
+ if ("ueb".equals(notificationType.get(0))) {
+ this.uebClientThread.terminate();
+ this.uebThread = false;
+ } else if (notificationType.get(0).equals(DMAAP)) {
+ this.dmaapClientThread.terminate();
+ this.dmaapThread = false;
+ } else {
+ AutoClientEnd.stop();
}
}
}
policyParameters.setPolicyDescription(policyDescription);
policyParameters.setOnapName(onapName);
policyParameters.setConfigName(configName);
- Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>();
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.MATCHING, configAttributes);
policyParameters.setAttributes(attributes);
policyParameters.setConfigBodyType(PolicyType.valueOf(configType));
try {
policyParameters.setTtlDate(new SimpleDateFormat("dd-MM-yyyy").parse(ttlDate));
} catch (NullPointerException | ParseException e) {
- LOGGER.warn("Error Parsing date given " + ttlDate);
+ LOGGER.warn("Error Parsing date given " + ttlDate, e);
policyParameters.setTtlDate(null);
}
return createUpdatePolicyImpl(policyParameters, updateFlag).getResponseMessage();
}
- public void setClientKey(String clientKey) {
+ public static void setClientKey(String clientKey) {
if (clientKey != null && !clientKey.isEmpty()) {
StdPolicyEngine.pass = clientKey;
setClientEncoding();