I want to mock authentication using spring aop. In our application we have authentication trough bank, backend redirects to bank, and then after user successfully authenticates via bank client we get a callback and user is authenticated in our system.
@Controller
@RequestMapping("/auth/bank")
public class BankAuth {
@GetMapping
public String getBankTemplate() {
// prepare data
return "redirect:/bank";
}
@PostMapping("/callback")
public String bankCallback(HttpServletRequest request, HttpServletResponse response,) {
// parse data from callback request
return "redirect:/index";
}
}
What i want to achieve is to intercept getBankTemplate method, add mock data to request and forward that request to bankCallback, so user would be successfully authenticated.
I can't use forwarding cause bankCallback request is POST.
Is there a way to achieve this without using httpClient in interceptor?
@Aspect
public class MockBankInterceptor {
@Pointcut("execution (* ...getBankTemplate(...))")
public void bankTemplate() {}
@Around("bankTemplate()")
public String authenticateUser(ProceedingJoinPoint pjp) {
pjp.proceed();
// populate request with data required to authenticate customer
return "forward:/auth/bank/callback";
}
}