* These are the parameters needed for DB access from the PAP
*/
private static int papIntegrityAuditPeriodSeconds = -1;
- public static String papDbDriver = null;
- public static String papDbUrl = null;
- public static String papDbUser = null;
- public static String papDbPassword = null;
+ private static String papDbDriver = null;
+ private static String papDbUrl = null;
+ private static String papDbUser = null;
+ private static String papDbPassword = null;
private static Integer papTransWait = null;
private static Integer papTransTimeout = null;
private static Integer papAuditTimeout = null;
private IntegrityAudit ia;
//MicroService Model Properties
- public static String msEcompName;
- public static String msPolicyName;
+ private static String msEcompName;
+ private static String msPolicyName;
/*
* This thread may be invoked upon startup to initiate sending PDP policy/pip configuration when
* this servlet starts. Its configurable by the admin.
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE,"XACMLPapServlet", " ERROR: Bad papDbDriver property entry");
throw new PAPException("papDbDriver is null");
}
+ setPapDbDriver(papDbDriver);
papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL);
if(papDbUrl == null){
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE,"XACMLPapServlet", " ERROR: Bad papDbUrl property entry");
throw new PAPException("papDbUrl is null");
}
+ setPapDbUrl(papDbUrl);
papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER);
if(papDbUser == null){
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE,"XACMLPapServlet", " ERROR: Bad papDbUser property entry");
throw new PAPException("papDbUser is null");
}
+ setPapDbUser(papDbUser);
papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD);
if(papDbPassword == null){
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE,"XACMLPapServlet", " ERROR: Bad papDbPassword property entry");
throw new PAPException("papDbPassword is null");
}
+ setPapDbPassword(papDbPassword);
papResourceName = XACMLProperties.getProperty(XACMLRestProperties.PAP_RESOURCE_NAME);
if(papResourceName == null){
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE,"XACMLPapServlet", " ERROR: Bad papResourceName property entry");
}
//Micro Service Properties
msEcompName=properties.getProperty("xacml.policy.msEcompName");
+ setMsEcompName(msEcompName);
msPolicyName=properties.getProperty("xacml.policy.msPolicyName");
+ setMsPolicyName(msPolicyName);
// PDPId File location
XACMLPapServlet.pdpFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_IDFILE);
if (XACMLPapServlet.pdpFile == null) {
try {
apiRequestHandler.doDelete(request, response, loggingContext, apiflag);
} catch (Exception e) {
- e.printStackTrace();
+ LOGGER.error("Exception Occured"+e);
}
if(apiRequestHandler.getNewGroup()!=null){
groupChanged(apiRequestHandler.getNewGroup());
PolicyLogger.info("JSON request from PolicyEngine API: " + json);
// convert Object sent as JSON into local object
StdPDPPolicy policy = PolicyUtils.jsonStringToObject(json, StdPDPPolicy.class);
- Set<PDPPolicy> policies = new HashSet<PDPPolicy>();
+ Set<PDPPolicy> policies = new HashSet<>();
if(policy!=null){
policies.add(policy);
}
//Get the current policies from the Group and Add the new one
- Set<PDPPolicy> currentPoliciesInGroup = new HashSet<PDPPolicy>();
+ Set<PDPPolicy> currentPoliciesInGroup = new HashSet<>();
currentPoliciesInGroup = group.getPolicies();
//If the selected policy is in the group we must remove it because the name is default
Iterator<PDPPolicy> policyIterator = policies.iterator();
}
}
//Update the PDP Group after removing old version of policy
- Set<PDPPolicy> updatedPoliciesInGroup = new HashSet<PDPPolicy>();
+ Set<PDPPolicy> updatedPoliciesInGroup = new HashSet<>();
updatedPoliciesInGroup = group.getPolicies();
//need to remove the policy with default name from group
for (PDPPolicy updatedPolicy : currentPoliciesInGroup) {
throw new PAPException(e.getMessage());
}
papEngine.updateGroup(group);
+ String policyId = "empty";
+ if(policy!=null){
+ policyId = policy.getId();
+ }
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
response.addHeader("operation", "push");
- response.addHeader("policyId", policy.getId());
+ response.addHeader("policyId", policyId);
response.addHeader("groupId", groupId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Group '" + group.getId() + "' updated");
loggingContext.transactionEnded();
auditLogger.info("Success");
- if ((policy.getId().contains("Config_MS_")) || (policy.getId().contains("BRMS_Param"))) {
+ if (policy != null && (policy.getId().contains("Config_MS_")) || (policy.getId().contains("BRMS_Param"))) {
PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance();
if (pushPolicyHandler.preSafetyCheck(policy, CONFIG_HOME)) {
LOGGER.debug("Precheck Successful.");
if (papEngine.getPDP(pdpId) == null) {
// this is a request to create a new PDP object
try{
- acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), pdp.getDescription(), pdp.getJmxPort(),"XACMLPapServlet.doACPut");
+ acPutTransaction.addPdpToGroup(pdp == null ? "PDP is null" : pdp.getId(), group.getId(), pdp == null ? "PDP is null" : pdp.getName(),
+ pdp == null ? "PDP is null" : pdp.getDescription(),
+ pdp == null ? 0 : pdp.getJmxPort(),"XACMLPapServlet.doACPut");
} catch(Exception e){
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while adding pdp to group in the database: "
- +"pdp="+pdp.getId()+",to group="+group.getId());
+ +"pdp="+ (pdp == null ? "PDP is null" : pdp.getId()) +",to group="+group.getId());
throw new PAPException(e.getMessage());
}
papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut");
} catch(Exception e){
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating pdp in the database: "
- +"pdp="+pdp.getId());
+ +"pdp="+(pdp == null ? "PDP is null" : pdp.getId()));
throw new PAPException(e.getMessage());
}
// this is a request to update the pdp
// The Path on the PAP side is not carried on the RESTful interface with the AC
// (because it is local to the PAP)
// so we need to fill that in before submitting the group for update
- ((StdPDPGroup)objectFromJSON).setDirectory(((StdPDPGroup)group).getDirectory());
+ if(objectFromJSON != null){
+ ((StdPDPGroup)objectFromJSON).setDirectory(((StdPDPGroup)group).getDirectory());
+ }
try{
acPutTransaction.updateGroup((StdPDPGroup)objectFromJSON, "XACMLPapServlet.doACPut");
} catch(Exception e){
moveToGroup = papEngine.getGroup(moveToGroupId);
}
// get list of PDPs in the group being deleted so we can notify them that they got changed
- Set<EcompPDP> movedPDPs = new HashSet<EcompPDP>();
+ Set<EcompPDP> movedPDPs = new HashSet<>();
movedPDPs.addAll(group.getEcompPdps());
// do the move/remove
try{
*/
private class Heartbeat implements Runnable {
private PAPPolicyEngine papEngine;
- private Set<EcompPDP> pdps = new HashSet<EcompPDP>();
+ private Set<EcompPDP> pdps = new HashSet<>();
private int heartbeatInterval;
private int heartbeatTimeout;
synchronized(this) {
this.isRunning = true;
}
- HashMap<String, URL> idToURLMap = new HashMap<String, URL>();
+ HashMap<String, URL> idToURLMap = new HashMap<>();
try {
while (this.isRunning()) {
// Wait the given time
HttpURLConnection connection = null;
try {
// Open up the connection
- connection = (HttpURLConnection)pdpURL.openConnection();
- // Setup our method and headers
- connection.setRequestMethod("GET");
- connection.setConnectTimeout(heartbeatTimeout);
- // Authentication
- String encoding = CheckPDP.getEncoding(pdp.getId());
- if(encoding !=null){
- connection.setRequestProperty("Authorization", "Basic " + encoding);
- }
- // Do the connect
- connection.connect();
- if (connection.getResponseCode() == 204) {
- newStatus = connection.getHeaderField(XACMLRestProperties.PROP_PDP_HTTP_HEADER_HB);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Heartbeat '" + pdp.getId() + "' status='" + newStatus + "'");
+ if(pdpURL != null){
+ connection = (HttpURLConnection)pdpURL.openConnection();
+ // Setup our method and headers
+ connection.setRequestMethod("GET");
+ connection.setConnectTimeout(heartbeatTimeout);
+ // Authentication
+ String encoding = CheckPDP.getEncoding(pdp.getId());
+ if(encoding !=null){
+ connection.setRequestProperty("Authorization", "Basic " + encoding);
}
- } else {
- // anything else is an unexpected result
- newStatus = PDPStatus.Status.UNKNOWN.toString();
- PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " Heartbeat connect response code " + connection.getResponseCode() + ": " + pdp.getId());
+ // Do the connect
+ connection.connect();
+ if (connection.getResponseCode() == 204) {
+ newStatus = connection.getHeaderField(XACMLRestProperties.PROP_PDP_HTTP_HEADER_HB);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Heartbeat '" + pdp.getId() + "' status='" + newStatus + "'");
+ }
+ } else {
+ // anything else is an unexpected result
+ newStatus = PDPStatus.Status.UNKNOWN.toString();
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " Heartbeat connect response code " + connection.getResponseCode() + ": " + pdp.getId());
+ }
}
} catch (UnknownHostException e) {
newStatus = PDPStatus.Status.NO_SUCH_HOST.toString();
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", "Heartbeat '" + pdp.getId() + "' connect exception");
} finally {
// cleanup the connection
- connection.disconnect();
+ if(connection != null)
+ connection.disconnect();
}
if ( ! pdp.getStatus().getStatus().toString().equals(newStatus)) {
if (LOGGER.isDebugEnabled()) {
}
} finally {
// cleanup the connection
- connection.disconnect();
+ if(connection != null){
+ connection.disconnect();
+ }
// tell the AC to update it's status info
notifyAC();
}
private class NotifyACThread implements Runnable {
public void run() {
- List<String> disconnectedACs = new ArrayList<String>();
+ List<String> disconnectedACs = new ArrayList<>();
// There should be no Concurrent exception here because the list is a CopyOnWriteArrayList.
// The "for each" loop uses the collection's iterator under the covers, so it should be correct.
for (String acURL : adminConsoleURLStringList) {
disconnectedACs.add(acURL);
} finally {
// cleanup the connection
- connection.disconnect();
+ if(connection != null)
+ connection.disconnect();
}
}
// remove any ACs that are no longer connected
public static PolicyDBDaoTransaction getDbDaoTransaction(){
return policyDBDao.getNewTransaction();
}
+ public static String getPapDbDriver() {
+ return papDbDriver;
+ }
+
+ public static void setPapDbDriver(String papDbDriver) {
+ XACMLPapServlet.papDbDriver = papDbDriver;
+ }
+
+ public static String getPapDbUrl() {
+ return papDbUrl;
+ }
+
+ public static void setPapDbUrl(String papDbUrl) {
+ XACMLPapServlet.papDbUrl = papDbUrl;
+ }
+
+ public static String getPapDbUser() {
+ return papDbUser;
+ }
+
+ public static void setPapDbUser(String papDbUser) {
+ XACMLPapServlet.papDbUser = papDbUser;
+ }
+
+ public static String getPapDbPassword() {
+ return papDbPassword;
+ }
+
+ public static void setPapDbPassword(String papDbPassword) {
+ XACMLPapServlet.papDbPassword = papDbPassword;
+ }
+
+ public static String getMsEcompName() {
+ return msEcompName;
+ }
+
+ public static void setMsEcompName(String msEcompName) {
+ XACMLPapServlet.msEcompName = msEcompName;
+ }
+
+ public static String getMsPolicyName() {
+ return msPolicyName;
+ }
+
+ public static void setMsPolicyName(String msPolicyName) {
+ XACMLPapServlet.msPolicyName = msPolicyName;
+ }
}