diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/RestfulAttestationCertificateAuthority.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/RestfulAttestationCertificateAuthority.java index db00267d..289b998e 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/RestfulAttestationCertificateAuthority.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/RestfulAttestationCertificateAuthority.java @@ -16,9 +16,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySources; import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @@ -95,8 +96,7 @@ public class RestfulAttestationCertificateAuthority extends AttestationCertifica */ @Override @ResponseBody - @RequestMapping(value = "/identity-claim-tpm2/process", - method = RequestMethod.POST, + @PostMapping(value = "/identity-claim-tpm2/process", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE) public byte[] processIdentityClaimTpm2(@RequestBody final byte[] identityClaim) { return super.processIdentityClaimTpm2(identityClaim); @@ -113,8 +113,7 @@ public class RestfulAttestationCertificateAuthority extends AttestationCertifica */ @Override @ResponseBody - @RequestMapping(value = "/request-certificate-tpm2", - method = RequestMethod.POST, + @PostMapping(value = "/request-certificate-tpm2", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE) public byte[] processCertificateRequest(@RequestBody final byte[] certificateRequest) { return super.processCertificateRequest(certificateRequest); @@ -129,7 +128,7 @@ public class RestfulAttestationCertificateAuthority extends AttestationCertifica */ @Override @ResponseBody - @RequestMapping(value = "/public-key", method = RequestMethod.GET) + @GetMapping("/public-key") public byte[] getPublicKey() { return super.getPublicKey(); } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java index 4639e411..92825536 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java @@ -43,9 +43,10 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.util.StreamUtils; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; @@ -244,9 +245,8 @@ public class CertificatePageController extends PageController { * @return the data table */ @ResponseBody - @RequestMapping(value = "/{certificateType}/list", - produces = MediaType.APPLICATION_JSON_VALUE, - method = RequestMethod.GET) + @GetMapping(value = "/{certificateType}/list", + produces = MediaType.APPLICATION_JSON_VALUE) public DataTableResponse getTableData( @PathVariable("certificateType") final String certificateType, final DataTableInput input) { @@ -402,7 +402,7 @@ public class CertificatePageController extends PageController { * @return the redirection view * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "/{certificateType}/upload", method = RequestMethod.POST) + @PostMapping("/{certificateType}/upload") protected RedirectView upload( @PathVariable("certificateType") final String certificateType, @RequestParam("file") final MultipartFile[] files, @@ -440,7 +440,7 @@ public class CertificatePageController extends PageController { * @return redirect to this page * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "/{certificateType}/delete", method = RequestMethod.POST) + @PostMapping("/{certificateType}/delete") public RedirectView delete( @PathVariable("certificateType") final String certificateType, @RequestParam final String id, @@ -510,7 +510,7 @@ public class CertificatePageController extends PageController { * file name) * @throws IOException when writing to response output stream */ - @RequestMapping(value = "/{certificateType}/download", method = RequestMethod.GET) + @GetMapping("/{certificateType}/download") public void download( @PathVariable("certificateType") final String certificateType, @RequestParam final String id, @@ -557,7 +557,7 @@ public class CertificatePageController extends PageController { * @throws IOException when writing to response output stream */ @ResponseBody - @RequestMapping(value = "/trust-chain/download-aca-cert", method = RequestMethod.GET) + @GetMapping("/trust-chain/download-aca-cert") public void downloadAcaCertificate(final HttpServletResponse response) throws IOException { @@ -577,7 +577,7 @@ public class CertificatePageController extends PageController { * file name) * @throws IOException when writing to response output stream */ - @RequestMapping(value = "/trust-chain/bulk", method = RequestMethod.GET) + @GetMapping("/trust-chain/bulk") public void caBulkDownload(final HttpServletResponse response) throws IOException { log.info("Handling request to download all trust chain certificates"); @@ -609,7 +609,7 @@ public class CertificatePageController extends PageController { * file name) * @throws IOException when writing to response output stream */ - @RequestMapping(value = "/platform-credentials/bulk", method = RequestMethod.GET) + @GetMapping("/platform-credentials/bulk") public void pcBulkDownload(final HttpServletResponse response) throws IOException { log.info("Handling request to download all platform certificates"); @@ -641,7 +641,7 @@ public class CertificatePageController extends PageController { * file name) * @throws IOException when writing to response output stream */ - @RequestMapping(value = "/issued-certificates/bulk", method = RequestMethod.GET) + @GetMapping("/issued-certificates/bulk") public void icBulkDownload(final HttpServletResponse response) throws IOException { log.info("Handling request to download all issued certificates"); @@ -674,7 +674,7 @@ public class CertificatePageController extends PageController { * file name) * @throws IOException when writing to response output stream */ - @RequestMapping(value = "/endorsement-key-credentials/bulk", method = RequestMethod.GET) + @GetMapping("/endorsement-key-credentials/bulk") public void ekBulkDownload(final HttpServletResponse response) throws IOException { log.info("Handling request to download all endorsement certificates"); diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java index ecd94bc8..a304a687 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java @@ -13,8 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.view.RedirectView; @@ -118,7 +118,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-pc-validation", method = RequestMethod.POST) + @PostMapping("update-pc-validation") public RedirectView updatePcVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -169,7 +169,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-pc-attribute-validation", method = RequestMethod.POST) + @PostMapping("update-pc-attribute-validation") public RedirectView updatePcAttributeVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -219,7 +219,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-revision-ignore", method = RequestMethod.POST) + @PostMapping("update-revision-ignore") public RedirectView updateIgnoreRevisionAttribute(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -270,7 +270,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-issue-attestation", method = RequestMethod.POST) + @PostMapping("update-issue-attestation") public RedirectView updateAttestationVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -314,7 +314,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-issue-devid", method = RequestMethod.POST) + @PostMapping("update-issue-devid") public RedirectView updateDevIdVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -359,7 +359,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-expire-on", method = RequestMethod.POST) + @PostMapping("update-expire-on") public RedirectView updateExpireOnVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -429,7 +429,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-devid-expire-on", method = RequestMethod.POST) + @PostMapping("update-devid-expire-on") public RedirectView updateDevIdExpireOnVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -499,7 +499,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-threshold", method = RequestMethod.POST) + @PostMapping("update-threshold") public RedirectView updateThresholdVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -570,7 +570,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-devid-threshold", method = RequestMethod.POST) + @PostMapping("update-devid-threshold") public RedirectView updateDevIdThresholdVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -640,7 +640,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-ec-validation", method = RequestMethod.POST) + @PostMapping("update-ec-validation") public RedirectView updateEcVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -692,7 +692,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-firmware-validation", method = RequestMethod.POST) + @PostMapping("update-firmware-validation") public RedirectView updateFirmwareVal(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { @@ -749,7 +749,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-ima-ignore", method = RequestMethod.POST) + @PostMapping("update-ima-ignore") public RedirectView updateIgnoreIma(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { // set the data received to be populated back into the form @@ -800,7 +800,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-tboot-ignore", method = RequestMethod.POST) + @PostMapping("update-tboot-ignore") public RedirectView updateIgnoreTboot(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { // set the data received to be populated back into the form @@ -851,7 +851,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-gpt-ignore", method = RequestMethod.POST) + @PostMapping("update-gpt-ignore") public RedirectView updateIgnoreGptEvents(@ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) throws URISyntaxException { // set the data received to be populated back into the form @@ -902,7 +902,7 @@ public class PolicyPageController extends PageController { * @return View containing the url and parameters * @throws URISyntaxException if malformed URI */ - @RequestMapping(value = "update-os-evt-ignore", method = RequestMethod.POST) + @PostMapping("update-os-evt-ignore") public RedirectView updateIgnoreOsEvents( @ModelAttribute final PolicyPageModel ppModel, final RedirectAttributes attr) @@ -995,6 +995,15 @@ public class PolicyPageController extends PageController { return policy; } + /** + * Helper method that saves the provided policy to the database and displays a success message. + * + * @param ppModel policy page model + * @param model model + * @param messages page messages + * @param successMessage success message + * @param settings policy settings + */ private void savePolicyAndApplySuccessMessage( final PolicyPageModel ppModel, final Map model, final PageMessages messages, final String successMessage, @@ -1004,7 +1013,7 @@ public class PolicyPageController extends PageController { // Log and set the success message messages.addSuccess(successMessage); - log.debug("ACA Policy set to: " + ppModel.toString()); + log.debug("ACA Policy set to: {}", ppModel.toString()); model.put(MESSAGES_ATTRIBUTE, messages); } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java index fc84e213..5c96cec3 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java @@ -29,8 +29,9 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.util.StreamUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; @@ -107,16 +108,15 @@ public class ReferenceManifestPageController extends PageController getTableData( @Valid final DataTableInput input) { - log.debug("Handling request for summary list: " + input); + log.debug("Handling request for summary list: {}", input); String orderColumnName = input.getOrderColumnName(); - log.info("Ordering on column: " + orderColumnName); - log.info("Querying with the following dataTableInput: " + input); + log.info("Ordering on column: {}", orderColumnName); + log.info("Querying with the following dataTableInput: {}", input); FilteredRecordsList records = new FilteredRecordsList<>(); int currentPage = input.getStart() / input.getLength(); @@ -137,7 +137,7 @@ public class ReferenceManifestPageController extends PageController(records, input); } @@ -150,7 +150,7 @@ public class ReferenceManifestPageController extends PageController baseRims = new ArrayList<>(); List supportRims = new ArrayList<>(); - log.info(String.format("Processing %s uploaded files", files.length)); + log.info("Processing {} uploaded files", files.length); // loop through the files for (MultipartFile file : files) { @@ -182,16 +182,16 @@ public class ReferenceManifestPageController extends PageController { - log.info(String.format("Storing swidtag %s", rim.getFileName())); + log.info("Storing swidtag {}", rim.getFileName()); this.referenceManifestRepository.save(rim); }); supportRims.forEach((rim) -> { - log.info(String.format("Storing event log %s", rim.getFileName())); + log.info("Storing event log {}", rim.getFileName()); this.referenceManifestRepository.save(rim); }); @@ -223,10 +223,10 @@ public class ReferenceManifestPageController extends PageController model = new HashMap<>(); PageMessages messages = new PageMessages(); @@ -267,11 +267,11 @@ public class ReferenceManifestPageController extends PageController baseRims = new LinkedList<>(); baseRims.addAll(this.referenceManifestRepository .getBaseByManufacturerModel(supportRim.getPlatformManufacturer(), @@ -522,11 +523,7 @@ public class ReferenceManifestPageController extends PageController { * information */ @ResponseBody - @RequestMapping(value = "/list", - produces = MediaType.APPLICATION_JSON_VALUE, - method = RequestMethod.GET) + @GetMapping(value = "/list", + produces = MediaType.APPLICATION_JSON_VALUE) public DataTableResponse getTableData( @Valid final DataTableInput input) { - log.info("Handling request for summary list: " + input); + log.info("Handling request for summary list: {}", input); String orderColumnName = input.getOrderColumnName(); - log.info("Ordering on column: " + orderColumnName); + log.info("Ordering on column: {}", orderColumnName); // check that the alert is not archived and that it is in the specified report CriteriaModifier criteriaModifier = new CriteriaModifier() { @@ -106,7 +105,7 @@ public class RimDatabasePageController extends PageController { } }; - log.info("Querying with the following dataTableInput: " + input.toString()); + log.info("Querying with the following dataTableInput: {}", input); FilteredRecordsList referenceDigestValues = new FilteredRecordsList<>(); @@ -139,7 +138,7 @@ public class RimDatabasePageController extends PageController { } } - log.debug("Returning list of size: " + referenceDigestValues.size()); + log.debug("Returning list of size: {}", referenceDigestValues.size()); return new DataTableResponse<>(referenceDigestValues, input); } } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index ba4fad8e..e9926aa3 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -28,9 +28,9 @@ import org.springframework.data.domain.Sort; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @@ -111,8 +111,7 @@ public class ValidationReportsPageController extends PageController getTableData( final DataTableInput input) { @@ -146,7 +145,7 @@ public class ValidationReportsPageController extends PageController