2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.std;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.StringReader;
27 import java.io.UnsupportedEncodingException;
29 import java.net.URLConnection;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.text.ParseException;
34 import java.text.SimpleDateFormat;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.Base64;
38 import java.util.Collection;
39 import java.util.Collections;
40 import java.util.HashMap;
41 import java.util.List;
43 import java.util.Properties;
44 import java.util.UUID;
46 import javax.json.Json;
47 import javax.json.JsonObject;
48 import javax.json.JsonReader;
49 import javax.xml.parsers.DocumentBuilder;
50 import javax.xml.parsers.DocumentBuilderFactory;
52 import org.onap.policy.api.AttributeType;
53 import org.onap.policy.api.ConfigRequestParameters;
54 import org.onap.policy.api.DecisionRequestParameters;
55 import org.onap.policy.api.DecisionResponse;
56 import org.onap.policy.api.DeletePolicyParameters;
57 import org.onap.policy.api.DictionaryParameters;
58 import org.onap.policy.api.DictionaryResponse;
59 import org.onap.policy.api.EventRequestParameters;
60 import org.onap.policy.api.ImportParameters;
61 import org.onap.policy.api.MetricsRequestParameters;
62 import org.onap.policy.api.MetricsResponse;
63 import org.onap.policy.api.NotificationHandler;
64 import org.onap.policy.api.NotificationScheme;
65 import org.onap.policy.api.PDPNotification;
66 import org.onap.policy.api.PolicyChangeResponse;
67 import org.onap.policy.api.PolicyClass;
68 import org.onap.policy.api.PolicyConfig;
69 import org.onap.policy.api.PolicyConfigException;
70 import org.onap.policy.api.PolicyConfigType;
71 import org.onap.policy.api.PolicyDecisionException;
72 import org.onap.policy.api.PolicyEngineException;
73 import org.onap.policy.api.PolicyEventException;
74 import org.onap.policy.api.PolicyException;
75 import org.onap.policy.api.PolicyParameters;
76 import org.onap.policy.api.PolicyResponse;
77 import org.onap.policy.api.PolicyType;
78 import org.onap.policy.api.PushPolicyParameters;
79 import org.onap.policy.common.logging.flexlogger.FlexLogger;
80 import org.onap.policy.common.logging.flexlogger.Logger;
81 import org.onap.policy.models.APIDictionaryResponse;
82 import org.onap.policy.models.APIPolicyConfigResponse;
83 import org.onap.policy.utils.AAFEnvironment;
84 import org.onap.policy.utils.PolicyUtils;
85 import org.onap.policy.xacml.api.XACMLErrorConstants;
86 import org.springframework.core.io.FileSystemResource;
87 import org.springframework.http.HttpEntity;
88 import org.springframework.http.HttpHeaders;
89 import org.springframework.http.HttpMethod;
90 import org.springframework.http.HttpStatus;
91 import org.springframework.http.MediaType;
92 import org.springframework.http.ResponseEntity;
93 import org.springframework.util.LinkedMultiValueMap;
94 import org.springframework.web.client.HttpClientErrorException;
95 import org.springframework.web.client.RestTemplate;
96 import org.xml.sax.InputSource;
98 import com.fasterxml.jackson.core.JsonProcessingException;
99 import com.google.gson.Gson;
100 import com.google.gson.GsonBuilder;
103 * PolicyEngine Implementation class
107 public class StdPolicyEngine {
108 private static final String ERROR_AUTH_GET_PERM = "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to: ";
109 private static final String DEFAULT_NOTIFICATION = "websocket";
110 private static final String ERROR_DATA_ISSUE = "Invalid Data is given.";
111 private static final String DMAAP = "dmaap";
112 private static final String ERROR_INVALID_PDPS = "Unable to get valid Response from PDP(s) ";
113 private static final String ERROR_WHILE_CONNECTING = "Error while connecting to ";
115 private static String clientEncoding = null;
116 private String contentType = null;
117 private static List<String> pdps = null;
118 private static String environment = null;
119 private static String userName = null;
120 private static String pass = null;
121 private static List<String> encoding = null;
122 private static boolean junit = false;
123 private List<String> notificationType = new ArrayList<>();
124 private List<String> notificationURLList = new ArrayList<>();
125 private NotificationScheme scheme = null;
126 private NotificationHandler handler = null;
127 private AutoClientUEB uebClientThread = null;
128 private Thread registerUEBThread = null;
129 private boolean uebThread = false;
130 private AutoClientDMAAP dmaapClientThread = null;
131 private Thread registerDMAAPThread = null;
132 private boolean dmaapThread = false;
133 private String topic = null;
134 private String apiKey = null;
135 private String apiSecret = null;
137 private static final String UNIQUEID = UUID.randomUUID().toString();
138 private static final Logger LOGGER = FlexLogger.getLogger(StdPolicyConfig.class.getName());
141 * Taking the Property file even if it null.
143 public StdPolicyEngine(String propertyFilePath, String clientKey) throws PolicyEngineException {
144 setProperty(propertyFilePath, clientKey);
148 * Taking the Notification Constructor.
150 public StdPolicyEngine(String propertyFilePath, NotificationScheme scheme, NotificationHandler handler)
151 throws PolicyEngineException {
152 setProperty(propertyFilePath, null);
153 this.scheme = scheme;
154 this.handler = handler;
155 if ((!"ueb".equals(notificationType.get(0))) || (!DMAAP.equals(notificationType.get(0)))) {
156 AutoClientEnd.setAuto(scheme, handler);
158 notification(scheme, handler);
162 * Taking the Notification Constructor.
164 public StdPolicyEngine(String propertyFilePath, NotificationScheme scheme) throws PolicyEngineException {
165 setProperty(propertyFilePath, null);
166 this.scheme = scheme;
171 * sendEvent API Implementation
173 public Collection<PolicyResponse> sendEvent(Map<String, String> eventAttributes, UUID requestID)
174 throws PolicyEventException {
175 return sendEventImpl(eventAttributes, requestID);
179 * sendEvent API Implementation for eventRequestParameters
181 public Collection<PolicyResponse> sendEvent(EventRequestParameters eventRequestParameters)
182 throws PolicyEventException {
183 if (eventRequestParameters == null) {
184 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No event Request Parameters Given. ";
185 LOGGER.error(message);
186 throw new PolicyEventException(message);
188 return sendEventImpl(eventRequestParameters.getEventAttributes(), eventRequestParameters.getRequestID());
192 * getConfig using configRequestParameters Implementation
194 public Collection<PolicyConfig> getConfig(ConfigRequestParameters configRequestParameters)
195 throws PolicyConfigException {
196 return getConfigImpl(configRequestParameters);
200 * listPolicies using configRequestParameters Implementation
202 public Collection<String> listConfig(ConfigRequestParameters listPolicyRequestParameters)
203 throws PolicyConfigException {
204 return listConfigImpl(listPolicyRequestParameters);
208 * getDecision using the decision Attributes.
210 public DecisionResponse getDecision(String onapName, Map<String, String> decisionAttributes, UUID requestID)
211 throws PolicyDecisionException {
212 return getDecisionImpl(onapName, decisionAttributes, requestID);
216 * getDecision Using decisionRequestParameters.
218 public DecisionResponse getDecision(DecisionRequestParameters decisionRequestParameters)
219 throws PolicyDecisionException {
220 if (decisionRequestParameters == null) {
221 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Decision Request Parameters Given. ";
222 LOGGER.error(message);
223 throw new PolicyDecisionException(message);
225 return getDecisionImpl(decisionRequestParameters.getOnapName(),
226 decisionRequestParameters.getDecisionAttributes(), decisionRequestParameters.getRequestID());
230 * getMetrics using metricsRequestParameters
232 public MetricsResponse getMetrics(MetricsRequestParameters parameters) throws PolicyException {
233 return getMetricsImpl(parameters);
236 public MetricsResponse getMetricsImpl(MetricsRequestParameters parameters) throws PolicyException {
237 StdMetricsResponse response = new StdMetricsResponse();
238 String resource = "getMetrics";
240 // Create the Request
242 if (parameters != null) {
243 body = PolicyUtils.objectToJsonString(parameters);
245 } catch (JsonProcessingException e) {
246 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
247 LOGGER.error(message);
248 throw new PolicyException(message, e);
252 ResponseEntity<String> result = callNewPDP(resource, HttpMethod.GET, body, String.class);
254 response.setResponseMessage(result.getBody());
255 response.setResponseCode(result.getStatusCode().value());
256 } catch (PolicyException exception) {
257 if (exception.getCause() != null && exception.getCause() instanceof HttpClientErrorException) {
258 LOGGER.error(exception);
259 HttpClientErrorException ex = (HttpClientErrorException) exception.getCause();
260 response.setResponseCode(ex.getRawStatusCode());
261 response.setResponseMessage(exception.getMessage());
264 String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR
265 + "Error while processing results. please check logs.";
266 LOGGER.error(message, exception);
267 throw new PolicyException(message, exception);
274 * PushPolicy using pushPolicyParameters.
276 public PolicyChangeResponse pushPolicy(PushPolicyParameters pushPolicyParameters) throws PolicyException {
277 return pushPolicyImpl(pushPolicyParameters);
280 public PolicyChangeResponse pushPolicyImpl(PushPolicyParameters pushPolicyParameters) throws PolicyException {
281 StdPolicyChangeResponse response = new StdPolicyChangeResponse();
282 String resource = "pushPolicy";
286 body = PolicyUtils.objectToJsonString(pushPolicyParameters);
287 } catch (JsonProcessingException e) {
288 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
289 LOGGER.error(message);
290 throw new PolicyException(message, e);
294 ResponseEntity<String> result = callNewPDP(resource, HttpMethod.PUT, body, String.class);
296 response.setResponseMessage(result.getBody());
297 response.setResponseCode(result.getStatusCode().value());
298 } catch (PolicyException exception) {
299 return processException(exception);
305 * Delete a Policy using deletePolicyParameters
307 public PolicyChangeResponse deletePolicy(DeletePolicyParameters parameters) throws PolicyException {
308 return deletePolicyImpl(parameters);
311 public PolicyChangeResponse deletePolicyImpl(DeletePolicyParameters parameters) throws PolicyException {
312 StdPolicyChangeResponse response = new StdPolicyChangeResponse();
313 String resource = "deletePolicy";
317 body = PolicyUtils.objectToJsonString(parameters);
318 } catch (JsonProcessingException e) {
319 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
320 LOGGER.error(message);
321 throw new PolicyException(message, e);
325 ResponseEntity<String> result = callNewPDP(resource, HttpMethod.DELETE, body, String.class);
327 response.setResponseMessage(result.getBody());
328 response.setResponseCode(result.getStatusCode().value());
329 } catch (PolicyException exception) {
330 return processException(exception);
336 * getDictionaryItem Using dictionaryParameters
338 public DictionaryResponse getDictionaryItem(DictionaryParameters parameters) throws PolicyException {
339 return getDictionaryItemImpl(parameters);
342 public DictionaryResponse getDictionaryItemImpl(DictionaryParameters parameters) throws PolicyException {
343 StdDictionaryResponse response = new StdDictionaryResponse();
344 String resource = "getDictionaryItems";
348 body = PolicyUtils.objectToJsonString(parameters);
349 } catch (JsonProcessingException e) {
350 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
351 LOGGER.error(message);
352 throw new PolicyException(message, e);
356 ResponseEntity<APIDictionaryResponse> result = callNewPDP(resource, HttpMethod.POST, body,
357 APIDictionaryResponse.class);
359 response = dictionaryResult(result.getBody());
360 } catch (Exception exception) {
361 if (exception.getCause().getMessage().contains("401")) {
362 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_AUTH_GET_PERM + resource;
363 LOGGER.error(message);
364 response.setResponseMessage(message);
365 response.setResponseCode(401);
368 if (exception.getCause().getMessage().contains("400")) {
369 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
370 response.setResponseMessage(message);
371 response.setResponseCode(400);
374 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_INVALID_PDPS
376 LOGGER.error(message, exception);
377 response.setResponseMessage(message);
378 response.setResponseCode(500);
384 @SuppressWarnings("unchecked")
385 private StdDictionaryResponse dictionaryResult(APIDictionaryResponse body) {
386 StdDictionaryResponse response = new StdDictionaryResponse();
387 response.setResponseCode(body.getResponseCode());
388 response.setResponseMessage(body.getResponseMessage());
389 response.setDictionaryData((Map<String, String>) body.getDictionaryData());
390 if (body.getDictionaryJson() != null) {
391 Gson objGson = new GsonBuilder().create();
392 String mapToJson = objGson.toJson(body.getDictionaryJson());
393 JsonReader jsonReader = Json.createReader(new StringReader(mapToJson));
394 JsonObject object = jsonReader.readObject();
396 response.setDictionaryJson(object);
402 * createDictinaryItem Using dictionaryParameters.
404 public PolicyChangeResponse createDictionaryItem(DictionaryParameters parameters) throws PolicyException {
405 return createUpdateDictionaryItemImpl(parameters, false);
409 * updateDictinaryItem Using dictionaryParameters.
411 public PolicyChangeResponse updateDictionaryItem(DictionaryParameters parameters) throws PolicyException {
412 return createUpdateDictionaryItemImpl(parameters, true);
415 public PolicyChangeResponse createUpdateDictionaryItemImpl(DictionaryParameters parameters, boolean updateFlag)
416 throws PolicyException {
417 StdPolicyChangeResponse response = new StdPolicyChangeResponse();
418 String resource = "createDictionaryItem";
420 resource = "updateDictionaryItem";
425 body = PolicyUtils.objectToJsonString(parameters);
426 } catch (JsonProcessingException e) {
427 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
428 LOGGER.error(message);
429 throw new PolicyException(message, e);
433 ResponseEntity<String> result = callNewPDP(resource, HttpMethod.PUT, body, String.class);
435 response.setResponseMessage(result.getBody());
436 response.setResponseCode(result.getStatusCode().value());
437 } catch (PolicyException exception) {
438 return processException(exception);
444 * PolicyEngine Import
446 public PolicyChangeResponse policyEngineImport(ImportParameters importParameters) throws PolicyException {
447 return policyEngineImportImpl(importParameters);
450 public PolicyChangeResponse policyEngineImportImpl(ImportParameters importParameters) throws PolicyException {
451 StdPolicyChangeResponse response = new StdPolicyChangeResponse();
452 String resource = "policyEngineImport";
453 LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
456 String body = PolicyUtils.objectToJsonString(importParameters);
457 parameters.set("importParametersJson", body);
458 parameters.set("file", new FileSystemResource(importParameters.getFilePath()));
459 } catch (Exception e) {
460 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
461 LOGGER.error(message);
462 throw new PolicyException(message, e);
464 contentType = MediaType.MULTIPART_FORM_DATA_VALUE;
467 ResponseEntity<String> result = callNewPDP(resource, HttpMethod.POST, parameters, String.class);
469 response.setResponseMessage(result.getBody());
470 response.setResponseCode(result.getStatusCode().value());
471 } catch (PolicyException exception) {
472 return processException(exception);
480 * createPolicy Using policyParameters.
482 public PolicyChangeResponse createPolicy(PolicyParameters policyParameters) throws PolicyException {
483 return createUpdatePolicyImpl(policyParameters, false);
487 * updatePolicy using policyParameters.
489 public PolicyChangeResponse updatePolicy(PolicyParameters policyParameters) throws PolicyException {
490 return createUpdatePolicyImpl(policyParameters, true);
493 public PolicyChangeResponse createUpdatePolicyImpl(PolicyParameters policyParameters, boolean updateFlag)
494 throws PolicyException {
495 StdPolicyChangeResponse response = new StdPolicyChangeResponse();
496 String resource = "createPolicy";
498 resource = "updatePolicy";
503 body = PolicyUtils.objectToJsonString(policyParameters);
504 } catch (JsonProcessingException e) {
505 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
506 LOGGER.error(message);
507 throw new PolicyException(message, e);
511 ResponseEntity<String> result = callNewPDP(resource, HttpMethod.PUT, body, String.class);
513 response.setResponseMessage(result.getBody());
514 response.setResponseCode(result.getStatusCode().value());
515 } catch (PolicyException exception) {
516 return processException(exception);
521 private PolicyChangeResponse processException(PolicyException exception) throws PolicyException {
522 StdPolicyChangeResponse response = new StdPolicyChangeResponse();
523 if (exception.getCause() != null && exception.getCause() instanceof HttpClientErrorException) {
524 LOGGER.error(exception);
525 HttpClientErrorException ex = (HttpClientErrorException) exception.getCause();
526 response.setResponseCode(ex.getRawStatusCode());
527 response.setResponseMessage(exception.getMessage());
530 String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR
531 + "Error while processing results. please check logs.";
532 LOGGER.error(message, exception);
533 throw new PolicyException(message, exception);
537 public DecisionResponse getDecisionImpl(String onapName, Map<String, String> decisionAttributes, UUID requestID)
538 throws PolicyDecisionException {
539 String resource = "getDecision";
540 StdDecisionResponse response = new StdDecisionResponse();
544 DecisionRequestParameters decisionRequestParameters = new DecisionRequestParameters();
545 decisionRequestParameters.setDecisionAttributes(decisionAttributes);
546 decisionRequestParameters.setOnapName(onapName);
547 decisionRequestParameters.setRequestID(requestID);
548 body = PolicyUtils.objectToJsonString(decisionRequestParameters);
549 } catch (JsonProcessingException e) {
550 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
551 LOGGER.error(message);
552 throw new PolicyDecisionException(message, e);
556 ResponseEntity<StdDecisionResponse> result = callNewPDP(resource, HttpMethod.POST, body,
557 StdDecisionResponse.class);
559 response = result.getBody();
560 } catch (Exception exception) {
561 if (exception.getCause().getMessage().contains("401")) {
562 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_AUTH_GET_PERM + resource;
563 LOGGER.error(message);
564 throw new PolicyDecisionException(message, exception);
566 if (exception.getCause().getMessage().contains("400")) {
567 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
568 LOGGER.error(message);
569 throw new PolicyDecisionException(message, exception);
571 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_INVALID_PDPS
573 LOGGER.error(message, exception);
574 throw new PolicyDecisionException(message, exception);
579 public Collection<PolicyConfig> getConfigImpl(ConfigRequestParameters configRequestParameters)
580 throws PolicyConfigException {
581 String resource = "getConfig";
582 ArrayList<PolicyConfig> response = null;
586 body = PolicyUtils.objectToJsonString(configRequestParameters);
587 } catch (JsonProcessingException e) {
588 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
589 LOGGER.error(message);
590 throw new PolicyConfigException(message, e);
594 ResponseEntity<APIPolicyConfigResponse[]> result = callNewPDP(resource, HttpMethod.POST, body,
595 APIPolicyConfigResponse[].class);
597 response = configResult(result.getBody());
598 } catch (Exception exception) {
599 if (exception.getCause().getMessage().contains("401")) {
600 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_AUTH_GET_PERM + resource;
601 LOGGER.error(message);
602 throw new PolicyConfigException(message, exception);
604 if (exception.getCause().getMessage().contains("400")) {
605 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
606 LOGGER.error(message);
607 throw new PolicyConfigException(message, exception);
609 String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_INVALID_PDPS
611 LOGGER.error(message, exception);
612 throw new PolicyConfigException(message, exception);
617 private ArrayList<PolicyConfig> configResult(APIPolicyConfigResponse[] response) throws PolicyConfigException {
618 ArrayList<PolicyConfig> result = new ArrayList<>();
619 if (response != null && response.length > 0) {
620 for (APIPolicyConfigResponse policyConfigResponse : response) {
621 StdPolicyConfig policyConfig = new StdPolicyConfig();
622 policyConfig.setConfigStatus(policyConfigResponse.getPolicyConfigMessage());
623 policyConfig.setMatchingConditions(policyConfigResponse.getMatchingConditions());
624 policyConfig.setPolicyConfigStatus(policyConfigResponse.getPolicyConfigStatus());
625 policyConfig.setPolicyName(policyConfigResponse.getPolicyName());
626 policyConfig.setPolicyType(policyConfigResponse.getType());
627 policyConfig.setPolicyVersion(policyConfigResponse.getPolicyVersion());
628 policyConfig.setResponseAttributes(policyConfigResponse.getResponseAttributes());
629 setMatches(policyConfig.getMatchingConditions());
630 if (policyConfigResponse.getType() != null) {
632 switch (policyConfigResponse.getType()) {
634 JsonReader jsonReader = Json
635 .createReader(new StringReader(policyConfigResponse.getConfig()));
636 JsonObject object = jsonReader.readObject();
638 policyConfig.setJsonObject(object);
641 policyConfig.setOther(policyConfigResponse.getConfig());
644 Properties props = new Properties();
645 props.putAll(policyConfigResponse.getProperty());
646 policyConfig.setProperties(props);
649 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
650 DocumentBuilder builder;
651 builder = factory.newDocumentBuilder();
652 policyConfig.setDocument(builder
653 .parse(new InputSource(new StringReader(policyConfigResponse.getConfig()))));
656 } catch (Exception e) {
657 LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e);
658 throw new PolicyConfigException(
659 XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Unable to parse the config", e);
662 result.add(policyConfig);
668 private void setMatches(Map<String, String> matchingConditions) {
669 Matches match = new Matches();
670 HashMap<String, String> configAttributes = new HashMap<>();
672 for (Map.Entry<String,String> entry : matchingConditions.entrySet()) {
673 if (entry.getKey().equalsIgnoreCase("ONAPName")) {
674 match.setOnapName(entry.getValue());
675 } else if (entry.getKey().equalsIgnoreCase("ConfigName")) {
676 match.setConfigName(entry.getValue());
678 configAttributes.put(entry.getKey(), entry.getValue());
681 if (!configAttributes.isEmpty()) {
682 match.setConfigAttributes(configAttributes);
684 MatchStore.storeMatch(match);
685 } catch (Exception e) {
686 LOGGER.error("StoreMatch failed for Onap:" + match.getOnapName() + " Config: " + match.getConfigName(), e);
691 * Generic Rest Client to call PDP services.
693 private <T> ResponseEntity<T> callNewPDP(String resource, HttpMethod method, Object body, Class<T> responseType)
694 throws PolicyException {
695 RestTemplate restTemplate = new RestTemplate();
696 HttpEntity<?> requestEntity = new HttpEntity<>(body, getHeaders());
697 ResponseEntity<T> result = null;
698 HttpClientErrorException exception = null;
700 while (pdpsCount < pdps.size()) {
702 result = restTemplate.exchange(pdps.get(0) + "/api/" + resource, method, requestEntity, responseType);
703 } catch (HttpClientErrorException e) {
704 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps.get(0), e);
706 } catch (Exception e) {
707 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps.get(0), e);
708 exception = new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
710 if (result == null) {
711 Collections.rotate(pdps, -1);
712 Collections.rotate(encoding, -1);
718 if (exception != null && exception.getStatusCode() != null) {
719 if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
720 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ":" + exception.getStatusCode() + ":"
721 + ERROR_AUTH_GET_PERM + resource;
722 LOGGER.error(message);
723 throw new PolicyException(message, exception);
725 if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
726 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ":" + exception.getStatusCode() + ":"
727 + exception.getResponseBodyAsString();
728 LOGGER.error(message);
729 throw new PolicyException(message, exception);
731 if (exception.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
732 String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps
734 LOGGER.error(message);
735 throw new PolicyException(message, exception);
737 String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + exception.getStatusCode() + ":"
738 + exception.getResponseBodyAsString();
739 LOGGER.error(message);
740 throw new PolicyException(message, exception);
745 private HttpHeaders getHeaders() {
746 HttpHeaders headers = new HttpHeaders();
747 headers.set("ClientAuth", "Basic " + clientEncoding);
748 headers.set("Authorization", "Basic " + encoding.get(0));
749 if (contentType != null) {
750 headers.set("Content-Type", contentType);
752 headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
754 headers.set("Environment", environment);
758 private static void setClientEncoding() {
759 Base64.Encoder encoder = Base64.getEncoder();
760 clientEncoding = encoder.encodeToString((userName + ":" + pass).getBytes(StandardCharsets.UTF_8));
763 public Collection<String> listConfigImpl(ConfigRequestParameters listRequestParameters)
764 throws PolicyConfigException {
765 Collection<String> policyList = new ArrayList<>();
767 policyList.add("Policy Name: listConfigTest");
770 Collection<PolicyConfig> policyConfig = getConfigImpl(listRequestParameters);
771 for (PolicyConfig policy : policyConfig) {
772 if (policy.getPolicyConfigMessage() != null && policy.getPolicyConfigMessage().contains("PE300")) {
773 policyList.add(policy.getPolicyConfigMessage());
775 policyList.add("Policy Name: " + policy.getPolicyName());
781 public Collection<PolicyResponse> sendEventImpl(Map<String, String> eventAttributes, UUID requestID)
782 throws PolicyEventException {
783 String resource = "sendEvent";
784 ArrayList<PolicyResponse> response = null;
788 // Long way here, can be shortened and will be done.
789 EventRequestParameters eventRequestParameters = new EventRequestParameters();
790 eventRequestParameters.setEventAttributes(eventAttributes);
791 eventRequestParameters.setRequestID(requestID);
792 body = PolicyUtils.objectToJsonString(eventRequestParameters);
793 } catch (JsonProcessingException e) {
794 String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + e;
795 LOGGER.error(message);
796 throw new PolicyEventException(message, e);
800 ResponseEntity<StdPolicyResponse[]> result = callNewPDP(resource, HttpMethod.POST, body,
801 StdPolicyResponse[].class);
803 response = eventResult(result.getBody());
804 } catch (Exception exception) {
805 if (exception.getCause().getMessage().contains("401")) {
806 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_AUTH_GET_PERM + resource;
807 LOGGER.error(message);
808 throw new PolicyEventException(message, exception);
810 if (exception.getCause().getMessage().contains("400")) {
811 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ERROR_DATA_ISSUE;
812 LOGGER.error(message);
813 throw new PolicyEventException(message, exception);
815 String message = XACMLErrorConstants.ERROR_PERMISSIONS + ERROR_INVALID_PDPS
817 LOGGER.error(message, exception);
818 throw new PolicyEventException(message, exception);
823 private ArrayList<PolicyResponse> eventResult(StdPolicyResponse[] response){
824 ArrayList<PolicyResponse> eventResult = new ArrayList<>();
825 if (response != null && response.length > 0) {
826 for (StdPolicyResponse policyConfigResponse : response) {
827 eventResult.add(policyConfigResponse);
833 private void setProperty(String propertyFilePath, String clientKey) throws PolicyEngineException {
834 if (propertyFilePath == null) {
835 throw new PolicyEngineException(
836 XACMLErrorConstants.ERROR_DATA_ISSUE + "Error NO PropertyFile Path provided");
838 // Adding logic for remote Properties file.
839 Properties prop = new Properties();
840 if (propertyFilePath.startsWith("http")) {
843 configURL = new URL(propertyFilePath);
844 URLConnection connection = null;
845 connection = configURL.openConnection();
846 prop.load(connection.getInputStream());
847 } catch (IOException e) {
848 LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
849 throw new PolicyEngineException(
850 XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL " + e.getMessage());
853 Path file = Paths.get(propertyFilePath);
854 if (!file.toFile().exists()) {
855 throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
856 + "File doesn't exist in the specified Path " + file.toString());
858 if (file.toString().endsWith(".properties")) {
860 prop = new Properties();
862 in = new FileInputStream(file.toFile());
864 } catch (IOException e) {
865 LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
866 throw new PolicyEngineException(
867 XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e);
870 LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath);
871 throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file");
874 // UEB and DMAAP Settings
875 String checkType = prop.getProperty("NOTIFICATION_TYPE");
876 String serverList = prop.getProperty("NOTIFICATION_SERVERS");
877 topic = prop.getProperty("NOTIFICATION_TOPIC");
878 apiKey = prop.getProperty("UEB_API_KEY");
879 apiSecret = prop.getProperty("UEB_API_SECRET");
881 if (checkType == null) {
882 notificationType.add(DEFAULT_NOTIFICATION);
884 "Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets");
886 checkType = checkType.trim();
887 if (checkType.contains(",")) {
888 notificationType = new ArrayList<>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(",")));
890 notificationType = new ArrayList<>();
891 notificationType.add(checkType);
894 if (serverList == null) {
895 notificationType.clear();
896 notificationType.add(DEFAULT_NOTIFICATION);
898 "Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets");
900 serverList = serverList.trim();
901 if (serverList.contains(",")) {
902 notificationURLList = new ArrayList<>(Arrays.asList(serverList.split(",")));
904 notificationURLList = new ArrayList<>();
905 notificationURLList.add(serverList);
910 topic = topic.trim();
912 LOGGER.error("Properties file doesn't have the NOTIFICATION_TOPIC parameter.");
915 // Client ID Authorization Settings.
916 String clientID = prop.getProperty("CLIENT_ID");
917 if (clientKey == null) {
918 clientKey = prop.getProperty("CLIENT_KEY");
920 clientKey = PolicyUtils.decode(clientKey);
921 } catch (UnsupportedEncodingException | IllegalArgumentException e) {
922 LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
923 + " Cannot Decode the given Password Proceeding with given Password!!", e);
926 if (clientID == null || clientKey == null || clientID.isEmpty() || clientKey.isEmpty()) {
927 LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
928 + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
929 throw new PolicyEngineException(XACMLErrorConstants.ERROR_PERMISSIONS
930 + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
932 setClientId(clientID.trim());
933 setClientKey(clientKey.trim());
935 setEnvironment(prop);
936 // Initializing the values.
938 // Check the Keys for PDP_URLs
939 Collection<Object> unsorted = prop.keySet();
940 @SuppressWarnings({ "rawtypes", "unchecked" })
941 List<String> sorted = new ArrayList(unsorted);
942 Collections.sort(sorted);
943 for (String propKey : sorted) {
944 if (propKey.startsWith("PDP_URL")) {
945 String checkVal = prop.getProperty(propKey);
946 if (checkVal == null) {
947 throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
948 + "Properties file doesn't have the PDP_URL parameter");
950 if (checkVal.contains(";")) {
951 List<String> pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*")));
953 while (pdpCount < pdpDefault.size()) {
954 String pdpVal = pdpDefault.get(pdpCount);
955 readPDPParam(pdpVal);
959 readPDPParam(checkVal);
963 if (pdps == null || pdps.isEmpty()) {
964 LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
965 throw new PolicyEngineException(
966 XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
968 // Get JUNIT property from properties file when running tests
973 private static void checkJunit(Properties prop) {
974 String junitFlag = prop.getProperty("JUNIT");
975 if (junitFlag == null || junitFlag.isEmpty()) {
976 LOGGER.info("No JUNIT property provided, this will not be executed as a test.");
978 if (junitFlag.equalsIgnoreCase("test")) {
979 StdPolicyEngine.junit = true;
981 StdPolicyEngine.junit = false;
986 private static void init() {
987 pdps = new ArrayList<>();
988 encoding = new ArrayList<>();
991 private static void setEnvironment(Properties prop) {
992 environment = prop.getProperty("ENVIRONMENT", AAFEnvironment.DEVL.toString());
993 if (environment.equalsIgnoreCase(AAFEnvironment.TEST.toString())) {
994 environment = AAFEnvironment.TEST.toString();
995 } else if (environment.equalsIgnoreCase(AAFEnvironment.PROD.toString())) {
996 environment = AAFEnvironment.PROD.toString();
998 environment = AAFEnvironment.DEVL.toString();
1002 private static void setClientId(String clientID) {
1003 userName = clientID;
1007 * Read the PDP_URL parameter
1009 private void readPDPParam(String pdpVal) throws PolicyEngineException {
1010 if (pdpVal.contains(",")) {
1011 List<String> pdpValues = new ArrayList<>(Arrays.asList(pdpVal.split("\\s*,\\s*")));
1012 if (pdpValues.size() == 3) {
1014 pdps.add(pdpValues.get(0));
1015 // 1:2 will be UserID:Password
1016 String userID = pdpValues.get(1);
1017 String userPas = pdpValues.get(2);
1018 Base64.Encoder encoder = Base64.getEncoder();
1019 encoding.add(encoder.encodeToString((userID + ":" + userPas).getBytes(StandardCharsets.UTF_8)));
1021 LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Credentials to send Request: " + pdpValues);
1022 throw new PolicyEngineException(
1023 XACMLErrorConstants.ERROR_DATA_ISSUE + "No enough Credentials to send Request. " + pdpValues);
1027 XACMLErrorConstants.ERROR_DATA_ISSUE + "PDP value is improper/missing required values: " + pdpVal);
1028 throw new PolicyEngineException(
1029 XACMLErrorConstants.ERROR_DATA_ISSUE + "PDP value is improper/missing required values.");
1034 * Allowing changes to the scheme and Handler.
1036 public void notification(NotificationScheme scheme, NotificationHandler handler) {
1037 this.scheme = scheme;
1038 this.handler = handler;
1039 LOGGER.debug("Scheme is : " + scheme.toString());
1040 LOGGER.debug("Handler is : " + handler.getClass().getName());
1042 if (notificationType.get(0).equals("ueb")) {
1043 if (this.uebThread) {
1044 AutoClientUEB.setAuto(scheme, handler);
1045 this.uebThread = registerUEBThread.isAlive();
1047 } else if (notificationType.get(0).equals(DMAAP)) {
1048 if (this.dmaapThread) {
1049 AutoClientDMAAP.setAuto(scheme, handler);
1050 this.dmaapThread = registerDMAAPThread.isAlive();
1053 AutoClientEnd.setAuto(scheme, handler);
1061 if (notificationType.get(0).equals("ueb") && !this.uebThread) {
1062 this.uebClientThread = new AutoClientUEB(pdps.get(0), notificationURLList, apiKey, apiSecret);
1063 AutoClientUEB.setAuto(scheme, handler);
1064 this.registerUEBThread = new Thread(this.uebClientThread);
1065 this.registerUEBThread.start();
1066 this.uebThread = true;
1067 } else if (notificationType.get(0).equals(DMAAP) && !this.dmaapThread) {
1068 this.dmaapClientThread = new AutoClientDMAAP(notificationURLList, topic, userName, pass);
1069 AutoClientDMAAP.setAuto(scheme, handler);
1070 this.registerDMAAPThread = new Thread(this.dmaapClientThread);
1071 this.registerDMAAPThread.start();
1072 this.dmaapThread = true;
1074 if (pdps.get(0) != null) {
1075 if (AutoClientEnd.getURL() == null) {
1076 AutoClientEnd.start(pdps.get(0));
1078 AutoClientEnd.stop();
1079 AutoClientEnd.start(pdps.get(0));
1087 * Gets the Notification if one exists. Used only for Manual Polling purposes.
1089 public PDPNotification getNotification() {
1090 // Check if there is proper scheme..
1091 PDPNotification notification = null;
1092 if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)
1093 || this.scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
1094 if (notificationType.get(0).equals("ueb")) {
1095 ManualClientEndUEB.start(pdps.get(0), notificationURLList, UNIQUEID);
1096 notification = ManualClientEndUEB.result(scheme);
1097 } else if (notificationType.get(0).equals(DMAAP)) {
1098 ManualClientEndDMAAP.start(notificationURLList, topic, UNIQUEID, userName, pass);
1099 notification = ManualClientEndDMAAP.result(scheme);
1101 ManualClientEnd.start(pdps.get(0));
1102 LOGGER.debug("manual notification requested.. : " + scheme.toString());
1103 notification = ManualClientEnd.result(scheme);
1105 if (notification == null) {
1106 LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Notification yet..");
1109 return notification;
1117 * Setting the Scheme.
1119 public void setScheme(NotificationScheme scheme) {
1120 this.scheme = scheme;
1121 if (notificationType.get(0).equals("ueb")) {
1122 AutoClientUEB.setScheme(this.scheme);
1123 if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
1124 ManualClientEndUEB.createTopic(pdps.get(0), UNIQUEID, notificationURLList);
1126 } else if (notificationType.get(0).equals(DMAAP)) {
1127 AutoClientDMAAP.setScheme(this.scheme);
1128 if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
1129 ManualClientEndDMAAP.createTopic(topic, UNIQUEID, notificationURLList, userName, pass);
1132 AutoClientEnd.setScheme(this.scheme);
1137 * Returns the Scheme
1139 public NotificationScheme getScheme() {
1144 * Returns the NotificationHandler
1146 public NotificationHandler getNotificationHandler() {
1147 return this.handler;
1151 * Stop the Notification Service if its running.
1153 public void stopNotification() {
1154 if (this.scheme != null && this.handler != null && (this.scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)
1155 || this.scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS))) {
1156 LOGGER.info("Clear Notification called.. ");
1157 if (notificationType.get(0).equals("ueb")) {
1158 this.uebClientThread.terminate();
1159 this.uebThread = false;
1160 } else if (notificationType.get(0).equals(DMAAP)) {
1161 this.dmaapClientThread.terminate();
1162 this.dmaapThread = false;
1164 AutoClientEnd.stop();
1170 * Push a policy to the PDP API implementation
1172 public String pushPolicy(String policyScope, String policyName, String policyType, String pdpGroup, UUID requestID)
1173 throws PolicyException {
1174 PushPolicyParameters pushPolicyParameters = new PushPolicyParameters();
1175 if (policyScope == null || policyScope.trim().isEmpty()) {
1176 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given.";
1177 LOGGER.error(message);
1178 throw new PolicyException(message);
1180 if (policyName == null || policyName.trim().isEmpty()) {
1181 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given.";
1182 LOGGER.error(message);
1183 throw new PolicyException(message);
1185 pushPolicyParameters.setPolicyName(policyScope + "." + policyName);
1186 pushPolicyParameters.setPolicyType(policyType);
1187 pushPolicyParameters.setPdpGroup(pdpGroup);
1188 pushPolicyParameters.setRequestID(requestID);
1189 return pushPolicyImpl(pushPolicyParameters).getResponseMessage();
1192 public String createUpdateConfigPolicy(String policyName, String policyDescription, String onapName,
1193 String configName, Map<String, String> configAttributes, String configType, String body, String policyScope,
1194 UUID requestID, String riskLevel, String riskType, String guard, String ttlDate, boolean updateFlag)
1195 throws PolicyException {
1196 return createUpdateConfigPolicyImpl(policyName, policyDescription, onapName, configName, configAttributes,
1197 configType, body, policyScope, requestID, riskLevel, riskType, guard, ttlDate, updateFlag);
1201 * Create Config Policy API Implementation
1203 public String createUpdateConfigPolicyImpl(String policyName, String policyDescription, String onapName,
1204 String configName, Map<String, String> configAttributes, String configType, String body, String policyScope,
1205 UUID requestID, String riskLevel, String riskType, String guard, String ttlDate, boolean updateFlag)
1206 throws PolicyException {
1207 PolicyParameters policyParameters = new PolicyParameters();
1208 policyParameters.setPolicyClass(PolicyClass.Config);
1209 policyParameters.setPolicyConfigType(PolicyConfigType.Base);
1210 if (policyScope == null || policyScope.trim().isEmpty()) {
1211 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given.";
1212 LOGGER.error(message);
1213 throw new PolicyException(message);
1215 if (policyName == null || policyName.trim().isEmpty()) {
1216 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given.";
1217 LOGGER.error(message);
1218 throw new PolicyException(message);
1220 policyParameters.setPolicyName(policyScope + "." + policyName);
1221 policyParameters.setPolicyDescription(policyDescription);
1222 policyParameters.setOnapName(onapName);
1223 policyParameters.setConfigName(configName);
1224 Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>();
1225 attributes.put(AttributeType.MATCHING, configAttributes);
1226 policyParameters.setAttributes(attributes);
1227 policyParameters.setConfigBodyType(PolicyType.valueOf(configType));
1228 policyParameters.setConfigBody(body);
1229 policyParameters.setRequestID(requestID);
1230 policyParameters.setRiskLevel(riskLevel);
1231 policyParameters.setRiskType(riskType);
1232 policyParameters.setGuard(Boolean.parseBoolean(guard));
1234 policyParameters.setTtlDate(new SimpleDateFormat("dd-MM-yyyy").parse(ttlDate));
1235 } catch (ParseException e) {
1236 LOGGER.warn("Error Parsing date given " + ttlDate);
1237 policyParameters.setTtlDate(null);
1239 return createUpdatePolicyImpl(policyParameters, updateFlag).getResponseMessage();
1242 public String createUpdateConfigFirewallPolicy(String policyName, JsonObject firewallJson, String policyScope,
1243 UUID requestID, String riskLevel, String riskType, String guard, String ttlDate, boolean updateFlag)
1244 throws PolicyException {
1245 return createUpdateConfigFirewallPolicyImpl(policyName, firewallJson, policyScope, requestID, riskLevel,
1246 riskType, guard, ttlDate, updateFlag);
1250 * Create Update Config Firewall Policy API implementation
1252 public String createUpdateConfigFirewallPolicyImpl(String policyName, JsonObject firewallJson, String policyScope,
1253 UUID requestID, String riskLevel, String riskType, String guard, String ttlDate, boolean updateFlag)
1254 throws PolicyException {
1255 PolicyParameters policyParameters = new PolicyParameters();
1256 policyParameters.setPolicyClass(PolicyClass.Config);
1257 policyParameters.setPolicyConfigType(PolicyConfigType.Firewall);
1258 if (policyScope == null || policyScope.trim().isEmpty()) {
1259 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given.";
1260 LOGGER.error(message);
1261 throw new PolicyException(message);
1263 if (policyName == null || policyName.trim().isEmpty()) {
1264 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given.";
1265 LOGGER.error(message);
1266 throw new PolicyException(message);
1268 policyParameters.setPolicyName(policyScope + "." + policyName);
1269 policyParameters.setConfigBody(firewallJson.toString());
1270 policyParameters.setRequestID(requestID);
1271 policyParameters.setRiskLevel(riskLevel);
1272 policyParameters.setRiskType(riskType);
1273 policyParameters.setGuard(Boolean.parseBoolean(guard));
1275 policyParameters.setTtlDate(new SimpleDateFormat("dd-MM-yyyy").parse(ttlDate));
1276 } catch (NullPointerException | ParseException e) {
1277 LOGGER.warn("Error Parsing date given " + ttlDate, e);
1278 policyParameters.setTtlDate(null);
1280 return createUpdatePolicyImpl(policyParameters, updateFlag).getResponseMessage();
1283 public static void setClientKey(String clientKey) {
1284 if (clientKey != null && !clientKey.isEmpty()) {
1285 StdPolicyEngine.pass = clientKey;
1286 setClientEncoding();
1291 * Get the Environment.
1293 public static String getEnvironment() {
1298 * Rotate the PDP list upon WEBsocket Failures
1300 public static void rotatePDPList() {
1301 Collections.rotate(pdps, -1);
1302 Collections.rotate(encoding, -1);
1306 * Get the latest PDP
1308 public static String getPDPURL() {