aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java105
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java180
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java899
-rw-r--r--ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java6
-rw-r--r--packages/base/src/files/install/servers/onap/WEB-INF/conf/system.properties2
-rwxr-xr-xpackages/base/src/files/install/servers/pdplp/bin/parserlog.properties2
6 files changed, 650 insertions, 544 deletions
diff --git a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
index c3d631e1f..1dbe12523 100644
--- a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
+++ b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
@@ -77,22 +77,21 @@ public class ParseLog {
private static String logFile;
private static String debuglogFile;
private static String errorlogFile;
- private static String JDBC_URL;
- private static String JDBC_USER;
- private static String JDBC_PASSWORD;
- private static String JDBC_DRIVER;
+ private static String jdbcUrl;
+ private static String jdbcUser;
+ private static String jdbcPassword;
+ private static String jdbcDriver;
private static int maxLength = 255; //Max length that is allowed in the DB table
private static String resourceName;
private static long sleepTimer = 50000;
static IntegrityMonitor im;
private static boolean isMissingLogFile;
//Default:Timer initial delay and the delay between in milliseconds before task is to be execute
- private static int TIMER_DELAY_TIME = 1000;
+ private static final int TIMER_DELAY_TIME = 1000;
//Default:Timer scheduleAtFixedRate period - time in milliseconds between successive task executions
- private static int CHECK_INTERVAL = 86400000; // run this clean up once a day
- private static RandomAccessFile randomAccessFile;
+ private static int checkInterval = 86400000; // run this clean up once a day
private static String loggingProcess = "Error processing line in ";
- private static int TIME_FRAME = 5;
+ private static int defaultTimeFrame = 5;
private static String message =" value read in: ";
private static String lineFormat = "(\\r\\n|\\n)";
private static String lineRead = "-line-Read:";
@@ -344,30 +343,32 @@ public class ParseLog {
file.createNewFile();
return null;
}
- randomAccessFile = new RandomAccessFile(file, "r");
- StringBuilder builder = new StringBuilder();
- long length = file.length();
- logger.debug("dataFileName: " +dataFileName);
- if(length > 0){
- length--;
- randomAccessFile.seek(length);
- for(long seek = length; seek >= 0; --seek){
- randomAccessFile.seek(seek);
- char c = (char)randomAccessFile.read();
- builder.append(c);
- if(c == '\n'){
- builder = builder.reverse();
- logger.debug("builder.toString(): " +builder.toString());
- if (builder.toString().contains(last+dataFileName+lineRead)){
- String[] parseString = builder.toString().split(last+dataFileName+lineRead);
- String returnValue = parseString[1].replace("\r", "");
- return returnValue.trim();
- }
- builder = new StringBuilder();
- }
- }
- }
-
+ try(RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");){
+ StringBuilder builder = new StringBuilder();
+ long length = file.length();
+ logger.debug("dataFileName: " +dataFileName);
+ if(length > 0){
+ length--;
+ randomAccessFile.seek(length);
+ for(long seek = length; seek >= 0; --seek){
+ randomAccessFile.seek(seek);
+ char c = (char)randomAccessFile.read();
+ builder.append(c);
+ if(c == '\n'){
+ builder = builder.reverse();
+ logger.debug("builder.toString(): " +builder.toString());
+ if (builder.toString().contains(last+dataFileName+lineRead)){
+ String[] parseString = builder.toString().split(last+dataFileName+lineRead);
+ String returnValue = parseString[1].replace("\r", "");
+ randomAccessFile.close();
+ return returnValue.trim();
+ }
+ builder = new StringBuilder();
+ }
+ }
+ }
+ randomAccessFile.close();
+ }
return null;
}
@@ -602,7 +603,7 @@ public class ParseLog {
private static void writeDB(LogEntryObject returnLogValue) {
- Connection conn = dbConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD);
+ Connection conn = dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword);
dbAccesss(conn, returnLogValue.getSystem(), returnLogValue.getDescription(),
returnLogValue.getDate(), returnLogValue.getRemote(),
returnLogValue.getSystemType(), returnLogValue.getLogType().toString());
@@ -613,8 +614,7 @@ public class ParseLog {
try {
Class.forName(driver);
- Connection conn = DriverManager.getConnection(jdbc, user, pass);
- return conn;
+ return DriverManager.getConnection(jdbc, user, pass);
} catch ( Exception e) {
logger.error("Error connecting to DB: " + e);
}
@@ -713,19 +713,24 @@ public class ParseLog {
if(cleanupInterval != null && !cleanupInterval.isEmpty()){
int intCheckInterval = Integer.parseInt(cleanupInterval);
if(intCheckInterval > 300000) {//must be longer than 5 minutes
- CHECK_INTERVAL = intCheckInterval;
+ checkInterval = intCheckInterval;
}
}else{
- logger.debug("No value defined for CHECK_INTERVAL in parserlog.properties, so use its default value:" + CHECK_INTERVAL + " milliseconds");
+ logger.debug("No value defined for CHECK_INTERVAL in parserlog.properties, so use its default value:" + checkInterval + " milliseconds");
}
- if(timeFrame != null && !timeFrame.isEmpty()){
- int intTimeFrame = Integer.parseInt(timeFrame);
+ if(timeFrame != null && !timeFrame.trim().isEmpty()){
+ int intTimeFrame = defaultTimeFrame;
+ try{
+ intTimeFrame = Integer.parseInt(timeFrame);
+ }catch(NumberFormatException e){
+ logger.debug("Improper value defined for TIME_FRAME in parserlog.properties, so use its default value:" + defaultTimeFrame + " days");
+ }
if(intTimeFrame > 0){
- TIME_FRAME = intTimeFrame;
+ defaultTimeFrame = intTimeFrame;
}
}else{
- logger.debug("No value defined for TIME_FRAME in parserlog.properties, so use its default value:" + TIME_FRAME + " days");
+ logger.debug("No value defined for TIME_FRAME in parserlog.properties, so use its default value:" + defaultTimeFrame + " days");
}
}
@@ -800,17 +805,17 @@ public class ParseLog {
setLogFileProperties(splitString);
- JDBC_URL = config.getProperty("JDBC_URL").replace("'", "");
- JDBC_USER = config.getProperty("JDBC_USER");
- JDBC_DRIVER = config.getProperty("JDBC_DRIVER");
- JDBC_PASSWORD = config.getProperty("JDBC_PASSWORD");
+ jdbcUrl = config.getProperty("JDBC_URL").replace("'", "");
+ jdbcUser = config.getProperty("JDBC_USER");
+ jdbcDriver = config.getProperty("JDBC_DRIVER");
+ jdbcPassword = config.getProperty("JDBC_PASSWORD");
return config;
} catch (IOException e) {
logger.error("Error porcessing Config file will be unable to create Health Check" + e);
}catch(Exception e){
logger.error("Error getPropertiesValue on TIME_FRAME", e);
- logger.debug("Error getPropertiesValue on TIME_FRAME, so use its default value:" + TIME_FRAME + " days");
+ logger.debug("Error getPropertiesValue on TIME_FRAME, so use its default value:" + defaultTimeFrame + " days");
}
}
@@ -822,13 +827,13 @@ public class ParseLog {
}
public static Connection getDbConnection(){
- return dbConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD);
+ return dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword);
}
private static void startCleanUp(){
- Connection conn = dbConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD);
- CleanUpSystemLogDB cleanUp = new CleanUpSystemLogDB(conn, TIME_FRAME);
+ Connection conn = dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword);
+ CleanUpSystemLogDB cleanUp = new CleanUpSystemLogDB(conn, defaultTimeFrame);
Timer timer = new Timer(true);
- timer.scheduleAtFixedRate(cleanUp, TIMER_DELAY_TIME, CHECK_INTERVAL);
+ timer.scheduleAtFixedRate(cleanUp, TIMER_DELAY_TIME, checkInterval);
logger.info("startCleanUp begins! : " + new Date());
}
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
index b3ac236cf..88f6d4540 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -43,6 +43,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+import java.util.Scanner;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -53,7 +54,6 @@ import javax.persistence.PersistenceException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@@ -338,11 +338,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
initiateThread.start();
}
- private static void mapperWriteValue(ObjectMapper mapper, ServletOutputStream out, Object value) {
+ private static void mapperWriteValue(ObjectMapper mapper, HttpServletResponse response, Object value) {
try {
- mapper.writeValue(out, value);
+ mapper.writeValue(response.getOutputStream(), value);
} catch (Exception e) {
- LOGGER.debug(e);
+ LOGGER.error(e);
}
}
@@ -784,7 +784,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
if (apiflag!=null) {
if(authorizeRequest(request)){
APIRequestHandler apiRequestHandler = new APIRequestHandler();
- apiRequestHandler.doGet(request,response, apiflag);
+ try{
+ apiRequestHandler.doGet(request,response, apiflag);
+ }catch(IOException e){
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
@@ -803,7 +807,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String groupId = request.getParameter("groupId");
if (groupId != null) {
// this is from the Admin Console, so handle separately
- doACGet(request, response, groupId, loggingContext);
+ try{
+ doACGet(request, response, groupId, loggingContext);
+ } catch(IOException e){
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
@@ -828,7 +836,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.setServiceName("PAP.getGroups");
Set<OnapPDPGroup> groups = papEngine.getOnapPDPGroups();
// convert response object to JSON and include in the response
- mapperWriteValue(new ObjectMapper(), response.getOutputStream(), groups);
+ mapperWriteValue(new ObjectMapper(), response, groups);
response.setHeader("content-type", "application/json");
response.setStatus(HttpServletResponse.SC_OK);
loggingContext.transactionEnded();
@@ -846,7 +854,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
loggingContext.setServiceName("PAP.getPolicy");
// Get the PDP's Group
- OnapPDPGroup group = XACMLPapServlet.papEngine.getPDPGroup((OnapPDP) pdp);
+ OnapPDPGroup group = null;
+ try {
+ group = XACMLPapServlet.papEngine.getPDPGroup((OnapPDP) pdp);
+ } catch (PAPException e) {
+ LOGGER.error(e);
+ }
if (group == null) {
String message = "No group associated with pdp " + pdp.getId();
LOGGER.warn(XACMLErrorConstants.ERROR_PERMISSIONS + message);
@@ -877,8 +890,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
im.endTransaction();
return;
}
- LOGGER.warn("PolicyDebugging: Policy Validity: " + policy.isValid() + "\n "
- + "Policy Name : " + policy.getName() + "\n Policy URI: " + policy.getLocation().toString());
+ try{
+ LOGGER.warn("PolicyDebugging: Policy Validity: " + policy.isValid() + "\n "
+ + "Policy Name : " + policy.getName() + "\n Policy URI: " + policy.getLocation().toString());
+ } catch (PAPException| IOException e){
+ LOGGER.error(e);
+ }
try (InputStream is = new FileInputStream(((StdPDPGroup)group).getDirectory().toString()+File.separator+policyId); OutputStream os = response.getOutputStream()) {
// Send the policy back
IOUtils.copy(is, os);
@@ -894,7 +911,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
PolicyLogger.audit("Transaction Failed - See Error.log");
setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
}
- } catch (PAPException | IOException e) {
+ } catch (PAPException e) {
LOGGER.debug(e);
PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " GET exception");
loggingContext.transactionEnded();
@@ -951,7 +968,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String policyDBDaoRequestUrl = request.getParameter("policydbdaourl");
if(policyDBDaoRequestUrl != null){
String policyDBDaoRequestEntityId = request.getParameter("entityid");
- //String policyDBDaoRequestEntityType = request.getParameter("entitytype");
String policyDBDaoRequestEntityType = request.getParameter("entitytype");
String policyDBDaoRequestExtraData = request.getParameter("extradata");
if(policyDBDaoRequestEntityId == null || policyDBDaoRequestEntityType == null){
@@ -975,7 +991,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
if (importService != null) {
if(authorizeRequest(request)){
APIRequestHandler apiRequestHandler = new APIRequestHandler();
- apiRequestHandler.doPut(request, response, importService);
+ try{
+ apiRequestHandler.doPut(request, response, importService);
+ }catch(IOException e){
+ LOGGER.error(e);
+ }
im.endTransaction();
return;
} else {
@@ -1070,7 +1090,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return;
}
if(apiflag.equalsIgnoreCase("addPolicyToGroup")){
- updateGroupsFromAPI(request, response, groupId, loggingContext);
+ try{
+ updateGroupsFromAPI(request, response, groupId, loggingContext);
+ }catch(IOException e){
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
@@ -1078,7 +1102,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
}
// this is from the Admin Console, so handle separately
- doACPut(request, response, groupId, loggingContext);
+ try {
+ doACPut(request, response, groupId, loggingContext);
+ } catch (IOException e) {
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
@@ -1090,7 +1118,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
if (apiflag != null && apiflag.equalsIgnoreCase("admin")){
// this request is from the Admin Console
SavePolicyHandler savePolicyHandler = SavePolicyHandler.getInstance();
- savePolicyHandler.doPolicyAPIPut(request, response);
+ try{
+ savePolicyHandler.doPolicyAPIPut(request, response);
+ } catch (IOException e) {
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
@@ -1099,7 +1131,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// this request is from the Policy Creation API
if(authorizeRequest(request)){
APIRequestHandler apiRequestHandler = new APIRequestHandler();
- apiRequestHandler.doPut(request, response, request.getHeader("ClientScope"));
+ try{
+ apiRequestHandler.doPut(request, response, request.getHeader("ClientScope"));
+ } catch (IOException e) {
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
@@ -1188,7 +1224,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return;
}
// this is from the Admin Console, so handle separately
- doACDelete(request, response, groupId, loggingContext);
+ try{
+ doACDelete(request, response, groupId, loggingContext);
+ } catch (IOException e) {
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
@@ -1393,8 +1433,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
if (groupName != null && groupDescription != null) {
// Args: group=<groupId> groupName=<name> groupDescription=<description> <= create a new group
loggingContext.setServiceName("AC:PAP.createGroup");
- String unescapedName = URLDecoder.decode(groupName, "UTF-8");
- String unescapedDescription = URLDecoder.decode(groupDescription, "UTF-8");
+ String unescapedName = null;
+ String unescapedDescription = null;
+ try{
+ unescapedName = URLDecoder.decode(groupName, "UTF-8");
+ unescapedDescription = URLDecoder.decode(groupDescription, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ LOGGER.error(e);
+ }
PolicyDBDaoTransaction newGroupTransaction = policyDBDao.getNewTransaction();
try {
newGroupTransaction.createGroup(PolicyDBDao.createNewPDPGroupId(unescapedName), unescapedName, unescapedDescription,"XACMLPapServlet.doACPost");
@@ -1423,7 +1469,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return;
}
// for all remaining POST operations the group must exist before the operation can be done
- OnapPDPGroup group = papEngine.getGroup(groupId);
+ OnapPDPGroup group = null;
+ try{
+ group = papEngine.getGroup(groupId);
+ } catch (PAPException e){
+ LOGGER.error(e);
+ }
if (group == null) {
String message = "Unknown groupId '" + groupId + "'";
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
@@ -1613,13 +1664,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.setServiceName("AC:PAP.getDefaultGroup");
OnapPDPGroup group = papEngine.getDefaultGroup();
// convert response object to JSON and include in the response
- mapperWriteValue(new ObjectMapper(), response.getOutputStream(), group);
+ mapperWriteValue(new ObjectMapper(), response, group);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET Default group req from '" + request.getRequestURL() + "'");
}
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("content-type", "application/json");
- response.getOutputStream().close();
+ try{
+ response.getOutputStream().close();
+ } catch (IOException e){
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
auditLogger.info("Success");
PolicyLogger.audit("Transaction Ended Successfully");
@@ -1631,7 +1686,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.setServiceName("AC:PAP.getPDP");
OnapPDP pdp = papEngine.getPDP(pdpId);
// convert response object to JSON and include in the response
- mapperWriteValue(new ObjectMapper(), response.getOutputStream(), pdp);
+ mapperWriteValue(new ObjectMapper(), response, pdp);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET pdp '" + pdpId + "' req from '" + request.getRequestURL() + "'");
}
@@ -1648,13 +1703,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
OnapPDP pdp = papEngine.getPDP(pdpId);
OnapPDPGroup group = papEngine.getPDPGroup((OnapPDP) pdp);
// convert response object to JSON and include in the response
- mapperWriteValue(new ObjectMapper(), response.getOutputStream(), group);
+ mapperWriteValue(new ObjectMapper(), response, group);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET PDP '" + pdpId + "' Group req from '" + request.getRequestURL() + "'");
}
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("content-type", "application/json");
- response.getOutputStream().close();
+ try{
+ response.getOutputStream().close();
+ } catch (IOException e){
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
auditLogger.info("Success");
PolicyLogger.audit("Transaction Ended Successfully");
@@ -1665,13 +1724,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.setServiceName("AC:PAP.getAllGroups");
Set<OnapPDPGroup> groups = papEngine.getOnapPDPGroups();
// convert response object to JSON and include in the response
- mapperWriteValue(new ObjectMapper(), response.getOutputStream(), groups);
+ mapperWriteValue(new ObjectMapper(), response, groups);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET All groups req");
}
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("content-type", "application/json");
- response.getOutputStream().close();
+ try{
+ response.getOutputStream().close();
+ } catch (IOException e){
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
auditLogger.info("Success");
PolicyLogger.audit("Transaction Ended Successfully");
@@ -1684,7 +1747,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String message = "Unknown groupId '" + groupId + "'";
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
loggingContext.transactionEnded();
-
PolicyLogger.audit("Transaction Failed - See Error.log");
setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
return;
@@ -1703,13 +1765,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// No other parameters, so return the identified Group
loggingContext.setServiceName("AC:PAP.getGroup");
// convert response object to JSON and include in the response
- mapperWriteValue(new ObjectMapper(), response.getOutputStream(), group);
+ mapperWriteValue(new ObjectMapper(), response, group);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET group '" + group.getId() + "' req from '" + request.getRequestURL() + "'");
}
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("content-type", "application/json");
- response.getOutputStream().close();
+ try{
+ response.getOutputStream().close();
+ } catch (IOException e){
+ LOGGER.error(e);
+ }
loggingContext.transactionEnded();
auditLogger.info("Success");
PolicyLogger.audit("Transaction Ended Successfully");
@@ -1780,7 +1846,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// get the request content into a String
String json = null;
// read the inputStream into a buffer (trick found online scans entire input looking for end-of-file)
- java.util.Scanner scanner = new java.util.Scanner(request.getInputStream());
+ Scanner scanner = null;
+ try{
+ scanner = new Scanner(request.getInputStream());
+ }catch(IOException e){
+ LOGGER.error(e);
+ }
scanner.useDelimiter("\\A");
json = scanner.hasNext() ? scanner.next() : "";
scanner.close();
@@ -1810,7 +1881,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
+"pdp="+ (pdp.getId()) +",to group="+group.getId());
throw new PAPException(e.getMessage());
}
- papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
+ try{
+ papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
+ }catch(PAPException e){
+ LOGGER.error(e);
+ }
} else {
try{
acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut");
@@ -1820,7 +1895,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
throw new PAPException(e.getMessage());
}
// this is a request to update the pdp
- papEngine.updatePDP(pdp);
+ try{
+ papEngine.updatePDP(pdp);
+ }catch(PAPException e){
+ LOGGER.error(e);
+ }
}
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
if (LOGGER.isDebugEnabled()) {
@@ -1861,7 +1940,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// get the request content into a String
String json = null;
// read the inputStream into a buffer (trick found online scans entire input looking for end-of-file)
- java.util.Scanner scanner = new java.util.Scanner(request.getInputStream());
+ Scanner scanner = null;
+ try{
+ scanner = new Scanner(request.getInputStream());
+ }catch(IOException e){
+ LOGGER.error(e);
+ }
scanner.useDelimiter("\\A");
json = scanner.hasNext() ? scanner.next() : "";
scanner.close();
@@ -1896,9 +1980,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
if (pushPolicyHandler.preSafetyCheck(updatedGroup, configHome)) {
LOGGER.debug("Precheck Successful.");
}
-
- papEngine.updateGroup((StdPDPGroup)objectFromJSON);
-
+ try{
+ papEngine.updateGroup((StdPDPGroup)objectFromJSON);
+ }catch(PAPException e){
+ LOGGER.error(e);
+ }
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Group '" + group.getId() + "' updated");
@@ -1990,7 +2076,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
} catch(Exception e){
throw new PAPException(e);
}
- papEngine.removePDP((OnapPDP) pdp);
+ try{
+ papEngine.removePDP((OnapPDP) pdp);
+ }catch(PAPException e){
+ LOGGER.error(e);
+ }
// adjust the status of the group, which may have changed when we removed this PDP
((StdPDPGroup)group).resetStatus();
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
@@ -2015,7 +2105,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String moveToGroupId = request.getParameter("movePDPsToGroupId");
OnapPDPGroup moveToGroup = null;
if (moveToGroupId != null) {
- moveToGroup = papEngine.getGroup(moveToGroupId);
+ try{
+ moveToGroup = papEngine.getGroup(moveToGroupId);
+ }catch(PAPException e){
+ LOGGER.error(e);
+ }
}
// get list of PDPs in the group being deleted so we can notify them that they got changed
Set<OnapPDP> movedPDPs = new HashSet<>();
@@ -2027,7 +2121,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " Failed to delete PDP Group. Exception");
throw new PAPException(e.getMessage());
}
- papEngine.removeGroup(group, moveToGroup);
+ try{
+ papEngine.removeGroup(group, moveToGroup);
+ }catch(PAPException e){
+ LOGGER.error(e);
+ }
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
notifyAC();
// notify any PDPs in the removed set that their config may have changed
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
index 5ad774d20..2e2fa0dd0 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
@@ -62,452 +62,455 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
public class ActionPolicy extends Policy {
-
- /**
- * ActionPolicy Fields
- */
- private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicy.class);
-
- public static final String JSON_CONFIG = "JSON";
-
- public static final String PDP_ACTION = "PDP";
- public static final String PEP_ACTION = "PEP";
- public static final String TYPE_ACTION = "REST";
-
- public static final String GET_METHOD = "GET";
- public static final String PUT_METHOD = "PUT";
- public static final String POST_METHOD = "POST";
-
- public static final String PERFORMER_ATTRIBUTEID = "performer";
- public static final String TYPE_ATTRIBUTEID = "type";
- public static final String METHOD_ATTRIBUTEID = "method";
- public static final String HEADERS_ATTRIBUTEID = "headers";
- public static final String URL_ATTRIBUTEID = "url";
- public static final String BODY_ATTRIBUTEID = "body";
-
- List<String> dynamicLabelRuleAlgorithms = new LinkedList<>();
- List<String> dynamicFieldFunctionRuleAlgorithms = new LinkedList<>();
- List<String> dynamicFieldOneRuleAlgorithms = new LinkedList<>();
- List<String> dynamicFieldTwoRuleAlgorithms = new LinkedList<>();
-
- protected Map<String, String> dropDownMap = new HashMap<>();
-
- private static boolean isAttribute = false;
- private synchronized static boolean getAttribute () {
- return isAttribute;
-
- }
-
- public ActionPolicy() {
- super();
- }
-
- public ActionPolicy(PolicyRestAdapter policyAdapter){
- this.policyAdapter = policyAdapter;
- }
-
- @Override
- public Map<String, String> savePolicies() throws PAPException {
-
- Map<String, String> successMap = new HashMap<>();
- if(isPolicyExists()){
- successMap.put("EXISTS", "This Policy already exist on the PAP");
- return successMap;
- }
-
- if(!ActionPolicy.getAttribute()) {
- successMap.put("invalidAttribute", "Action Attrbute was not in the database.");
- return successMap;
- }
-
- if(!isPreparedToSave()){
- //Prep and configure the policy for saving
- prepareToSave();
- }
-
- // Until here we prepared the data and here calling the method to create xml.
- Path newPolicyPath = null;
- newPolicyPath = Paths.get(policyAdapter.getNewFileName());
- successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() );
- return successMap;
- }
-
- //This is the method for preparing the policy for saving. We have broken it out
- //separately because the fully configured policy is used for multiple things
- @Override
- public boolean prepareToSave() throws PAPException{
-
- if(isPreparedToSave()){
- //we have already done this
- return true;
- }
-
- int version = 0;
- String policyID = policyAdapter.getPolicyID();
- version = policyAdapter.getHighestVersion();
-
- // Create the Instance for pojo, PolicyType object is used in marshalling.
- if (policyAdapter.getPolicyType().equals("Action")) {
- PolicyType policyConfig = new PolicyType();
-
- policyConfig.setVersion(Integer.toString(version));
- policyConfig.setPolicyId(policyID);
- policyConfig.setTarget(new TargetType());
- policyAdapter.setData(policyConfig);
- }
-
- policyName = policyAdapter.getNewFileName();
-
- if (policyAdapter.getData() != null) {
- // Action body is optional so checking value provided or not
- String comboDictValue = policyAdapter.getActionAttribute();
- String actionBody = policyAdapter.getActionBody();
- isAttribute = false;
-
- //if actionBody is null or empty then we know the ActionAttribute in the request does not exist in the dictionary
- if(!(actionBody==null || "".equals(actionBody))){
- saveActionBody(policyName, actionBody);
- isAttribute = true;
- } else {
- if(!getAttribute()){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table.");
- return false;
- }
- }
-
- PolicyType actionPolicy = (PolicyType) policyAdapter.getData();
- actionPolicy.setDescription(policyAdapter.getPolicyDescription());
- actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-
- AllOfType allOf = new AllOfType();
-
- Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes();
-
- // If there is any dynamic field attributes create the matches here
- for (String keyField : dynamicFieldComponentAttributes.keySet()) {
- String key = keyField;
- String value = dynamicFieldComponentAttributes.get(key);
- MatchType dynamicMatch = createDynamicMatch(key, value);
- allOf.getMatch().add(dynamicMatch);
- }
-
- AnyOfType anyOf = new AnyOfType();
- anyOf.getAllOf().add(allOf);
-
- TargetType target = new TargetType();
- target.getAnyOf().add(anyOf);
-
- // Adding the target to the policy element
- actionPolicy.setTarget(target);
-
- RuleType rule = new RuleType();
- rule.setRuleId(policyAdapter.getRuleID());
-
- rule.setEffect(EffectType.PERMIT);
- rule.setTarget(new TargetType());
-
- dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels();
- dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo();
- dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1();
- dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2();
- //dropDownMap = policyAdapter.getDropDownMap();
- dropDownMap = createDropDownMap();
-
- // Rule attributes are optional and dynamic so check and add them to condition.
- if (dynamicLabelRuleAlgorithms != null && dynamicLabelRuleAlgorithms.size() > 0) {
- boolean isCompound = false;
- ConditionType condition = new ConditionType();
- int index = dynamicFieldOneRuleAlgorithms.size() - 1;
-
- for (String labelAttr : dynamicLabelRuleAlgorithms) {
- // if the rule algorithm as a label means it is a compound
- if (dynamicFieldOneRuleAlgorithms.get(index).toString().equals(labelAttr)) {
- ApplyType actionApply = new ApplyType();
-
- String selectedFunction = (String) dynamicFieldFunctionRuleAlgorithms.get(index).toString();
- String value1 = (String) dynamicFieldOneRuleAlgorithms.get(index).toString();
- String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
- actionApply.setFunctionId(dropDownMap.get(selectedFunction));
- actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
- actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
- condition.setExpression(new ObjectFactory().createApply(actionApply));
- isCompound = true;
- }
- }
- // if rule algorithm not a compound
- if (!isCompound) {
- condition.setExpression(new ObjectFactory().createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index).toString())));
- }
- rule.setCondition(condition);
- }
- // set the obligations to rule
- rule.setObligationExpressions(getObligationExpressions());
- actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
- policyAdapter.setPolicyData(actionPolicy);
- } else {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
- }
-
- setPreparedToSave(true);
- return true;
- }
-
- // Saving the json Configurations file if exists at server location for action policy.
- private void saveActionBody(String policyName, String actionBodyData) {
- try {
- if(policyName.endsWith(".xml")){
- policyName = policyName.replace(".xml", "");
- }
- File file = new File(ACTION_HOME+ File.separator + policyName + ".json");
- FileWriter fw = new FileWriter(file.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(actionBodyData);
- bw.close();
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info("Action Body is succesfully saved at " + file.getAbsolutePath());
- }
- } catch (IOException e) {
- LOGGER.error("Exception Occured"+e);
- }
- }
-
- // Data required for obligation part is setting here.
- private ObligationExpressionsType getObligationExpressions() {
- ObligationExpressionsType obligations = new ObligationExpressionsType();
-
- ObligationExpressionType obligation = new ObligationExpressionType();
+
+ /**
+ * ActionPolicy Fields
+ */
+ private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicy.class);
+
+ public static final String JSON_CONFIG = "JSON";
+
+ public static final String PDP_ACTION = "PDP";
+ public static final String PEP_ACTION = "PEP";
+ public static final String TYPE_ACTION = "REST";
+
+ public static final String GET_METHOD = "GET";
+ public static final String PUT_METHOD = "PUT";
+ public static final String POST_METHOD = "POST";
+
+ public static final String PERFORMER_ATTRIBUTEID = "performer";
+ public static final String TYPE_ATTRIBUTEID = "type";
+ public static final String METHOD_ATTRIBUTEID = "method";
+ public static final String HEADERS_ATTRIBUTEID = "headers";
+ public static final String URL_ATTRIBUTEID = "url";
+ public static final String BODY_ATTRIBUTEID = "body";
+
+ List<String> dynamicLabelRuleAlgorithms = new LinkedList<>();
+ List<String> dynamicFieldFunctionRuleAlgorithms = new LinkedList<>();
+ List<String> dynamicFieldOneRuleAlgorithms = new LinkedList<>();
+ List<String> dynamicFieldTwoRuleAlgorithms = new LinkedList<>();
+
+ protected Map<String, String> dropDownMap = new HashMap<>();
+
+ private static boolean isAttribute = false;
+ private synchronized static boolean getAttribute () {
+ return isAttribute;
+
+ }
+
+ public ActionPolicy() {
+ super();
+ }
+
+ public ActionPolicy(PolicyRestAdapter policyAdapter){
+ this.policyAdapter = policyAdapter;
+ }
+
+ @Override
+ public Map<String, String> savePolicies() throws PAPException {
+
+ Map<String, String> successMap = new HashMap<>();
+ if(isPolicyExists()){
+ successMap.put("EXISTS", "This Policy already exist on the PAP");
+ return successMap;
+ }
+
+ if(!ActionPolicy.getAttribute()) {
+ successMap.put("invalidAttribute", "Action Attrbute was not in the database.");
+ return successMap;
+ }
+
+ if(!isPreparedToSave()){
+ //Prep and configure the policy for saving
+ prepareToSave();
+ }
+
+ // Until here we prepared the data and here calling the method to create xml.
+ Path newPolicyPath = null;
+ newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+ successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() );
+ return successMap;
+ }
+
+ //This is the method for preparing the policy for saving. We have broken it out
+ //separately because the fully configured policy is used for multiple things
+ @Override
+ public boolean prepareToSave() throws PAPException{
+
+ if(isPreparedToSave()){
+ //we have already done this
+ return true;
+ }
+
+ int version = 0;
+ String policyID = policyAdapter.getPolicyID();
+ version = policyAdapter.getHighestVersion();
+
+ // Create the Instance for pojo, PolicyType object is used in marshalling.
+ if (policyAdapter.getPolicyType().equals("Action")) {
+ PolicyType policyConfig = new PolicyType();
+
+ policyConfig.setVersion(Integer.toString(version));
+ policyConfig.setPolicyId(policyID);
+ policyConfig.setTarget(new TargetType());
+ policyAdapter.setData(policyConfig);
+ }
+
+ policyName = policyAdapter.getNewFileName();
+
+ if (policyAdapter.getData() != null) {
+ // Action body is optional so checking value provided or not
+ String comboDictValue = policyAdapter.getActionAttribute();
+ String actionBody = policyAdapter.getActionBody();
+ setAttribute(false);
+
+ //if actionBody is null or empty then we know the ActionAttribute in the request does not exist in the dictionary
+ if(!(actionBody==null || "".equals(actionBody))){
+ saveActionBody(policyName, actionBody);
+ setAttribute(true);
+ } else {
+ if(!getAttribute()){
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table.");
+ return false;
+ }
+ }
+
+ PolicyType actionPolicy = (PolicyType) policyAdapter.getData();
+ actionPolicy.setDescription(policyAdapter.getPolicyDescription());
+ actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+ AllOfType allOf = new AllOfType();
+
+ Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes();
+
+ // If there is any dynamic field attributes create the matches here
+ for (String keyField : dynamicFieldComponentAttributes.keySet()) {
+ String key = keyField;
+ String value = dynamicFieldComponentAttributes.get(key);
+ MatchType dynamicMatch = createDynamicMatch(key, value);
+ allOf.getMatch().add(dynamicMatch);
+ }
+
+ AnyOfType anyOf = new AnyOfType();
+ anyOf.getAllOf().add(allOf);
+
+ TargetType target = new TargetType();
+ target.getAnyOf().add(anyOf);
+
+ // Adding the target to the policy element
+ actionPolicy.setTarget(target);
+
+ RuleType rule = new RuleType();
+ rule.setRuleId(policyAdapter.getRuleID());
+
+ rule.setEffect(EffectType.PERMIT);
+ rule.setTarget(new TargetType());
+
+ dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels();
+ dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo();
+ dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1();
+ dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2();
+ dropDownMap = createDropDownMap();
+
+ // Rule attributes are optional and dynamic so check and add them to condition.
+ if (dynamicLabelRuleAlgorithms != null && dynamicLabelRuleAlgorithms.size() > 0) {
+ boolean isCompound = false;
+ ConditionType condition = new ConditionType();
+ int index = dynamicFieldOneRuleAlgorithms.size() - 1;
+
+ for (String labelAttr : dynamicLabelRuleAlgorithms) {
+ // if the rule algorithm as a label means it is a compound
+ if (dynamicFieldOneRuleAlgorithms.get(index).toString().equals(labelAttr)) {
+ ApplyType actionApply = new ApplyType();
+
+ String selectedFunction = (String) dynamicFieldFunctionRuleAlgorithms.get(index).toString();
+ String value1 = (String) dynamicFieldOneRuleAlgorithms.get(index).toString();
+ String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
+ actionApply.setFunctionId(dropDownMap.get(selectedFunction));
+ actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
+ actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
+ condition.setExpression(new ObjectFactory().createApply(actionApply));
+ isCompound = true;
+ }
+ }
+ // if rule algorithm not a compound
+ if (!isCompound) {
+ condition.setExpression(new ObjectFactory().createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index).toString())));
+ }
+ rule.setCondition(condition);
+ }
+ // set the obligations to rule
+ rule.setObligationExpressions(getObligationExpressions());
+ actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+ policyAdapter.setPolicyData(actionPolicy);
+ } else {
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
+ }
+
+ setPreparedToSave(true);
+ return true;
+ }
+
+ private static synchronized void setAttribute(boolean b) {
+ isAttribute = b;
+ }
+
+ // Saving the json Configurations file if exists at server location for action policy.
+ private void saveActionBody(String policyName, String actionBodyData) {
+ try {
+ if(policyName.endsWith(".xml")){
+ policyName = policyName.replace(".xml", "");
+ }
+ File file = new File(ACTION_HOME+ File.separator + policyName + ".json");
+ FileWriter fw = new FileWriter(file.getAbsoluteFile());
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write(actionBodyData);
+ bw.close();
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("Action Body is succesfully saved at " + file.getAbsolutePath());
+ }
+ } catch (IOException e) {
+ LOGGER.error("Exception Occured"+e);
+ }
+ }
+
+ // Data required for obligation part is setting here.
+ private ObligationExpressionsType getObligationExpressions() {
+ ObligationExpressionsType obligations = new ObligationExpressionsType();
+
+ ObligationExpressionType obligation = new ObligationExpressionType();
String comboDictValue = policyAdapter.getActionAttribute();
- obligation.setObligationId(comboDictValue);
- obligation.setFulfillOn(EffectType.PERMIT);
-
- // Add Action Assignment:
- AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
- assignment1.setAttributeId(PERFORMER_ATTRIBUTEID);
- assignment1.setCategory(CATEGORY_RECIPIENT_SUBJECT);
-
- AttributeValueType actionNameAttributeValue = new AttributeValueType();
- actionNameAttributeValue.setDataType(STRING_DATATYPE);
- actionNameAttributeValue.getContent().add(performer.get(policyAdapter.getActionPerformer()));
-
- assignment1.setExpression(new ObjectFactory().createAttributeValue(actionNameAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignment1);
-
- // Add Type Assignment:
- AttributeAssignmentExpressionType assignmentType = new AttributeAssignmentExpressionType();
- assignmentType.setAttributeId(TYPE_ATTRIBUTEID);
- assignmentType.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType typeAttributeValue = new AttributeValueType();
- typeAttributeValue.setDataType(STRING_DATATYPE);
- String actionDictType = policyAdapter.getActionDictType();
- typeAttributeValue.getContent().add(actionDictType);
-
- assignmentType.setExpression(new ObjectFactory().createAttributeValue(typeAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentType);
-
- // Add Rest_URL Assignment:
- AttributeAssignmentExpressionType assignmentURL = new AttributeAssignmentExpressionType();
- assignmentURL.setAttributeId(URL_ATTRIBUTEID);
- assignmentURL.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType actionURLAttributeValue = new AttributeValueType();
- actionURLAttributeValue.setDataType(URI_DATATYPE);
- String actionDictUrl = policyAdapter.getActionDictUrl();
- actionURLAttributeValue.getContent().add(actionDictUrl);
-
- assignmentURL.setExpression(new ObjectFactory().createAttributeValue(actionURLAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentURL);
-
- // Add Method Assignment:
- AttributeAssignmentExpressionType assignmentMethod = new AttributeAssignmentExpressionType();
- assignmentMethod.setAttributeId(METHOD_ATTRIBUTEID);
- assignmentMethod.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType methodAttributeValue = new AttributeValueType();
- methodAttributeValue.setDataType(STRING_DATATYPE);
- String actionDictMethod = policyAdapter.getActionDictMethod();
- methodAttributeValue.getContent().add(actionDictMethod);
-
- assignmentMethod.setExpression(new ObjectFactory().createAttributeValue(methodAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentMethod);
-
- // Add JSON_URL Assignment:
- String actionBody = policyAdapter.getActionBody();
- if (actionBody != null) {
- AttributeAssignmentExpressionType assignmentJsonURL = new AttributeAssignmentExpressionType();
- assignmentJsonURL.setAttributeId(BODY_ATTRIBUTEID);
- assignmentJsonURL.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType jsonURLAttributeValue = new AttributeValueType();
- jsonURLAttributeValue.setDataType(URI_DATATYPE);
- jsonURLAttributeValue.getContent().add(CONFIG_URL + "/Action/" + policyName + ".json");
-
- assignmentJsonURL.setExpression(new ObjectFactory().createAttributeValue(jsonURLAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentJsonURL);
- }
-
- String headerVal = policyAdapter.getActionDictHeader();
- if(headerVal != null && !headerVal.equals("")){
- // parse it on : to get number of headers
- String[] result = headerVal.split(":");
- for (String eachString : result){
- // parse each value on =
- String[] textFieldVals = eachString.split("=");
- obligation.getAttributeAssignmentExpression().add(addDynamicHeaders(textFieldVals[0], textFieldVals[1]));
- }
- }
-
- obligations.getObligationExpression().add(obligation);
- return obligations;
- }
-
-
- // if compound setting the inner apply here
- protected ApplyType getInnerActionApply(String value1Label) {
- ApplyType actionApply = new ApplyType();
- int index = 0;
- // check the index for the label.
- for (String labelAttr : dynamicLabelRuleAlgorithms) {
- if (labelAttr.equals(value1Label)) {
- String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
- // check if the row contains label again
- for (String labelValue : dynamicLabelRuleAlgorithms) {
- if (labelValue.equals(value1)) {
- return getCompoundApply(index);
- }
- }
-
- // Getting the values from the form.
- String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
- String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
- actionApply.setFunctionId(dropDownMap.get(functionKey));
- // if two text field are rule attributes.
- if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
- ApplyType innerActionApply1 = new ApplyType();
- ApplyType innerActionApply2 = new ApplyType();
- AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType();
- AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType();
- // If selected function is Integer function set integer functionID
- if (functionKey.toLowerCase().contains("integer")) {
- innerActionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
- innerActionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
- attributeDesignator1.setDataType(INTEGER_DATATYPE);
- attributeDesignator2.setDataType(INTEGER_DATATYPE);
- } else {
- // If selected function is not a Integer function
- // set String functionID
- innerActionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
- innerActionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
- attributeDesignator1.setDataType(STRING_DATATYPE);
- attributeDesignator2.setDataType(STRING_DATATYPE);
- }
- attributeDesignator1.setCategory(CATEGORY_RESOURCE);
- attributeDesignator2.setCategory(CATEGORY_RESOURCE);
-
- // Here set actual field values
- attributeDesignator1.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
- attributeDesignator2.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
-
- innerActionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator1));
- innerActionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator2));
-
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply1));
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply2));
-
- } else {// if either of one text field is rule attribute.
- ApplyType innerActionApply = new ApplyType();
- AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
- AttributeValueType actionConditionAttributeValue = new AttributeValueType();
-
- if (functionKey.toLowerCase().contains("integer")) {
- innerActionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
- actionConditionAttributeValue.setDataType(INTEGER_DATATYPE);
- attributeDesignator.setDataType(INTEGER_DATATYPE);
- } else {
- innerActionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
- actionConditionAttributeValue.setDataType(STRING_DATATYPE);
- attributeDesignator.setDataType(STRING_DATATYPE);
- }
-
- String attributeId = null;
- String attributeValue = null;
-
- // Find which textField has rule attribute and set it as
- attributeId = value1;
- attributeValue = value2;
-
- if (attributeId != null) {
- attributeDesignator.setCategory(CATEGORY_RESOURCE);
- attributeDesignator.setAttributeId(attributeId);
- }
- actionConditionAttributeValue.getContent().add(attributeValue);
- innerActionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
- // Decide the order of element based the values.
- if (attributeId.equals(value1)) {
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
- actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
- } else {
- actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
- }
- }
- }
- index++;
- }
- return actionApply;
- }
-
- // if the rule algorithm is multiple compound one setting the apply
- protected ApplyType getCompoundApply(int index) {
- ApplyType actionApply = new ApplyType();
- String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
- String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
- String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
- actionApply.setFunctionId(dropDownMap.get(selectedFunction));
- actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
- actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
- return actionApply;
- }
-
- // Adding the dynamic headers if any
- private AttributeAssignmentExpressionType addDynamicHeaders(String header, String value) {
- AttributeAssignmentExpressionType assignmentHeaders = new AttributeAssignmentExpressionType();
- assignmentHeaders.setAttributeId("headers:" + header);
- assignmentHeaders.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType headersAttributeValue = new AttributeValueType();
- headersAttributeValue.setDataType(STRING_DATATYPE);
- headersAttributeValue.getContent().add(value);
-
- assignmentHeaders.setExpression(new ObjectFactory().createAttributeValue(headersAttributeValue));
- return assignmentHeaders;
- }
-
- private Map<String,String> createDropDownMap(){
- JPAUtils jpaUtils = null;
- Map<String, String> dropDownMap = new HashMap<>();
- try {
- jpaUtils = JPAUtils.getJPAUtilsInstance(XACMLPapServlet.getEmf());
- } catch (Exception e) {
- LOGGER.error("Exception Occured"+e);
- }
- if(jpaUtils != null){
- Map<Datatype, List<FunctionDefinition>> functionMap = jpaUtils.getFunctionDatatypeMap();
-
- for (Datatype id : functionMap.keySet()) {
- List<FunctionDefinition> functionDefinitions = (List<FunctionDefinition>) functionMap
- .get(id);
- for (FunctionDefinition functionDef : functionDefinitions) {
- dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid());
- }
- }
- }
- return dropDownMap;
- }
-
- @Override
- public Object getCorrectPolicyDataObject() {
- return policyAdapter.getPolicyData();
- }
-
-}
+ obligation.setObligationId(comboDictValue);
+ obligation.setFulfillOn(EffectType.PERMIT);
+
+ // Add Action Assignment:
+ AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+ assignment1.setAttributeId(PERFORMER_ATTRIBUTEID);
+ assignment1.setCategory(CATEGORY_RECIPIENT_SUBJECT);
+
+ AttributeValueType actionNameAttributeValue = new AttributeValueType();
+ actionNameAttributeValue.setDataType(STRING_DATATYPE);
+ actionNameAttributeValue.getContent().add(performer.get(policyAdapter.getActionPerformer()));
+
+ assignment1.setExpression(new ObjectFactory().createAttributeValue(actionNameAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignment1);
+
+ // Add Type Assignment:
+ AttributeAssignmentExpressionType assignmentType = new AttributeAssignmentExpressionType();
+ assignmentType.setAttributeId(TYPE_ATTRIBUTEID);
+ assignmentType.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType typeAttributeValue = new AttributeValueType();
+ typeAttributeValue.setDataType(STRING_DATATYPE);
+ String actionDictType = policyAdapter.getActionDictType();
+ typeAttributeValue.getContent().add(actionDictType);
+
+ assignmentType.setExpression(new ObjectFactory().createAttributeValue(typeAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentType);
+
+ // Add Rest_URL Assignment:
+ AttributeAssignmentExpressionType assignmentURL = new AttributeAssignmentExpressionType();
+ assignmentURL.setAttributeId(URL_ATTRIBUTEID);
+ assignmentURL.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType actionURLAttributeValue = new AttributeValueType();
+ actionURLAttributeValue.setDataType(URI_DATATYPE);
+ String actionDictUrl = policyAdapter.getActionDictUrl();
+ actionURLAttributeValue.getContent().add(actionDictUrl);
+
+ assignmentURL.setExpression(new ObjectFactory().createAttributeValue(actionURLAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentURL);
+
+ // Add Method Assignment:
+ AttributeAssignmentExpressionType assignmentMethod = new AttributeAssignmentExpressionType();
+ assignmentMethod.setAttributeId(METHOD_ATTRIBUTEID);
+ assignmentMethod.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType methodAttributeValue = new AttributeValueType();
+ methodAttributeValue.setDataType(STRING_DATATYPE);
+ String actionDictMethod = policyAdapter.getActionDictMethod();
+ methodAttributeValue.getContent().add(actionDictMethod);
+
+ assignmentMethod.setExpression(new ObjectFactory().createAttributeValue(methodAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentMethod);
+
+ // Add JSON_URL Assignment:
+ String actionBody = policyAdapter.getActionBody();
+ if (actionBody != null) {
+ AttributeAssignmentExpressionType assignmentJsonURL = new AttributeAssignmentExpressionType();
+ assignmentJsonURL.setAttributeId(BODY_ATTRIBUTEID);
+ assignmentJsonURL.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType jsonURLAttributeValue = new AttributeValueType();
+ jsonURLAttributeValue.setDataType(URI_DATATYPE);
+ jsonURLAttributeValue.getContent().add(CONFIG_URL + "/Action/" + policyName + ".json");
+
+ assignmentJsonURL.setExpression(new ObjectFactory().createAttributeValue(jsonURLAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentJsonURL);
+ }
+
+ String headerVal = policyAdapter.getActionDictHeader();
+ if(headerVal != null && !headerVal.trim().isEmpty()){
+ // parse it on : to get number of headers
+ String[] result = headerVal.split(":");
+ for (String eachString : result){
+ // parse each value on =
+ String[] textFieldVals = eachString.split("=");
+ obligation.getAttributeAssignmentExpression().add(addDynamicHeaders(textFieldVals[0], textFieldVals[1]));
+ }
+ }
+
+ obligations.getObligationExpression().add(obligation);
+ return obligations;
+ }
+
+
+ // if compound setting the inner apply here
+ protected ApplyType getInnerActionApply(String value1Label) {
+ ApplyType actionApply = new ApplyType();
+ int index = 0;
+ // check the index for the label.
+ for (String labelAttr : dynamicLabelRuleAlgorithms) {
+ if (labelAttr.equals(value1Label)) {
+ String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
+ // check if the row contains label again
+ for (String labelValue : dynamicLabelRuleAlgorithms) {
+ if (labelValue.equals(value1)) {
+ return getCompoundApply(index);
+ }
+ }
+
+ // Getting the values from the form.
+ String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
+ String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
+ actionApply.setFunctionId(dropDownMap.get(functionKey));
+ // if two text field are rule attributes.
+ if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
+ ApplyType innerActionApply1 = new ApplyType();
+ ApplyType innerActionApply2 = new ApplyType();
+ AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType();
+ AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType();
+ // If selected function is Integer function set integer functionID
+ if (functionKey.toLowerCase().contains("integer")) {
+ innerActionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+ innerActionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+ attributeDesignator1.setDataType(INTEGER_DATATYPE);
+ attributeDesignator2.setDataType(INTEGER_DATATYPE);
+ } else {
+ // If selected function is not a Integer function
+ // set String functionID
+ innerActionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+ innerActionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+ attributeDesignator1.setDataType(STRING_DATATYPE);
+ attributeDesignator2.setDataType(STRING_DATATYPE);
+ }
+ attributeDesignator1.setCategory(CATEGORY_RESOURCE);
+ attributeDesignator2.setCategory(CATEGORY_RESOURCE);
+
+ // Here set actual field values
+ attributeDesignator1.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
+ attributeDesignator2.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
+
+ innerActionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator1));
+ innerActionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator2));
+
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply1));
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply2));
+
+ } else {// if either of one text field is rule attribute.
+ ApplyType innerActionApply = new ApplyType();
+ AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
+ AttributeValueType actionConditionAttributeValue = new AttributeValueType();
+
+ if (functionKey.toLowerCase().contains("integer")) {
+ innerActionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+ actionConditionAttributeValue.setDataType(INTEGER_DATATYPE);
+ attributeDesignator.setDataType(INTEGER_DATATYPE);
+ } else {
+ innerActionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+ actionConditionAttributeValue.setDataType(STRING_DATATYPE);
+ attributeDesignator.setDataType(STRING_DATATYPE);
+ }
+
+ String attributeId = null;
+ String attributeValue = null;
+
+ // Find which textField has rule attribute and set it as
+ attributeId = value1;
+ attributeValue = value2;
+
+ if (attributeId != null) {
+ attributeDesignator.setCategory(CATEGORY_RESOURCE);
+ attributeDesignator.setAttributeId(attributeId);
+ }
+ actionConditionAttributeValue.getContent().add(attributeValue);
+ innerActionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
+ // Decide the order of element based the values.
+ if (attributeId.equals(value1)) {
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
+ actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
+ } else {
+ actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
+ }
+ }
+ }
+ index++;
+ }
+ return actionApply;
+ }
+
+ // if the rule algorithm is multiple compound one setting the apply
+ protected ApplyType getCompoundApply(int index) {
+ ApplyType actionApply = new ApplyType();
+ String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
+ String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
+ String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
+ actionApply.setFunctionId(dropDownMap.get(selectedFunction));
+ actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
+ actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
+ return actionApply;
+ }
+
+ // Adding the dynamic headers if any
+ private AttributeAssignmentExpressionType addDynamicHeaders(String header, String value) {
+ AttributeAssignmentExpressionType assignmentHeaders = new AttributeAssignmentExpressionType();
+ assignmentHeaders.setAttributeId("headers:" + header);
+ assignmentHeaders.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType headersAttributeValue = new AttributeValueType();
+ headersAttributeValue.setDataType(STRING_DATATYPE);
+ headersAttributeValue.getContent().add(value);
+
+ assignmentHeaders.setExpression(new ObjectFactory().createAttributeValue(headersAttributeValue));
+ return assignmentHeaders;
+ }
+
+ private Map<String,String> createDropDownMap(){
+ JPAUtils jpaUtils = null;
+ Map<String, String> dropDownMap = new HashMap<>();
+ try {
+ jpaUtils = JPAUtils.getJPAUtilsInstance(XACMLPapServlet.getEmf());
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured"+e);
+ }
+ if(jpaUtils != null){
+ Map<Datatype, List<FunctionDefinition>> functionMap = jpaUtils.getFunctionDatatypeMap();
+
+ for (Datatype id : functionMap.keySet()) {
+ List<FunctionDefinition> functionDefinitions = (List<FunctionDefinition>) functionMap
+ .get(id);
+ for (FunctionDefinition functionDef : functionDefinitions) {
+ dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid());
+ }
+ }
+ }
+ return dropDownMap;
+ }
+
+ @Override
+ public Object getCorrectPolicyDataObject() {
+ return policyAdapter.getPolicyData();
+ }
+
+} \ No newline at end of file
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java
index f99855cf9..d393d7edb 100644
--- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java
+++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java
@@ -32,9 +32,9 @@ import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.eclipse.persistence.config.PersistenceUnitProperties;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
import com.att.research.xacml.api.Attribute;
import com.att.research.xacml.api.AttributeValue;
@@ -64,7 +64,7 @@ public class OperationHistoryEngine extends StdConfigurableEngine{
public static final String DEFAULT_DESCRIPTION = "PIP for retrieving Operations History from DB";
public static final String DEFAULT_ISSUER = "org:onap:xacml:guard:historydb";
- private static final Log LOGGER= LogFactory.getLog(OperationHistoryEngine.class);
+ private static final Logger LOGGER= FlexLogger.getLogger(OperationHistoryEngine.class);
private static final PIPRequest PIP_REQUEST_ACTOR = new StdPIPRequest(
XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
diff --git a/packages/base/src/files/install/servers/onap/WEB-INF/conf/system.properties b/packages/base/src/files/install/servers/onap/WEB-INF/conf/system.properties
index 484a61768..387a4e29b 100644
--- a/packages/base/src/files/install/servers/onap/WEB-INF/conf/system.properties
+++ b/packages/base/src/files/install/servers/onap/WEB-INF/conf/system.properties
@@ -81,4 +81,4 @@ instance_uuid=8da691c9-987d-43ed-a358-00ac2f35685d
guard_notebook_url=todo_guard_url
#authenticate user server
-authenticate_user_server=${{AUTHENTICATE_USER_SERVERS}} \ No newline at end of file
+authenticate_user_server= \ No newline at end of file
diff --git a/packages/base/src/files/install/servers/pdplp/bin/parserlog.properties b/packages/base/src/files/install/servers/pdplp/bin/parserlog.properties
index 2975ac74f..071a18e4f 100755
--- a/packages/base/src/files/install/servers/pdplp/bin/parserlog.properties
+++ b/packages/base/src/files/install/servers/pdplp/bin/parserlog.properties
@@ -36,7 +36,7 @@ PARSERLOGPATH=IntegrityMonitor.log
# run this cleanup systemlogdb table once a day
CHECK_INTERVAL=86400000
# timeFrame for removing old records from systemlogdb table
-TIME_FRAME=5
+TIME_FRAME=5
#Integrity Monitor values
#database driver for Integrity Monitor
javax.persistence.jdbc.driver=${{JDBC_DRIVER}}