@Test public void testCreatePolicy() throws Exception { Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn(DEVL); Mockito.when(httpServletRequest.getMethod()).thenReturn(PUT); Mockito.when(httpServletRequest.getParameter(APIFLAG)).thenReturn(API2); Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API); Mockito.when(httpServletRequest.getParameter("policy")).thenReturn(POLICY_NAME); stdEngine = new StdEngine(Paths.get(PDPS)); dbd.setPapEngine(stdEngine); consoleAndApi.doAcPut(httpServletRequest, httpServletResponse, DEFAULT, logContext, stdEngine); assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus()); }
public void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId, OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { PolicyDbDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { String userId = request.getParameter("userId"); OnapPDPGroup group = papEngine.getGroup(groupId); if (group == null) { String message = UNKNOWN_GROUP_ID + groupId + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_NOT_FOUND, message); acPutTransaction.rollbackTransaction(); return; } if (request.getParameter("policy") != null) { loggingContext.setServiceName("AC:PAP.putPolicy"); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PARTIALLY IMPLEMENTED!!! ACTUAL CHANGES SHOULD BE MADE BY PAP SERVLET!!! "); response.setStatus(HttpServletResponse.SC_NO_CONTENT); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); acPutTransaction.rollbackTransaction(); } else if (request.getParameter(PDP_ID) != null) { String pdpId = request.getParameter(PDP_ID); if (papEngine.getPDP(pdpId) == null) { loggingContext.setServiceName("AC:PAP.createPDP"); } else { loggingContext.setServiceName("AC:PAP.updatePDP"); } String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDP.class); } catch (Exception e) { LOGGER.error(e); } if (pdpId == null || objectFromJson == null || !(objectFromJson instanceof StdPDP) || ((StdPDP) objectFromJson).getId() == null || !((StdPDP) objectFromJson).getId().equals(pdpId)) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PDP new/update had bad input. pdpId=" + pdpId + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input pdpid for object:" + objectFromJson); } StdPDP pdp = (StdPDP) objectFromJson; if (pdp != null) { OnapPDP origPdp = null; try { origPdp = papEngine.getPDP(pdpId); } catch (PAPException e) { LOGGER.error(e); } if (origPdp == null) { try { acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), pdp.getDescription(), pdp.getJmxPort(), XACML_PAP_SERVLET_DO_AC_PUT); papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort()); } 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()); throw new PAPException(e.getMessage()); } } else { try { acPutTransaction.updatePdp(pdp, XACML_PAP_SERVLET_DO_AC_PUT); papEngine.updatePDP(pdp); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " Error while updating pdp in the database: " + "pdp=" + pdp.getId()); throw new PAPException(e.getMessage()); } } response.setStatus(HttpServletResponse.SC_NO_CONTENT); if (LOGGER.isDebugEnabled()) { LOGGER.debug("PDP '" + pdpId + "' created/updated"); } ((StdPDPGroup) group).resetStatus(); getPapInstance().pdpChanged(pdp, loggingContext); loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } else { try { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, XACMLPAPSERVLET, " Error while adding pdp to group in the database: " + "pdp=null" + TO_GROUP + group.getId()); throw new PAPException("PDP is null"); } catch (Exception e) { throw new PAPException("PDP is null" + e.getMessage() + e); } } } else if (request.getParameter("pipId") != null) { loggingContext.setServiceName("AC:PAP.putPIP"); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); acPutTransaction.rollbackTransaction(); } else { loggingContext.setServiceName("AC:PAP.updateGroup"); String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDPGroup.class); } catch (Exception e) { LOGGER.error(e); } if (!(objectFromJson instanceof StdPDPGroup) || !((StdPDPGroup) objectFromJson).getId().equals(group.getId())) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input id for object:" + objectFromJson); } if (objectFromJson != null) { ((StdPDPGroup) objectFromJson).setDirectory(((StdPDPGroup) group).getDirectory()); } try { if ("delete".equals(((StdPDPGroup) objectFromJson).getOperation())) { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, "XACMLPapServlet.doDelete", userId); } else { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, XACML_PAP_SERVLET_DO_AC_PUT, userId); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: " + "group=" + group.getId()); LOGGER.error(e); throw new PAPException(e.getMessage()); } PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance(); OnapPDPGroup updatedGroup = (StdPDPGroup) objectFromJson; if (pushPolicyHandler.preSafetyCheck(updatedGroup, XACMLPapServlet.getConfigHome())) { LOGGER.debug("Precheck Successful."); } 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"); } loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); getPapInstance().groupChanged(group, loggingContext); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } } catch (PAPException e) { LOGGER.debug(e); acPutTransaction.rollbackTransaction(); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC PUT exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
ConsoleAndApiService { public void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId, OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { PolicyDbDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { String userId = request.getParameter("userId"); OnapPDPGroup group = papEngine.getGroup(groupId); if (group == null) { String message = UNKNOWN_GROUP_ID + groupId + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_NOT_FOUND, message); acPutTransaction.rollbackTransaction(); return; } if (request.getParameter("policy") != null) { loggingContext.setServiceName("AC:PAP.putPolicy"); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PARTIALLY IMPLEMENTED!!! ACTUAL CHANGES SHOULD BE MADE BY PAP SERVLET!!! "); response.setStatus(HttpServletResponse.SC_NO_CONTENT); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); acPutTransaction.rollbackTransaction(); } else if (request.getParameter(PDP_ID) != null) { String pdpId = request.getParameter(PDP_ID); if (papEngine.getPDP(pdpId) == null) { loggingContext.setServiceName("AC:PAP.createPDP"); } else { loggingContext.setServiceName("AC:PAP.updatePDP"); } String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDP.class); } catch (Exception e) { LOGGER.error(e); } if (pdpId == null || objectFromJson == null || !(objectFromJson instanceof StdPDP) || ((StdPDP) objectFromJson).getId() == null || !((StdPDP) objectFromJson).getId().equals(pdpId)) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PDP new/update had bad input. pdpId=" + pdpId + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input pdpid for object:" + objectFromJson); } StdPDP pdp = (StdPDP) objectFromJson; if (pdp != null) { OnapPDP origPdp = null; try { origPdp = papEngine.getPDP(pdpId); } catch (PAPException e) { LOGGER.error(e); } if (origPdp == null) { try { acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), pdp.getDescription(), pdp.getJmxPort(), XACML_PAP_SERVLET_DO_AC_PUT); papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort()); } 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()); throw new PAPException(e.getMessage()); } } else { try { acPutTransaction.updatePdp(pdp, XACML_PAP_SERVLET_DO_AC_PUT); papEngine.updatePDP(pdp); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " Error while updating pdp in the database: " + "pdp=" + pdp.getId()); throw new PAPException(e.getMessage()); } } response.setStatus(HttpServletResponse.SC_NO_CONTENT); if (LOGGER.isDebugEnabled()) { LOGGER.debug("PDP '" + pdpId + "' created/updated"); } ((StdPDPGroup) group).resetStatus(); getPapInstance().pdpChanged(pdp, loggingContext); loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } else { try { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, XACMLPAPSERVLET, " Error while adding pdp to group in the database: " + "pdp=null" + TO_GROUP + group.getId()); throw new PAPException("PDP is null"); } catch (Exception e) { throw new PAPException("PDP is null" + e.getMessage() + e); } } } else if (request.getParameter("pipId") != null) { loggingContext.setServiceName("AC:PAP.putPIP"); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); acPutTransaction.rollbackTransaction(); } else { loggingContext.setServiceName("AC:PAP.updateGroup"); String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDPGroup.class); } catch (Exception e) { LOGGER.error(e); } if (!(objectFromJson instanceof StdPDPGroup) || !((StdPDPGroup) objectFromJson).getId().equals(group.getId())) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input id for object:" + objectFromJson); } if (objectFromJson != null) { ((StdPDPGroup) objectFromJson).setDirectory(((StdPDPGroup) group).getDirectory()); } try { if ("delete".equals(((StdPDPGroup) objectFromJson).getOperation())) { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, "XACMLPapServlet.doDelete", userId); } else { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, XACML_PAP_SERVLET_DO_AC_PUT, userId); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: " + "group=" + group.getId()); LOGGER.error(e); throw new PAPException(e.getMessage()); } PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance(); OnapPDPGroup updatedGroup = (StdPDPGroup) objectFromJson; if (pushPolicyHandler.preSafetyCheck(updatedGroup, XACMLPapServlet.getConfigHome())) { LOGGER.debug("Precheck Successful."); } 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"); } loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); getPapInstance().groupChanged(group, loggingContext); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } } catch (PAPException e) { LOGGER.debug(e); acPutTransaction.rollbackTransaction(); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC PUT exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } } }
ConsoleAndApiService { public void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId, OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { PolicyDbDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { String userId = request.getParameter("userId"); OnapPDPGroup group = papEngine.getGroup(groupId); if (group == null) { String message = UNKNOWN_GROUP_ID + groupId + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_NOT_FOUND, message); acPutTransaction.rollbackTransaction(); return; } if (request.getParameter("policy") != null) { loggingContext.setServiceName("AC:PAP.putPolicy"); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PARTIALLY IMPLEMENTED!!! ACTUAL CHANGES SHOULD BE MADE BY PAP SERVLET!!! "); response.setStatus(HttpServletResponse.SC_NO_CONTENT); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); acPutTransaction.rollbackTransaction(); } else if (request.getParameter(PDP_ID) != null) { String pdpId = request.getParameter(PDP_ID); if (papEngine.getPDP(pdpId) == null) { loggingContext.setServiceName("AC:PAP.createPDP"); } else { loggingContext.setServiceName("AC:PAP.updatePDP"); } String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDP.class); } catch (Exception e) { LOGGER.error(e); } if (pdpId == null || objectFromJson == null || !(objectFromJson instanceof StdPDP) || ((StdPDP) objectFromJson).getId() == null || !((StdPDP) objectFromJson).getId().equals(pdpId)) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PDP new/update had bad input. pdpId=" + pdpId + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input pdpid for object:" + objectFromJson); } StdPDP pdp = (StdPDP) objectFromJson; if (pdp != null) { OnapPDP origPdp = null; try { origPdp = papEngine.getPDP(pdpId); } catch (PAPException e) { LOGGER.error(e); } if (origPdp == null) { try { acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), pdp.getDescription(), pdp.getJmxPort(), XACML_PAP_SERVLET_DO_AC_PUT); papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort()); } 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()); throw new PAPException(e.getMessage()); } } else { try { acPutTransaction.updatePdp(pdp, XACML_PAP_SERVLET_DO_AC_PUT); papEngine.updatePDP(pdp); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " Error while updating pdp in the database: " + "pdp=" + pdp.getId()); throw new PAPException(e.getMessage()); } } response.setStatus(HttpServletResponse.SC_NO_CONTENT); if (LOGGER.isDebugEnabled()) { LOGGER.debug("PDP '" + pdpId + "' created/updated"); } ((StdPDPGroup) group).resetStatus(); getPapInstance().pdpChanged(pdp, loggingContext); loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } else { try { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, XACMLPAPSERVLET, " Error while adding pdp to group in the database: " + "pdp=null" + TO_GROUP + group.getId()); throw new PAPException("PDP is null"); } catch (Exception e) { throw new PAPException("PDP is null" + e.getMessage() + e); } } } else if (request.getParameter("pipId") != null) { loggingContext.setServiceName("AC:PAP.putPIP"); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); acPutTransaction.rollbackTransaction(); } else { loggingContext.setServiceName("AC:PAP.updateGroup"); String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDPGroup.class); } catch (Exception e) { LOGGER.error(e); } if (!(objectFromJson instanceof StdPDPGroup) || !((StdPDPGroup) objectFromJson).getId().equals(group.getId())) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input id for object:" + objectFromJson); } if (objectFromJson != null) { ((StdPDPGroup) objectFromJson).setDirectory(((StdPDPGroup) group).getDirectory()); } try { if ("delete".equals(((StdPDPGroup) objectFromJson).getOperation())) { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, "XACMLPapServlet.doDelete", userId); } else { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, XACML_PAP_SERVLET_DO_AC_PUT, userId); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: " + "group=" + group.getId()); LOGGER.error(e); throw new PAPException(e.getMessage()); } PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance(); OnapPDPGroup updatedGroup = (StdPDPGroup) objectFromJson; if (pushPolicyHandler.preSafetyCheck(updatedGroup, XACMLPapServlet.getConfigHome())) { LOGGER.debug("Precheck Successful."); } 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"); } loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); getPapInstance().groupChanged(group, loggingContext); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } } catch (PAPException e) { LOGGER.debug(e); acPutTransaction.rollbackTransaction(); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC PUT exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }  }
ConsoleAndApiService { public void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId, OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { PolicyDbDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { String userId = request.getParameter("userId"); OnapPDPGroup group = papEngine.getGroup(groupId); if (group == null) { String message = UNKNOWN_GROUP_ID + groupId + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_NOT_FOUND, message); acPutTransaction.rollbackTransaction(); return; } if (request.getParameter("policy") != null) { loggingContext.setServiceName("AC:PAP.putPolicy"); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PARTIALLY IMPLEMENTED!!! ACTUAL CHANGES SHOULD BE MADE BY PAP SERVLET!!! "); response.setStatus(HttpServletResponse.SC_NO_CONTENT); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); acPutTransaction.rollbackTransaction(); } else if (request.getParameter(PDP_ID) != null) { String pdpId = request.getParameter(PDP_ID); if (papEngine.getPDP(pdpId) == null) { loggingContext.setServiceName("AC:PAP.createPDP"); } else { loggingContext.setServiceName("AC:PAP.updatePDP"); } String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDP.class); } catch (Exception e) { LOGGER.error(e); } if (pdpId == null || objectFromJson == null || !(objectFromJson instanceof StdPDP) || ((StdPDP) objectFromJson).getId() == null || !((StdPDP) objectFromJson).getId().equals(pdpId)) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PDP new/update had bad input. pdpId=" + pdpId + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input pdpid for object:" + objectFromJson); } StdPDP pdp = (StdPDP) objectFromJson; if (pdp != null) { OnapPDP origPdp = null; try { origPdp = papEngine.getPDP(pdpId); } catch (PAPException e) { LOGGER.error(e); } if (origPdp == null) { try { acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), pdp.getDescription(), pdp.getJmxPort(), XACML_PAP_SERVLET_DO_AC_PUT); papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort()); } 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()); throw new PAPException(e.getMessage()); } } else { try { acPutTransaction.updatePdp(pdp, XACML_PAP_SERVLET_DO_AC_PUT); papEngine.updatePDP(pdp); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " Error while updating pdp in the database: " + "pdp=" + pdp.getId()); throw new PAPException(e.getMessage()); } } response.setStatus(HttpServletResponse.SC_NO_CONTENT); if (LOGGER.isDebugEnabled()) { LOGGER.debug("PDP '" + pdpId + "' created/updated"); } ((StdPDPGroup) group).resetStatus(); getPapInstance().pdpChanged(pdp, loggingContext); loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } else { try { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, XACMLPAPSERVLET, " Error while adding pdp to group in the database: " + "pdp=null" + TO_GROUP + group.getId()); throw new PAPException("PDP is null"); } catch (Exception e) { throw new PAPException("PDP is null" + e.getMessage() + e); } } } else if (request.getParameter("pipId") != null) { loggingContext.setServiceName("AC:PAP.putPIP"); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); acPutTransaction.rollbackTransaction(); } else { loggingContext.setServiceName("AC:PAP.updateGroup"); String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDPGroup.class); } catch (Exception e) { LOGGER.error(e); } if (!(objectFromJson instanceof StdPDPGroup) || !((StdPDPGroup) objectFromJson).getId().equals(group.getId())) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input id for object:" + objectFromJson); } if (objectFromJson != null) { ((StdPDPGroup) objectFromJson).setDirectory(((StdPDPGroup) group).getDirectory()); } try { if ("delete".equals(((StdPDPGroup) objectFromJson).getOperation())) { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, "XACMLPapServlet.doDelete", userId); } else { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, XACML_PAP_SERVLET_DO_AC_PUT, userId); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: " + "group=" + group.getId()); LOGGER.error(e); throw new PAPException(e.getMessage()); } PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance(); OnapPDPGroup updatedGroup = (StdPDPGroup) objectFromJson; if (pushPolicyHandler.preSafetyCheck(updatedGroup, XACMLPapServlet.getConfigHome())) { LOGGER.debug("Precheck Successful."); } 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"); } loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); getPapInstance().groupChanged(group, loggingContext); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } } catch (PAPException e) { LOGGER.debug(e); acPutTransaction.rollbackTransaction(); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC PUT exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }  void doAcPost(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcGet(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcDelete(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); }
ConsoleAndApiService { public void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId, OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { PolicyDbDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { String userId = request.getParameter("userId"); OnapPDPGroup group = papEngine.getGroup(groupId); if (group == null) { String message = UNKNOWN_GROUP_ID + groupId + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_NOT_FOUND, message); acPutTransaction.rollbackTransaction(); return; } if (request.getParameter("policy") != null) { loggingContext.setServiceName("AC:PAP.putPolicy"); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PARTIALLY IMPLEMENTED!!! ACTUAL CHANGES SHOULD BE MADE BY PAP SERVLET!!! "); response.setStatus(HttpServletResponse.SC_NO_CONTENT); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); acPutTransaction.rollbackTransaction(); } else if (request.getParameter(PDP_ID) != null) { String pdpId = request.getParameter(PDP_ID); if (papEngine.getPDP(pdpId) == null) { loggingContext.setServiceName("AC:PAP.createPDP"); } else { loggingContext.setServiceName("AC:PAP.updatePDP"); } String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDP.class); } catch (Exception e) { LOGGER.error(e); } if (pdpId == null || objectFromJson == null || !(objectFromJson instanceof StdPDP) || ((StdPDP) objectFromJson).getId() == null || !((StdPDP) objectFromJson).getId().equals(pdpId)) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PDP new/update had bad input. pdpId=" + pdpId + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input pdpid for object:" + objectFromJson); } StdPDP pdp = (StdPDP) objectFromJson; if (pdp != null) { OnapPDP origPdp = null; try { origPdp = papEngine.getPDP(pdpId); } catch (PAPException e) { LOGGER.error(e); } if (origPdp == null) { try { acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), pdp.getDescription(), pdp.getJmxPort(), XACML_PAP_SERVLET_DO_AC_PUT); papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort()); } 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()); throw new PAPException(e.getMessage()); } } else { try { acPutTransaction.updatePdp(pdp, XACML_PAP_SERVLET_DO_AC_PUT); papEngine.updatePDP(pdp); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " Error while updating pdp in the database: " + "pdp=" + pdp.getId()); throw new PAPException(e.getMessage()); } } response.setStatus(HttpServletResponse.SC_NO_CONTENT); if (LOGGER.isDebugEnabled()) { LOGGER.debug("PDP '" + pdpId + "' created/updated"); } ((StdPDPGroup) group).resetStatus(); getPapInstance().pdpChanged(pdp, loggingContext); loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } else { try { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, XACMLPAPSERVLET, " Error while adding pdp to group in the database: " + "pdp=null" + TO_GROUP + group.getId()); throw new PAPException("PDP is null"); } catch (Exception e) { throw new PAPException("PDP is null" + e.getMessage() + e); } } } else if (request.getParameter("pipId") != null) { loggingContext.setServiceName("AC:PAP.putPIP"); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); acPutTransaction.rollbackTransaction(); } else { loggingContext.setServiceName("AC:PAP.updateGroup"); String json = null; try { Scanner scanner = new Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); } catch (IOException e) { LOGGER.error(e); } LOGGER.info("JSON request from AC: " + json); ObjectMapper mapper = new ObjectMapper(); Object objectFromJson = null; try { objectFromJson = mapper.readValue(json, StdPDPGroup.class); } catch (Exception e) { LOGGER.error(e); } if (!(objectFromJson instanceof StdPDPGroup) || !((StdPDPGroup) objectFromJson).getId().equals(group.getId())) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON=" + objectFromJson); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input id for object:" + objectFromJson); } if (objectFromJson != null) { ((StdPDPGroup) objectFromJson).setDirectory(((StdPDPGroup) group).getDirectory()); } try { if ("delete".equals(((StdPDPGroup) objectFromJson).getOperation())) { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, "XACMLPapServlet.doDelete", userId); } else { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, XACML_PAP_SERVLET_DO_AC_PUT, userId); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: " + "group=" + group.getId()); LOGGER.error(e); throw new PAPException(e.getMessage()); } PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance(); OnapPDPGroup updatedGroup = (StdPDPGroup) objectFromJson; if (pushPolicyHandler.preSafetyCheck(updatedGroup, XACMLPapServlet.getConfigHome())) { LOGGER.debug("Precheck Successful."); } 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"); } loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); getPapInstance().groupChanged(group, loggingContext); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); } } catch (PAPException e) { LOGGER.debug(e); acPutTransaction.rollbackTransaction(); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC PUT exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }  void doAcPost(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcGet(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine); void doAcDelete(HttpServletRequest request, HttpServletResponse response, String groupId,
            OnapLoggingContext loggingContext, PAPPolicyEngine papEngine);  }