2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.pdp.rest;
23 import java.io.BufferedReader;
24 import java.io.ByteArrayInputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.InputStreamReader;
28 import java.io.OutputStream;
29 import java.lang.reflect.Constructor;
30 import java.net.InetAddress;
31 import java.net.UnknownHostException;
32 import java.nio.file.Files;
33 import java.util.Properties;
34 import java.util.UUID;
35 import java.util.concurrent.BlockingQueue;
36 import java.util.concurrent.LinkedBlockingQueue;
37 import javax.servlet.Servlet;
38 import javax.servlet.ServletConfig;
39 import javax.servlet.ServletException;
40 import javax.servlet.annotation.WebInitParam;
41 import javax.servlet.annotation.WebServlet;
42 import javax.servlet.http.HttpServlet;
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
45 import org.apache.commons.io.IOUtils;
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48 import org.apache.http.entity.ContentType;
49 import org.onap.policy.api.PolicyParameters;
50 import org.onap.policy.common.im.AdministrativeStateException;
51 import org.onap.policy.common.im.ForwardProgressException;
52 import org.onap.policy.common.im.IntegrityMonitor;
53 import org.onap.policy.common.im.IntegrityMonitorException;
54 import org.onap.policy.common.im.IntegrityMonitorProperties;
55 import org.onap.policy.common.im.StandbyStatusException;
56 import org.onap.policy.common.logging.ONAPLoggingContext;
57 import org.onap.policy.common.logging.ONAPLoggingUtils;
58 import org.onap.policy.common.logging.eelf.MessageCodes;
59 import org.onap.policy.common.logging.eelf.PolicyLogger;
60 import org.onap.policy.pdp.rest.jmx.PdpRestMonitor;
61 import org.onap.policy.rest.XACMLRest;
62 import org.onap.policy.rest.XACMLRestProperties;
63 import org.onap.policy.xacml.api.XACMLErrorConstants;
64 import org.onap.policy.xacml.pdp.std.functions.PolicyList;
65 import org.onap.policy.xacml.std.pap.StdPDPStatus;
66 import com.att.research.xacml.api.Request;
67 import com.att.research.xacml.api.Response;
68 import com.att.research.xacml.api.pap.PDPStatus.Status;
69 import com.att.research.xacml.api.pdp.PDPEngine;
70 import com.att.research.xacml.api.pdp.PDPException;
71 import com.att.research.xacml.std.dom.DOMRequest;
72 import com.att.research.xacml.std.dom.DOMResponse;
73 import com.att.research.xacml.std.json.JSONRequest;
74 import com.att.research.xacml.std.json.JSONResponse;
75 import com.att.research.xacml.util.XACMLProperties;
76 import com.fasterxml.jackson.databind.ObjectMapper;
79 * Servlet implementation class XacmlPdpServlet
81 * This is an implementation of the XACML 3.0 RESTful Interface with added features to support simple PAP RESTful API
82 * for policy publishing and PIP configuration changes.
84 * If you are running this the first time, then we recommend you look at the xacml.pdp.properties file. This properties
85 * file has all the default parameter settings. If you are running the servlet as is, then we recommend setting up
86 * you're container to run it on port 8080 with context "/pdp". Wherever the default working directory is set to, a
87 * "config" directory will be created that holds the policy and pip cache. This setting is located in the
88 * xacml.pdp.properties file.
90 * When you are ready to customize, you can create a separate xacml.pdp.properties on you're local file system and setup
91 * the parameters as you wish. Just set the Java VM System variable to point to that file:
93 * -Dxacml.properties=/opt/app/xacml/etc/xacml.pdp.properties
95 * Or if you only want to change one or two properties, simply set the Java VM System variable for that property.
97 * -Dxacml.rest.pdp.register=false
101 @WebServlet(description = "Implements the XACML PDP RESTful API and client PAP API.", urlPatterns = {"/"},
102 loadOnStartup = 1, initParams = {@WebInitParam(name = "XACML_PROPERTIES_NAME", value = "xacml.pdp.properties",
103 description = "The location of the PDP xacml.pdp.properties file holding configuration information.")})
104 public class XACMLPdpServlet extends HttpServlet implements Runnable {
105 private static final long serialVersionUID = 1L;
106 private static final String DEFAULT_MAX_CONTENT_LENGTH = "999999999"; // 32767
107 private static final String CREATE_UPDATE_POLICY_SERVICE =
108 "org.onap.policy.pdp.rest.api.services.CreateUpdatePolicyServiceImpl";
110 // Our application debug log
112 private static final Log logger = LogFactory.getLog(XACMLPdpServlet.class);
114 // This logger is specifically only for Xacml requests and their corresponding response.
115 // It's output ideally should be sent to a separate file from the application logger.
117 private static final Log requestLogger = LogFactory.getLog("xacml.request");
120 private static final Log auditLogger = LogFactory.getLog("auditLogger");
122 public static final PdpRestMonitor monitor = PdpRestMonitor.getSingleton();
125 // This thread may getting invoked on startup, to let the PAP know
126 // that we are up and running.
128 private static transient Thread registerThread = null;
129 private static transient XACMLPdpRegisterThread registerRunnable = null;
131 // This is our PDP engine pointer. There is a synchronized lock used
132 // for access to the pointer. In case we are servicing PEP requests while
133 // an update is occurring from the PAP.
135 private static PDPEngine pdpEngine = null;
136 private static final Object pdpEngineLock = new Object();
138 // This is our PDP's status. What policies are loaded (or not) and
139 // what PIP configurations are loaded (or not).
140 // There is a synchronized lock used for access to the object.
142 private static volatile StdPDPStatus status = new StdPDPStatus();
143 private static final Object pdpStatusLock = new Object();
144 private static Constructor<?> createUpdatePolicyConstructor;
146 private static final String ENVIORNMENT_HEADER = "Environment";
147 private static String environment = null;
150 // Queue of PUT requests
152 public static class PutRequest {
153 private Properties policyProperties = null;
154 private Properties pipConfigProperties = null;
156 PutRequest(Properties policies, Properties pips) {
157 this.policyProperties = policies;
158 this.pipConfigProperties = pips;
162 protected static volatile BlockingQueue<PutRequest> queue = null;
163 // For notification Delay.
164 private static int notificationDelay = 0;
166 public static int getNotificationDelay() {
167 return XACMLPdpServlet.notificationDelay;
170 private static String pdpResourceName;
171 private static String[] dependencyNodes = null;
174 // This is our configuration thread that attempts to load
175 // a new configuration request.
177 private static transient Thread configThread = null;
178 private static volatile boolean configThreadTerminate = false;
179 private transient ONAPLoggingContext baseLoggingContext = null;
180 private transient IntegrityMonitor im;
182 public IntegrityMonitor getIm() {
186 public void setIm(IntegrityMonitor im) {
191 * Default constructor.
193 public XACMLPdpServlet() {
194 // Default constructor.
198 * @see Servlet#init(ServletConfig)
201 public void init(ServletConfig config) throws ServletException {
202 String createUpdateResourceName = null;
203 String dependencyGroups = null;
207 XACMLRest.xacmlInit(config);
208 // Load the Notification Delay.
209 setNotificationDelay();
210 // Load Queue size. Not sure if we really need to have the queue bounded, we should look further into this
211 int queueSize = 50; // Set default Queue Size here.
212 queueSize = Integer.parseInt(XACMLProperties.getProperty("REQUEST_BUFFER_SIZE", String.valueOf(queueSize)));
213 initQueue(queueSize);
214 // Load our engine - this will use the latest configuration
215 // that was saved to disk and set our initial status object.
217 PDPEngine engine = XACMLPdpLoader.loadEngine(XACMLPdpServlet.status, null, null);
218 if (engine != null) {
219 synchronized (pdpEngineLock) {
222 // Notification will be Sent Here.
223 XACMLPdpLoader.sendNotification();
228 baseLoggingContext = new ONAPLoggingContext();
229 // fixed data that will be the same in all logging output goes here
231 String hostname = InetAddress.getLocalHost().getCanonicalHostName();
232 baseLoggingContext.setServer(hostname);
233 } catch (UnknownHostException e) {
234 logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get hostname for logging" + e);
237 Properties properties;
239 properties = XACMLProperties.getProperties();
240 } catch (IOException e) {
241 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e,
242 "Error loading properties with: XACMLProperties.getProperties()");
243 throw new ServletException(e.getMessage(), e.getCause());
245 if (properties.getProperty(XACMLRestProperties.PDP_RESOURCE_NAME) == null) {
246 XACMLProperties.reloadProperties();
248 properties = XACMLProperties.getProperties();
249 } catch (IOException e) {
250 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e,
251 "Error loading properties with: XACMLProperties.getProperties()");
252 throw new ServletException(e.getMessage(), e.getCause());
254 PolicyLogger.info("\n Properties Given : \n" + properties.toString());
256 setPDPResourceName(properties);
257 dependencyGroups = properties.getProperty(IntegrityMonitorProperties.DEPENDENCY_GROUPS);
258 if (dependencyGroups == null) {
259 PolicyLogger.error(MessageCodes.MISS_PROPERTY_ERROR, IntegrityMonitorProperties.DEPENDENCY_GROUPS,
261 throw new ServletException("dependency_groups is null");
263 setDependencyNodes(dependencyGroups);
266 // CreateUpdatePolicy ResourceName
267 createUpdateResourceName =
268 properties.getProperty("createUpdatePolicy.impl.className", CREATE_UPDATE_POLICY_SERVICE);
269 setCreateUpdatePolicyConstructor(createUpdateResourceName);
271 // Create an IntegrityMonitor
273 logger.info("Creating IntegrityMonitor");
274 im = IntegrityMonitor.getInstance(pdpResourceName, properties);
275 } catch (Exception e) {
276 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to create IntegrityMonitor" + e);
277 throw new ServletException(e);
281 System.setProperty("msToscaModel.home", properties.getProperty("msToscaModel.home"));
282 } catch (Exception e) {
283 logger.error("ERROR: Unable to set msToscaModel.home- Please check the configuration");
286 startThreads(baseLoggingContext, new Thread(this));
289 private static void startThreads(ONAPLoggingContext baseLoggingContext, Thread thread) {
290 environment = XACMLProperties.getProperty("ENVIRONMENT", "DEVL");
292 // Kick off our thread to register with the PAP servlet.
294 if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_REGISTER))) {
295 XACMLPdpServlet.registerRunnable = new XACMLPdpRegisterThread(baseLoggingContext);
296 XACMLPdpServlet.registerThread = new Thread(XACMLPdpServlet.registerRunnable);
297 XACMLPdpServlet.registerThread.start();
300 // This is our thread that manages incoming configuration
303 XACMLPdpServlet.configThread = thread;
304 XACMLPdpServlet.configThread.start();
307 private static void setDependencyNodes(String dependencyGroups) {
308 // dependency_groups is a semicolon-delimited list of groups, and
309 // each group is a comma-separated list of nodes. For our purposes
310 // we just need a list of dependencies without regard to grouping,
311 // so split the list into nodes separated by either comma or semicolon.
312 dependencyNodes = dependencyGroups.split("[;,]");
313 for (int i = 0; i < dependencyNodes.length; i++) {
314 dependencyNodes[i] = dependencyNodes[i].trim();
318 private static void setPDPResourceName(Properties properties) throws ServletException {
319 pdpResourceName = properties.getProperty(XACMLRestProperties.PDP_RESOURCE_NAME);
320 if (pdpResourceName == null) {
321 PolicyLogger.error(MessageCodes.MISS_PROPERTY_ERROR, XACMLRestProperties.PDP_RESOURCE_NAME, "xacml.pdp");
322 throw new ServletException("pdpResourceName is null");
326 private static void initQueue(int queueSize) {
327 queue = new LinkedBlockingQueue<>(queueSize);
330 private static void setNotificationDelay() {
332 XACMLPdpServlet.notificationDelay =
333 Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_DELAY));
334 } catch (NumberFormatException e) {
335 logger.error("Error in notification delay format, Taking the default value.", e);
340 * @see Servlet#destroy()
343 public void destroy() {
345 logger.info("Destroying....");
347 // Make sure the register thread is not running
349 if (XACMLPdpServlet.registerRunnable != null) {
351 XACMLPdpServlet.registerRunnable.terminate();
352 if (XACMLPdpServlet.registerThread != null) {
353 XACMLPdpServlet.registerThread.interrupt();
354 XACMLPdpServlet.registerThread.join();
356 } catch (InterruptedException e) {
357 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
358 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "");
359 XACMLPdpServlet.registerThread.interrupt();
363 // Make sure the configure thread is not running
365 setConfigThreadTerminate(true);
367 XACMLPdpServlet.configThread.interrupt();
368 XACMLPdpServlet.configThread.join();
369 } catch (InterruptedException e) {
370 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
371 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "");
372 XACMLPdpServlet.configThread.interrupt();
374 logger.info("Destroyed.");
377 private static void setConfigThreadTerminate(boolean value) {
378 XACMLPdpServlet.configThreadTerminate = value;
382 * PUT - The PAP engine sends configuration information using HTTP PUT request.
384 * One parameter is expected:
386 * config=[policy|pip|all]
388 * policy - Expect a properties file that contains updated lists of the root and referenced policies that the PDP
389 * should be using for PEP requests.
391 * Specifically should AT LEAST contain the following properties: xacml.rootPolicies xacml.referencedPolicies
393 * In addition, any relevant information needed by the PDP to load or retrieve the policies to store in its cache.
395 * EXAMPLE: xacml.rootPolicies=PolicyA.1, PolicyB.1
397 * PolicyA.1.url=http://localhost:9090/PAP?id=b2d7b86d-d8f1-4adf-ba9d-b68b2a90bee1&version=1
398 * PolicyB.1.url=http://localhost:9090/PAP/id=be962404-27f6-41d8-9521-5acb7f0238be&version=1
400 * xacml.referencedPolicies=RefPolicyC.1, RefPolicyD.1
402 * RefPolicyC.1.url=http://localhost:9090/PAP?id=foobar&version=1
403 * RefPolicyD.1.url=http://localhost:9090/PAP/id=example&version=1
405 * pip - Expect a properties file that contain PIP engine configuration properties.
407 * Specifically should AT LEAST the following property: xacml.pip.engines
409 * In addition, any relevant information needed by the PDP to load and configure the PIPs.
411 * EXAMPLE: xacml.pip.engines=foo,bar
413 * foo.classname=com.foo foo.sample=abc foo.example=xyz ......
415 * bar.classname=com.bar ......
417 * all - Expect ALL new configuration properties for the PDP
419 * @see HttpServlet#doPut(HttpServletRequest request, HttpServletResponse response)
422 protected void doPut(HttpServletRequest request, HttpServletResponse response)
423 throws ServletException, IOException {
424 ONAPLoggingContext loggingContext = ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
425 loggingContext.transactionStarted();
426 if ((loggingContext.getRequestID() == null) || "".equals(loggingContext.getRequestID())) {
427 UUID requestID = UUID.randomUUID();
428 loggingContext.setRequestID(requestID.toString());
429 PolicyLogger.info("requestID not provided in call to XACMLPdpSrvlet (doPut) so we generated one");
431 PolicyLogger.info("requestID was provided in call to XACMLPdpSrvlet (doPut)");
433 loggingContext.metricStarted();
434 loggingContext.metricEnded();
435 PolicyLogger.metrics("Metric example posted here - 1 of 2");
436 loggingContext.metricStarted();
437 loggingContext.metricEnded();
438 PolicyLogger.metrics("Metric example posted here - 2 of 2");
440 // Dump our request out
442 if (logger.isDebugEnabled()) {
443 XACMLRest.dumpRequest(request);
447 im.startTransaction();
448 } catch (IntegrityMonitorException e) {
449 String message = e.toString();
450 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e);
451 loggingContext.transactionEnded();
452 PolicyLogger.audit("Transaction Failed - See Error.log");
454 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
455 } catch (Exception e1) {
456 logger.error("Exception occured while sending error in response" + e1);
461 // What is being PUT?
463 String cache = request.getParameter("cache");
465 // Should be a list of policy and pip configurations in Java properties format
467 if (cache != null && request.getContentType().equals("text/x-java-properties")) {
468 loggingContext.setServiceName("PDP.putConfig");
470 if (request.getContentLength() > Integer
471 .parseInt(XACMLProperties.getProperty("MAX_CONTENT_LENGTH", DEFAULT_MAX_CONTENT_LENGTH))) {
472 String message = "Content-Length larger than server will accept.";
473 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message);
474 loggingContext.transactionEnded();
475 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message);
476 PolicyLogger.audit("Transaction Failed - See Error.log");
477 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
481 logger.info("XACMLPdpServlet: calling doPutConfig to add properties to the queue");
482 this.doPutConfig(cache, request, response, loggingContext);
483 loggingContext.transactionEnded();
484 PolicyLogger.audit("Transaction ended");
487 } catch (Exception e) {
488 logger.error("Exception Occured while getting Max Content lenght" + e);
491 String message = "Invalid cache: '" + cache + "' or content-type: '" + request.getContentType() + "'";
492 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message);
493 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message);
494 loggingContext.transactionEnded();
495 PolicyLogger.audit("Transaction Failed - See Error.log");
497 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
498 } catch (Exception e1) {
499 logger.error("Exception occured while sending error in response" + e1);
506 protected void doPutConfig(String config, HttpServletRequest request, HttpServletResponse response,
507 ONAPLoggingContext loggingContext) throws IOException {
509 // prevent multiple configuration changes from stacking up
510 logger.info("XACMLPdpServlet: checking remainingCapacity of Queue.");
511 if (XACMLPdpServlet.queue.remainingCapacity() <= 0) {
512 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Queue capacity reached");
513 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Queue capacity reached");
514 loggingContext.transactionEnded();
515 PolicyLogger.audit("Transaction Failed - See Error.log");
516 response.sendError(HttpServletResponse.SC_CONFLICT,
517 "Multiple configuration changes waiting processing.");
521 // Read the properties data into an object.
523 Properties newProperties = new Properties();
524 newProperties.load(request.getInputStream());
525 // should have something in the request
526 if (newProperties.size() == 0) {
527 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No properties in PUT");
528 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No properties in PUT");
529 loggingContext.transactionEnded();
530 PolicyLogger.audit("Transaction Failed - See Error.log");
531 response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT must contain at least one property");
535 // Which set of properties are they sending us? Whatever they send gets
536 // put on the queue (if there is room).
537 // For audit logging purposes, we consider the transaction done once the
538 // the request gets put on the queue.
540 if (config.equals("policies")) {
541 newProperties = XACMLProperties.getPolicyProperties(newProperties, true);
542 if (newProperties.size() == 0) {
543 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No policy properties in PUT");
544 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No policy properties in PUT");
545 loggingContext.transactionEnded();
546 PolicyLogger.audit("Transaction Failed - See Error.log");
547 response.sendError(HttpServletResponse.SC_BAD_REQUEST,
548 "PUT with cache=policies must contain at least one policy property");
551 logger.info("XACMLPdpServlet: offer policies to queue. No pip properties added.");
552 XACMLPdpServlet.queue.offer(new PutRequest(newProperties, null));
553 loggingContext.transactionEnded();
554 auditLogger.info("Success");
555 PolicyLogger.audit("Success");
556 } else if (config.equals("pips")) {
557 newProperties = XACMLProperties.getPipProperties(newProperties);
558 if (newProperties.size() == 0) {
559 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No pips properties in PUT");
560 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No pips properties in PUT");
561 loggingContext.transactionEnded();
562 PolicyLogger.audit("Transaction Failed - See Error.log");
563 response.sendError(HttpServletResponse.SC_BAD_REQUEST,
564 "PUT with cache=pips must contain at least one pip property");
567 logger.info("XACMLPdpServlet: offer pips to queue. No policy properties added.");
568 XACMLPdpServlet.queue.offer(new PutRequest(null, newProperties));
569 loggingContext.transactionEnded();
570 auditLogger.info("Success");
571 PolicyLogger.audit("Success");
572 } else if (config.equals("all")) {
573 Properties newPolicyProperties = XACMLProperties.getPolicyProperties(newProperties, true);
574 if (newPolicyProperties.size() == 0) {
575 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No policy properties in PUT");
576 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No policy properties in PUT");
577 loggingContext.transactionEnded();
578 PolicyLogger.audit("Transaction Failed - See Error.log");
579 response.sendError(HttpServletResponse.SC_BAD_REQUEST,
580 "PUT with cache=all must contain at least one policy property");
583 Properties newPipProperties = XACMLProperties.getPipProperties(newProperties);
584 if (newPipProperties.size() == 0) {
585 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No pips properties in PUT");
586 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No pips properties in PUT");
587 loggingContext.transactionEnded();
588 PolicyLogger.audit("Transaction Failed - See Error.log");
589 response.sendError(HttpServletResponse.SC_BAD_REQUEST,
590 "PUT with cache=all must contain at least one pip property");
593 logger.info("XACMLPdpServlet: offer policies and pips to queue.");
594 XACMLPdpServlet.queue.offer(new PutRequest(newPolicyProperties, newPipProperties));
595 loggingContext.transactionEnded();
596 auditLogger.info("Success");
597 PolicyLogger.audit("Success");
603 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid config value: " + config);
604 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Invalid config value: " + config);
605 loggingContext.transactionEnded();
606 PolicyLogger.audit("Transaction Failed - See Error.log");
607 response.sendError(HttpServletResponse.SC_BAD_REQUEST,
608 "Config must be one of 'policies', 'pips', 'all'");
611 } catch (Exception e) {
612 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed to process new configuration.", e);
613 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to process new configuration");
614 loggingContext.transactionEnded();
615 PolicyLogger.audit("Transaction Failed - See Error.log");
617 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
618 } catch (Exception e1) {
619 logger.error("Exception occured while sending error in response" + e1);
627 * Parameters: type=hb|config|Status
629 * 1. HeartBeat Status HeartBeat OK - All Policies are Loaded, All PIPs are Loaded LOADING_IN_PROGRESS - Currently
630 * loading a new policy set/pip configuration LAST_UPDATE_FAILED - Need to track the items that failed during last
631 * update LOAD_FAILURE - ??? Need to determine what information is sent and how 2. Configuration 3. Status return
632 * the StdPDPStatus object in the Response content
635 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
638 protected void doGet(HttpServletRequest request, HttpServletResponse response)
639 throws ServletException, IOException {
640 ONAPLoggingContext loggingContext = ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
641 loggingContext.transactionStarted();
642 if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")) {
643 UUID requestID = UUID.randomUUID();
644 loggingContext.setRequestID(requestID.toString());
645 PolicyLogger.info("requestID not provided in call to XACMLPdpSrvlet (doGet) so we generated one");
647 PolicyLogger.info("requestID was provided in call to XACMLPdpSrvlet (doGet)");
649 loggingContext.metricStarted();
650 loggingContext.metricEnded();
651 PolicyLogger.metrics("Metric example posted here - 1 of 2");
652 loggingContext.metricStarted();
653 loggingContext.metricEnded();
654 PolicyLogger.metrics("Metric example posted here - 2 of 2");
656 XACMLRest.dumpRequest(request);
658 String pathInfo = request.getRequestURI();
659 if (pathInfo != null && "/pdp/test".equals(pathInfo)) {
660 // health check from Global Site Selector (iDNS).
661 // DO NOT do a im.startTransaction for the test request
662 loggingContext.setServiceName("iDNS:PDP.test");
665 // If we make it this far, all is well
666 String message = "GET:/pdp/test called and PDP " + pdpResourceName + " is OK";
667 PolicyLogger.debug(message);
668 PolicyLogger.audit("Success");
669 response.setStatus(HttpServletResponse.SC_OK);
671 } catch (ForwardProgressException | AdministrativeStateException | StandbyStatusException fpe) {
672 // No forward progress is being made
673 String message = "GET:/pdp/test called and PDP " + pdpResourceName + " is not making forward progress."
674 + " Exception Message: " + fpe.getMessage();
675 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + fpe);
676 PolicyLogger.audit("Transaction Failed - See Error.log");
678 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
679 } catch (Exception e1) {
680 logger.error("Exception occured while sending error in response" + e1);
683 } catch (Exception e) {
684 // A subsystem is not making progress or is not responding
685 String eMsg = e.getMessage();
687 eMsg = "No Exception Message";
689 String message = "GET:/pdp/test called and PDP " + pdpResourceName + " has had a subsystem failure."
690 + " Exception Message: " + eMsg;
691 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message);
692 // Get the specific list of subsystems that failed
693 String failedNodeList = null;
694 for (String node : dependencyNodes) {
695 if (eMsg.contains(node)) {
696 if (failedNodeList == null) {
697 failedNodeList = node;
699 failedNodeList = failedNodeList.concat("," + node);
703 if (failedNodeList == null) {
704 failedNodeList = "UnknownSubSystem";
706 response.addHeader("X-ONAP-SubsystemFailure", failedNodeList);
708 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
709 } catch (Exception e1) {
710 logger.error("Exception occured while sending error in response" + e1);
712 PolicyLogger.audit("Transaction Failed - See Error.log" + e);
715 loggingContext.transactionEnded();
720 im.startTransaction();
721 } catch (IntegrityMonitorException e) {
722 String message = e.toString();
723 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message);
724 loggingContext.transactionEnded();
725 PolicyLogger.audit("Transaction Failed - See Error.log" + e);
727 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
728 } catch (Exception e1) {
729 logger.error("Exception occured while sending error in response" + e1);
734 // What are they requesting?
736 boolean returnHB = false;
737 response.setHeader("Cache-Control", "no-cache");
738 String type = request.getParameter("type");
739 // type might be null, so use equals on string constants
740 if ("config".equals(type)) {
741 loggingContext.setServiceName("PDP.getConfig");
742 response.setContentType("text/x-java-properties");
744 String lists = XACMLProperties.PROP_ROOTPOLICIES + "="
745 + XACMLProperties.getProperty(XACMLProperties.PROP_ROOTPOLICIES, "");
746 lists = lists + "\n" + XACMLProperties.PROP_REFERENCEDPOLICIES + "="
747 + XACMLProperties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "") + "\n";
748 try (InputStream listInputStream = new ByteArrayInputStream(lists.getBytes());
749 InputStream pipInputStream = Files.newInputStream(XACMLPdpLoader.getPIPConfig());
750 OutputStream os = response.getOutputStream()) {
751 IOUtils.copy(listInputStream, os);
752 IOUtils.copy(pipInputStream, os);
754 loggingContext.transactionEnded();
755 auditLogger.info("Success");
756 PolicyLogger.audit("Success");
757 response.setStatus(HttpServletResponse.SC_OK);
758 } catch (Exception e) {
759 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed to copy property file", e);
760 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to copy property file");
761 loggingContext.transactionEnded();
762 PolicyLogger.audit("Transaction Failed - See Error.log");
764 response.sendError(400, "Failed to copy Property file");
765 } catch (Exception e1) {
766 logger.error("Exception occured while sending error in response" + e1);
770 } else if ("hb".equals(type)) {
772 response.setStatus(HttpServletResponse.SC_NO_CONTENT);
774 } else if ("Status".equals(type)) {
775 loggingContext.setServiceName("PDP.getStatus");
776 // convert response object to JSON and include in the response
777 synchronized (pdpStatusLock) {
778 ObjectMapper mapper = new ObjectMapper();
780 mapper.writeValue(response.getOutputStream(), status);
781 } catch (Exception e1) {
782 logger.error("Exception occured while writing output stream" + e1);
785 response.setStatus(HttpServletResponse.SC_OK);
786 loggingContext.transactionEnded();
787 auditLogger.info("Success");
788 PolicyLogger.audit("Success");
791 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid type value: " + type);
792 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Invalid type value: " + type);
793 loggingContext.transactionEnded();
794 PolicyLogger.audit("Transaction Failed - See Error.log");
796 response.sendError(HttpServletResponse.SC_BAD_REQUEST, "type not 'config' or 'hb'");
797 } catch (Exception e1) {
798 logger.error("Exception occured while sending error in response" + e1);
802 synchronized (pdpStatusLock) {
803 response.addHeader(XACMLRestProperties.PROP_PDP_HTTP_HEADER_HB, status.getStatus().toString());
806 loggingContext.transactionEnded();
807 PolicyLogger.audit("Transaction Ended");
813 * POST - We expect XACML requests to be posted by PEP applications. They can be in the form of XML or JSON
814 * according to the XACML 3.0 Specifications for both.
817 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
820 protected void doPost(HttpServletRequest request, HttpServletResponse response)
821 throws ServletException, IOException {
823 ONAPLoggingContext loggingContext = ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
824 loggingContext.transactionStarted();
825 loggingContext.setServiceName("PDP.decide");
826 if ((loggingContext.getRequestID() == null) || ("".equals(loggingContext.getRequestID()))) {
827 UUID requestID = UUID.randomUUID();
828 loggingContext.setRequestID(requestID.toString());
829 PolicyLogger.info("requestID not provided in call to XACMLPdpSrvlet (doPost) so we generated one");
831 PolicyLogger.info("requestID was provided in call to XACMLPdpSrvlet (doPost)");
833 loggingContext.metricStarted();
834 loggingContext.metricEnded();
835 PolicyLogger.metrics("Metric example posted here - 1 of 2");
836 loggingContext.metricStarted();
837 loggingContext.metricEnded();
838 PolicyLogger.metrics("Metric example posted here - 2 of 2");
839 monitor.pdpEvaluationAttempts();
842 im.startTransaction();
843 } catch (IntegrityMonitorException e) {
844 String message = e.toString();
845 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e);
846 loggingContext.transactionEnded();
847 PolicyLogger.audit("Transaction Failed - See Error.log");
849 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
850 } catch (Exception e1) {
851 logger.error("Exception occured while sending error in response" + e1);
856 // no point in doing any work if we know from the get-go that we cannot do anything with the request
858 if (status.getLoadedRootPolicies().isEmpty()) {
859 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Request from PEP at " + request.getRequestURI()
860 + " for service when PDP has No Root Policies loaded");
861 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "Request from PEP at " + request.getRequestURI()
862 + " for service when PDP has No Root Policies loaded");
863 loggingContext.transactionEnded();
864 PolicyLogger.audit("Transaction Failed - See Error.log");
866 response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
867 } catch (Exception e1) {
868 logger.error("Exception occured while sending error in response" + e1);
874 XACMLRest.dumpRequest(request);
876 // Set our no-cache header
878 response.setHeader("Cache-Control", "no-cache");
880 // They must send a Content-Type
882 if (request.getContentType() == null) {
883 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Must specify a Content-Type");
884 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Must specify a Content-Type");
885 loggingContext.transactionEnded();
886 PolicyLogger.audit("Transaction Failed - See Error.log");
888 response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given");
889 } catch (Exception e1) {
890 logger.error("Exception occured while sending error in response" + e1);
896 // Limit the Content-Length to something reasonable
899 if (request.getContentLength() > Integer
900 .parseInt(XACMLProperties.getProperty("MAX_CONTENT_LENGTH", "32767"))) {
901 String message = "Content-Length larger than server will accept.";
902 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message);
903 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message);
904 loggingContext.transactionEnded();
905 PolicyLogger.audit("Transaction Failed - See Error.log");
906 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
910 } catch (Exception e) {
911 logger.error("Exception occured while getting max content length" + e);
914 if (request.getContentLength() <= 0) {
915 String message = "Content-Length is negative";
916 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message);
917 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message);
918 loggingContext.transactionEnded();
919 PolicyLogger.audit("Transaction Failed - See Error.log");
921 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
922 } catch (Exception e1) {
923 logger.error("Exception occured while sending error in response" + e1);
928 ContentType contentType = null;
930 contentType = ContentType.parse(request.getContentType());
931 } catch (Exception e) {
932 String message = "Parsing Content-Type: " + request.getContentType() + ", error=" + e.getMessage();
933 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message, e);
934 loggingContext.transactionEnded();
935 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, message);
936 PolicyLogger.audit("Transaction Failed - See Error.log");
938 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
939 } catch (Exception e1) {
940 logger.error("Exception occured while sending error in response" + e1);
946 // What exactly did they send us?
948 String incomingRequestString = null;
949 Request pdpRequest = null;
950 if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())
951 || contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType())
952 || contentType.getMimeType().equalsIgnoreCase("application/xacml+xml")) {
954 // Read in the string
956 StringBuilder buffer = new StringBuilder();
957 BufferedReader reader = null;
959 reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
960 } catch (IOException e) {
961 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error during reading input stream", e);
966 while ((line = reader.readLine()) != null) {
969 } catch (Exception e) {
970 logger.error("Exception Occured while reading line" + e);
973 incomingRequestString = buffer.toString();
974 logger.info(incomingRequestString);
976 // Parse into a request
979 if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) {
980 pdpRequest = JSONRequest.load(incomingRequestString);
981 } else if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType())
982 || "application/xacml+xml".equalsIgnoreCase(contentType.getMimeType())) {
983 pdpRequest = DOMRequest.load(incomingRequestString);
985 } catch (Exception e) {
986 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not parse request", e);
987 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "Could not parse request");
988 loggingContext.transactionEnded();
989 PolicyLogger.audit("Transaction Failed - See Error.log");
991 response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
992 } catch (Exception e1) {
993 logger.error("Exception occured while sending error in response" + e1);
999 String message = "unsupported content type" + request.getContentType();
1000 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message);
1001 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message);
1002 loggingContext.transactionEnded();
1003 PolicyLogger.audit("Transaction Failed - See Error.log");
1005 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
1006 } catch (Exception e1) {
1007 logger.error("Exception occured while sending error in response" + e1);
1009 im.endTransaction();
1013 // Did we successfully get and parse a request?
1015 if (pdpRequest == null || pdpRequest.getRequestAttributes() == null
1016 || pdpRequest.getRequestAttributes().isEmpty()) {
1017 String message = "Zero Attributes found in the request";
1018 logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message);
1019 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message);
1020 loggingContext.transactionEnded();
1021 PolicyLogger.audit("Transaction Failed - See Error.log");
1023 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
1024 } catch (Exception e1) {
1025 logger.error("Exception occured while sending error in response" + e1);
1027 im.endTransaction();
1035 // Authenticating the Request here.
1037 if (!authorizeRequest(request)) {
1039 "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. ";
1040 logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + message);
1041 PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS, message);
1042 loggingContext.transactionEnded();
1043 PolicyLogger.audit("Transaction Failed - See Error.log");
1044 response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
1045 im.endTransaction();
1049 // Get the pointer to the PDP Engine
1051 PDPEngine myEngine = null;
1052 synchronized (pdpEngineLock) {
1053 myEngine = XACMLPdpServlet.pdpEngine;
1055 if (myEngine == null) {
1056 String message = "No engine loaded.";
1057 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message);
1058 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message);
1059 loggingContext.transactionEnded();
1060 PolicyLogger.audit("Transaction Failed - See Error.log");
1061 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
1062 im.endTransaction();
1066 // Send the request and save the response
1070 Response pdpResponse = null;
1072 synchronized (pdpEngineLock) {
1073 myEngine = XACMLPdpServlet.pdpEngine;
1075 PolicyList.clearPolicyList();
1076 lTimeStart = System.currentTimeMillis();
1077 pdpResponse = myEngine.decide(pdpRequest);
1078 lTimeEnd = System.currentTimeMillis();
1079 } catch (PDPException e) {
1080 String message = "Exception during decide: " + e.getMessage();
1081 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message + e);
1082 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message);
1083 loggingContext.transactionEnded();
1084 PolicyLogger.audit("Transaction Failed - See Error.log");
1086 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
1087 } catch (Exception e1) {
1088 logger.error("Exception occured while sending error in response" + e1);
1090 im.endTransaction();
1094 monitor.computeLatency(lTimeEnd - lTimeStart);
1095 requestLogger.info(lTimeStart + "=" + incomingRequestString);
1096 for (String policy : PolicyList.getpolicyList()) {
1097 monitor.policyCountAdd(policy, 1);
1101 logger.info("PolicyID triggered in Request: " + PolicyList.getpolicyList());
1103 // need to go through the list and find out if the value is unique and then add it other wise
1104 // monitor.policyCountAdd(PolicyList.getpolicyList(), 1);
1106 if (logger.isDebugEnabled()) {
1107 logger.debug("Request time: " + (lTimeEnd - lTimeStart) + "ms");
1110 // Convert Response to appropriate Content-Type
1112 if (pdpResponse == null) {
1113 requestLogger.info(lTimeStart + "=" + "{}");
1115 throw new PDPException("Failed to get response from PDP engine.");
1116 } catch (Exception e1) {
1117 logger.error("Exception occured while throwing Exception" + e1);
1121 // Set our content-type
1123 response.setContentType(contentType.getMimeType());
1125 // Convert the PDP response object to a String to
1126 // return to our caller as well as dump to our loggers.
1128 String outgoingResponseString = "";
1130 if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) {
1132 // Get it as a String. This is not very efficient but we need to log our
1133 // results for auditing.
1135 outgoingResponseString = JSONResponse.toString(pdpResponse, logger.isDebugEnabled());
1136 if (logger.isDebugEnabled()) {
1137 logger.debug(outgoingResponseString);
1139 // Get rid of whitespace
1141 outgoingResponseString = JSONResponse.toString(pdpResponse, false);
1143 } else if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType())
1144 || contentType.getMimeType().equalsIgnoreCase("application/xacml+xml")) {
1146 // Get it as a String. This is not very efficient but we need to log our
1147 // results for auditing.
1149 outgoingResponseString = DOMResponse.toString(pdpResponse, logger.isDebugEnabled());
1150 if (logger.isDebugEnabled()) {
1151 logger.debug(outgoingResponseString);
1153 // Get rid of whitespace
1155 outgoingResponseString = DOMResponse.toString(pdpResponse, false);
1158 // adding the jmx values for NA, Permit and Deny
1160 if (outgoingResponseString.contains("NotApplicable")
1161 || outgoingResponseString.contains("Decision not a Permit")) {
1162 monitor.pdpEvaluationNA();
1165 if (outgoingResponseString.contains("Permit")
1166 && !outgoingResponseString.contains("Decision not a Permit")) {
1167 monitor.pdpEvaluationPermit();
1170 if (outgoingResponseString.contains("Deny")) {
1171 monitor.pdpEvaluationDeny();
1174 // lTimeStart is used as an ID within the requestLogger to match up
1175 // request's with responses.
1177 requestLogger.info(lTimeStart + "=" + outgoingResponseString);
1178 response.getWriter().print(outgoingResponseString);
1179 } catch (Exception e) {
1180 logger.error("Exception Occured" + e);
1182 } catch (Exception e) {
1183 String message = "Exception executing request: " + e;
1184 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message, e);
1185 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, message);
1186 loggingContext.transactionEnded();
1187 PolicyLogger.audit("Transaction Failed - See Error.log");
1189 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
1190 } catch (Exception e1) {
1191 logger.error("Exception occured while sending error in response" + e1);
1196 monitor.pdpEvaluationSuccess();
1197 response.setStatus(HttpServletResponse.SC_OK);
1199 loggingContext.transactionEnded();
1200 auditLogger.info("Success");
1201 PolicyLogger.audit("Success");
1206 * Added for Authorizing the PEP Requests for Environment check.
1208 private boolean authorizeRequest(HttpServletRequest request) {
1209 // Get the client Credentials from the Request header.
1210 HttpServletRequest httpServletRequest = request;
1211 String clientCredentials = httpServletRequest.getHeader(ENVIORNMENT_HEADER);
1212 if (clientCredentials != null && clientCredentials.equalsIgnoreCase(environment)) {
1222 // Keep running until we are told to terminate
1225 // variable not used, but constructor has needed side-effects so don't remove:
1226 while (!XACMLPdpServlet.configThreadTerminate) {
1227 logger.info("XACMLPdpServlet: Taking requests from the queue");
1228 PutRequest request = XACMLPdpServlet.queue.take();
1229 logger.info("XACMLPdpServlet: Taking requests from the queue COMPLETED");
1230 StdPDPStatus newStatus = new StdPDPStatus();
1232 PDPEngine newEngine = null;
1233 synchronized (pdpStatusLock) {
1234 XACMLPdpServlet.status.setStatus(Status.UPDATING_CONFIGURATION);
1236 logger.info("created new PDPEngine");
1238 XACMLPdpLoader.loadEngine(newStatus, request.policyProperties, request.pipConfigProperties);
1240 if (newEngine != null) {
1241 logger.info("XACMLPdpServlet: newEngine created, assigning newEngine to the pdpEngine.");
1242 synchronized (XACMLPdpServlet.pdpEngineLock) {
1243 XACMLPdpServlet.pdpEngine = newEngine;
1245 logger.info("Saving configuration.");
1246 if (request.policyProperties != null) {
1247 logger.info("Saving configuration: Policy Properties: " + request.policyProperties);
1248 try (OutputStream os = Files.newOutputStream(XACMLPdpLoader.getPDPPolicyCache())) {
1249 request.policyProperties.store(os, "");
1252 if (request.pipConfigProperties != null) {
1253 logger.info("Saving configuration: PIP Properties: " + request.pipConfigProperties);
1254 try (OutputStream os = Files.newOutputStream(XACMLPdpLoader.getPIPConfig())) {
1255 request.pipConfigProperties.store(os, "");
1258 newStatus.setStatus(Status.UP_TO_DATE);
1259 } catch (Exception e) {
1261 XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to store new properties." + e);
1262 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Failed to store new properties");
1263 newStatus.setStatus(Status.LOAD_ERRORS);
1264 newStatus.addLoadWarning("Unable to save configuration: " + e.getMessage());
1268 newStatus.setStatus(Status.LAST_UPDATE_FAILED);
1270 synchronized (pdpStatusLock) {
1271 XACMLPdpServlet.status.set(newStatus);
1273 logger.info("New PDP Servlet Status: " + newStatus.getStatus());
1274 if (Status.UP_TO_DATE.equals(newStatus.getStatus())) {
1275 // Notification will be Sent Here.
1276 XACMLPdpLoader.sendNotification();
1279 } catch (InterruptedException e) {
1280 logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "interrupted" + e);
1281 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "interrupted");
1282 Thread.currentThread().interrupt();
1286 public static PDPEngine getPDPEngine() {
1287 PDPEngine myEngine = null;
1288 synchronized (pdpEngineLock) {
1289 myEngine = XACMLPdpServlet.pdpEngine;
1294 public static Constructor<?> getCreateUpdatePolicyConstructor() {
1295 return createUpdatePolicyConstructor;
1298 public static Object getPDPEngineLock() {
1299 return pdpEngineLock;
1302 private static void setCreateUpdatePolicyConstructor(String createUpdateResourceName) throws ServletException {
1304 Class<?> createUpdateclass = Class.forName(createUpdateResourceName);
1305 createUpdatePolicyConstructor =
1306 createUpdateclass.getConstructor(PolicyParameters.class, String.class, boolean.class);
1307 } catch (Exception e) {
1308 PolicyLogger.error(MessageCodes.MISS_PROPERTY_ERROR, "createUpdatePolicy.impl.className",
1309 "xacml.pdp.init" + e);
1310 throw new ServletException(
1311 "Could not find the Class name : " + createUpdateResourceName + "\n" + e.getMessage());