From 31dcbbf9258b449b660e61cab1fd7041838a2252 Mon Sep 17 00:00:00 2001 From: nikpapag <82569427+nikpapag@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:35:45 +0000 Subject: [PATCH 1/7] Update MVCController.java --- .../java/com/nikp/payment/api/MVCController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java index 7b91c4d7..afa2b69d 100644 --- a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java +++ b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java @@ -80,4 +80,16 @@ public String paymentForm( @ModelAttribute PaymentDto paymentDto,@RequestParam(n return "createOriginal"; } + + @GetMapping("/mvc/makePayment") + public String paymentForm( @ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") + String number, @RequestParam(name = "sename", required = false, defaultValue = "") + String sename, Model model) { + System.out.println("Notification: creating payment using the main form"); + model.addAttribute("paymentDto", new PaymentDto()); + model.addAttribute("number",buildNumber ); + model.addAttribute("sename", seName); + + return "createOriginal"; + } } From 1962608c64ee1ef208583407377dc3974fd9de11 Mon Sep 17 00:00:00 2001 From: nikpapag <82569427+nikpapag@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:38:27 +0000 Subject: [PATCH 2/7] Update MVCController.java --- .../src/main/java/com/nikp/payment/api/MVCController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java index afa2b69d..cdb3960e 100644 --- a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java +++ b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java @@ -82,7 +82,7 @@ public String paymentForm( @ModelAttribute PaymentDto paymentDto,@RequestParam(n } @GetMapping("/mvc/makePayment") - public String paymentForm( @ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") + public String paymentFormNew( @ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") String number, @RequestParam(name = "sename", required = false, defaultValue = "") String sename, Model model) { System.out.println("Notification: creating payment using the main form"); From 6033a2c08b1964209680b555901bc198e5953ea0 Mon Sep 17 00:00:00 2001 From: nikpapag <82569427+nikpapag@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:42:00 +0100 Subject: [PATCH 3/7] Update MVCController.java --- .../com/nikp/payment/api/MVCController.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java index cdb3960e..266fd162 100644 --- a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java +++ b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java @@ -22,7 +22,7 @@ import javax.annotation.PostConstruct; import javax.ws.rs.ForbiddenException; - +import com.nikp.captcha.CaptchaService; @Controller public class MVCController { @@ -43,6 +43,10 @@ private void init() { @Autowired private EventBus eventBus; + + @Autowired + private CaptchaService captchaService; + @RequestMapping("/") public String indexView(@RequestParam(name = "number", required = false, defaultValue = "") String number, @RequestParam(name = "sename", required = false, defaultValue = "") @@ -56,10 +60,27 @@ public String indexView(@RequestParam(name = "number", required = false, default @PostMapping("/mvc/payment") - public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") + public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam(value="g-recaptcha-response") String response,@RequestParam(name = "number", required = false, defaultValue = "") String number, @RequestParam(name = "sename", required = false, defaultValue = "") String sename, Model model) { + if(paymentDto.getBankValidation().isEmpty()) + { + try { + captchaService.processResponse(response); + }catch(BankValidationException e) { + + model.addAttribute(paymentDto); + model.addAttribute("response",response); + + return "bankError"; + }catch(ReCaptchaInvalidException re) + { + return "captchaError"; + }catch(ReCaptchaUnavailableException reU) { + return "captchaError"; + } + } paymentRepository.save(new Payment(paymentDto.getUserId(), paymentDto.getAccountFrom(), paymentDto.getAccountTo(), paymentDto.getAmount())); eventBus.publish(new Event("SAVE", "Save payment" + paymentDto)); System.out.println("Notification: added payment from user "+paymentDto.getUserId()); @@ -92,4 +113,20 @@ public String paymentFormNew( @ModelAttribute PaymentDto paymentDto,@RequestPara return "createOriginal"; } + + + @PostMapping("/mvc/payment/bank") + public String paymentSubmitBank(@ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") + String number, @RequestParam(name = "sename", required = false, defaultValue = "") + String sename, Model model) { + + paymentRepository.save(new Payment(paymentDto.getUserId(), paymentDto.getAccountFrom(), paymentDto.getAccountTo(), paymentDto.getAmount())); + eventBus.publish(new Event("SAVE", "Save payment" + paymentDto)); + model.addAttribute("list", paymentRepository.findAll()); + model.addAttribute("number",buildNumber ); + model.addAttribute("sename", seName); + return "allPayments"; + + + } } From d049ae1f838435b2e5c81f018188c13a795b924b Mon Sep 17 00:00:00 2001 From: nikpapag <82569427+nikpapag@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:43:17 +0100 Subject: [PATCH 4/7] Update MVCControllerTest.java --- .../src/test/java/com/nikp/payment/api/MVCControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payment-service/src/test/java/com/nikp/payment/api/MVCControllerTest.java b/payment-service/src/test/java/com/nikp/payment/api/MVCControllerTest.java index b24bda78..98089551 100644 --- a/payment-service/src/test/java/com/nikp/payment/api/MVCControllerTest.java +++ b/payment-service/src/test/java/com/nikp/payment/api/MVCControllerTest.java @@ -96,6 +96,6 @@ public void shouldPostNewPayment() throws Exception { .contentType(MediaType.APPLICATION_FORM_URLENCODED) .sessionAttr("paymentDto", paymentDto) ) - .andExpect(status().isOk()); + .andExpect(status().is4xxClientError()); } -} \ No newline at end of file +} From bbdec3152db2651fd5d7212bc612f82e1dca20d8 Mon Sep 17 00:00:00 2001 From: nikpapag <82569427+nikpapag@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:43:46 +0100 Subject: [PATCH 5/7] Update MVCControllerSecurityTest.java --- .../nikp/payment/api/security/MVCControllerSecurityTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payment-service/src/test/java/com/nikp/payment/api/security/MVCControllerSecurityTest.java b/payment-service/src/test/java/com/nikp/payment/api/security/MVCControllerSecurityTest.java index c3f19a9e..d1b343cb 100644 --- a/payment-service/src/test/java/com/nikp/payment/api/security/MVCControllerSecurityTest.java +++ b/payment-service/src/test/java/com/nikp/payment/api/security/MVCControllerSecurityTest.java @@ -92,7 +92,7 @@ public void shouldPostNewPaymentWithCsrf() throws Exception { .contentType(MediaType.APPLICATION_FORM_URLENCODED).with(csrf()) .sessionAttr("paymentDto", paymentDto) ) - .andExpect(status().isOk()); + .andExpect(status().is4xxClientError()); } @Test @@ -111,4 +111,4 @@ public void shouldReturn403IfPostWithoutCsrf() throws Exception { ) .andExpect(status().is(403)); } -} \ No newline at end of file +} From c742ca8b01fc0f05b51a0f076d8970e15dcfc41d Mon Sep 17 00:00:00 2001 From: nikpapag <82569427+nikpapag@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:42:39 +0100 Subject: [PATCH 6/7] Update MVCController.java --- .../com/nikp/payment/api/MVCController.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java index 266fd162..a6f79763 100644 --- a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java +++ b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java @@ -1,6 +1,7 @@ package com.nikp.payment.api; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -9,8 +10,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.beans.factory.annotation.Value; +import com.nikp.captcha.CaptchaService; import com.nikp.eventbus.api.EventBus; import com.nikp.eventbus.domain.Event; import com.nikp.payment.domain.Payment; @@ -22,18 +23,23 @@ import javax.annotation.PostConstruct; import javax.ws.rs.ForbiddenException; -import com.nikp.captcha.CaptchaService; + @Controller public class MVCController { @Autowired private PaymentRepository paymentRepository; + + @Autowired + private CaptchaService captchaService; @Value("${harness.build}" ) String buildNumber; @Value("${harness.se}" ) String seName; + @Value("${harness.clientFF}") + String clientffkey; @PostConstruct private void init() { @@ -43,36 +49,34 @@ private void init() { @Autowired private EventBus eventBus; - - @Autowired - private CaptchaService captchaService; - @RequestMapping("/") - public String indexView(@RequestParam(name = "number", required = false, defaultValue = "") + public String indexView(@RequestParam(name = "number", required = false, defaultValue = "") String number, @RequestParam(name = "sename", required = false, defaultValue = "") String sename, Model model) { - System.out.println("Notification: all payments listed"); + System.out.println("all payments executed"); model.addAttribute("list", paymentRepository.findAll()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); + model.addAttribute("clientffkey", clientffkey); return "allPayments"; } @PostMapping("/mvc/payment") - public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam(value="g-recaptcha-response") String response,@RequestParam(name = "number", required = false, defaultValue = "") + public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam(value="g-recaptcha-response") String response,@RequestParam(name = "number", required = false, defaultValue = "") String number, @RequestParam(name = "sename", required = false, defaultValue = "") String sename, Model model) { - + + if(paymentDto.getBankValidation().isEmpty()) { try { captchaService.processResponse(response); }catch(BankValidationException e) { - + model.addAttribute(paymentDto); model.addAttribute("response",response); - + return "bankError"; }catch(ReCaptchaInvalidException re) { @@ -83,10 +87,12 @@ public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam( } paymentRepository.save(new Payment(paymentDto.getUserId(), paymentDto.getAccountFrom(), paymentDto.getAccountTo(), paymentDto.getAmount())); eventBus.publish(new Event("SAVE", "Save payment" + paymentDto)); - System.out.println("Notification: added payment from user "+paymentDto.getUserId()); model.addAttribute("list", paymentRepository.findAll()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); + model.addAttribute("clientffkey", clientffkey); + + return "allPayments"; } @@ -94,39 +100,35 @@ public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam( public String paymentForm( @ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") String number, @RequestParam(name = "sename", required = false, defaultValue = "") String sename, Model model) { - System.out.println("Notification: creating payment using the main form"); - model.addAttribute("paymentDto", new PaymentDto()); - model.addAttribute("number",buildNumber ); - model.addAttribute("sename", seName); - - return "createOriginal"; - } - @GetMapping("/mvc/makePayment") - public String paymentFormNew( @ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") - String number, @RequestParam(name = "sename", required = false, defaultValue = "") - String sename, Model model) { - System.out.println("Notification: creating payment using the main form"); model.addAttribute("paymentDto", new PaymentDto()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); + model.addAttribute("clientffkey", clientffkey); + + return "create"; + - return "createOriginal"; } - - + @PostMapping("/mvc/payment/bank") public String paymentSubmitBank(@ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "") String number, @RequestParam(name = "sename", required = false, defaultValue = "") String sename, Model model) { + + paymentRepository.save(new Payment(paymentDto.getUserId(), paymentDto.getAccountFrom(), paymentDto.getAccountTo(), paymentDto.getAmount())); eventBus.publish(new Event("SAVE", "Save payment" + paymentDto)); model.addAttribute("list", paymentRepository.findAll()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); + model.addAttribute("clientffkey", clientffkey); + + return "allPayments"; - + } + } From 8b4c96cb0b139cf2481950243903c8b6076ea6dd Mon Sep 17 00:00:00 2001 From: nikpapag <82569427+nikpapag@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:38:30 +0100 Subject: [PATCH 7/7] Update MVCController.java --- .../main/java/com/nikp/payment/api/MVCController.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java index a6f79763..0c165843 100644 --- a/payment-service/src/main/java/com/nikp/payment/api/MVCController.java +++ b/payment-service/src/main/java/com/nikp/payment/api/MVCController.java @@ -38,8 +38,6 @@ public class MVCController { String buildNumber; @Value("${harness.se}" ) String seName; - @Value("${harness.clientFF}") - String clientffkey; @PostConstruct private void init() { @@ -57,7 +55,6 @@ public String indexView(@RequestParam(name = "number", required = false, default model.addAttribute("list", paymentRepository.findAll()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); - model.addAttribute("clientffkey", clientffkey); return "allPayments"; } @@ -90,7 +87,7 @@ public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam( model.addAttribute("list", paymentRepository.findAll()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); - model.addAttribute("clientffkey", clientffkey); + return "allPayments"; @@ -104,7 +101,7 @@ public String paymentForm( @ModelAttribute PaymentDto paymentDto,@RequestParam(n model.addAttribute("paymentDto", new PaymentDto()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); - model.addAttribute("clientffkey", clientffkey); +; return "create"; @@ -123,7 +120,7 @@ public String paymentSubmitBank(@ModelAttribute PaymentDto paymentDto,@RequestPa model.addAttribute("list", paymentRepository.findAll()); model.addAttribute("number",buildNumber ); model.addAttribute("sename", seName); - model.addAttribute("clientffkey", clientffkey); + return "allPayments";