@Test @WithMockUser(value = USERNAME, roles = ROLE_SU) void testRecoverAccount() { String recoveryCodeId = "123456"; Model model = new ExtendedModelMap(); String viewTemplate = twoFactorAuthenticationController.recoverAccount(model, recoveryCodeId); assertEquals("redirect:/", viewTemplate); }
@PostMapping(TWO_FACTOR_RECOVER_URI) public String recoverAccount(Model model, @RequestParam String recoveryCode) { String redirectUrl = "redirect:/"; try { RecoveryAuthenticationToken authToken = new RecoveryAuthenticationToken(recoveryCode); Authentication authentication = recoveryAuthenticationProvider.authenticate(authToken); SecurityContextHolder.getContext().setAuthentication(authentication); } catch (AuthenticationException e) { model.addAttribute(ATTRIBUTE_2FA_RECOVER_MODE, true); model.addAttribute(MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(e)); redirectUrl = VIEW_2FA_CONFIGURED_MODAL; } return redirectUrl; }
TwoFactorAuthenticationController { @PostMapping(TWO_FACTOR_RECOVER_URI) public String recoverAccount(Model model, @RequestParam String recoveryCode) { String redirectUrl = "redirect:/"; try { RecoveryAuthenticationToken authToken = new RecoveryAuthenticationToken(recoveryCode); Authentication authentication = recoveryAuthenticationProvider.authenticate(authToken); SecurityContextHolder.getContext().setAuthentication(authentication); } catch (AuthenticationException e) { model.addAttribute(ATTRIBUTE_2FA_RECOVER_MODE, true); model.addAttribute(MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(e)); redirectUrl = VIEW_2FA_CONFIGURED_MODAL; } return redirectUrl; } }
TwoFactorAuthenticationController { @PostMapping(TWO_FACTOR_RECOVER_URI) public String recoverAccount(Model model, @RequestParam String recoveryCode) { String redirectUrl = "redirect:/"; try { RecoveryAuthenticationToken authToken = new RecoveryAuthenticationToken(recoveryCode); Authentication authentication = recoveryAuthenticationProvider.authenticate(authToken); SecurityContextHolder.getContext().setAuthentication(authentication); } catch (AuthenticationException e) { model.addAttribute(ATTRIBUTE_2FA_RECOVER_MODE, true); model.addAttribute(MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(e)); redirectUrl = VIEW_2FA_CONFIGURED_MODAL; } return redirectUrl; } TwoFactorAuthenticationController(
      TwoFactorAuthenticationProvider authenticationProvider,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      RecoveryAuthenticationProvider recoveryAuthenticationProvider,
      OtpService otpService); }
TwoFactorAuthenticationController { @PostMapping(TWO_FACTOR_RECOVER_URI) public String recoverAccount(Model model, @RequestParam String recoveryCode) { String redirectUrl = "redirect:/"; try { RecoveryAuthenticationToken authToken = new RecoveryAuthenticationToken(recoveryCode); Authentication authentication = recoveryAuthenticationProvider.authenticate(authToken); SecurityContextHolder.getContext().setAuthentication(authentication); } catch (AuthenticationException e) { model.addAttribute(ATTRIBUTE_2FA_RECOVER_MODE, true); model.addAttribute(MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(e)); redirectUrl = VIEW_2FA_CONFIGURED_MODAL; } return redirectUrl; } TwoFactorAuthenticationController(
      TwoFactorAuthenticationProvider authenticationProvider,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      RecoveryAuthenticationProvider recoveryAuthenticationProvider,
      OtpService otpService); @GetMapping(TWO_FACTOR_CONFIGURED_URI) String configured(); @PostMapping(TWO_FACTOR_VALIDATION_URI) String validate(Model model, @RequestParam String verificationCode); @GetMapping(TWO_FACTOR_ACTIVATION_URI) String activation(Model model); @PostMapping(TWO_FACTOR_ACTIVATION_AUTHENTICATE_URI) String authenticate(
      Model model, @RequestParam String verificationCode, @RequestParam String secretKey); @PostMapping(TWO_FACTOR_RECOVER_URI) String recoverAccount(Model model, @RequestParam String recoveryCode); }
TwoFactorAuthenticationController { @PostMapping(TWO_FACTOR_RECOVER_URI) public String recoverAccount(Model model, @RequestParam String recoveryCode) { String redirectUrl = "redirect:/"; try { RecoveryAuthenticationToken authToken = new RecoveryAuthenticationToken(recoveryCode); Authentication authentication = recoveryAuthenticationProvider.authenticate(authToken); SecurityContextHolder.getContext().setAuthentication(authentication); } catch (AuthenticationException e) { model.addAttribute(ATTRIBUTE_2FA_RECOVER_MODE, true); model.addAttribute(MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(e)); redirectUrl = VIEW_2FA_CONFIGURED_MODAL; } return redirectUrl; } TwoFactorAuthenticationController(
      TwoFactorAuthenticationProvider authenticationProvider,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      RecoveryAuthenticationProvider recoveryAuthenticationProvider,
      OtpService otpService); @GetMapping(TWO_FACTOR_CONFIGURED_URI) String configured(); @PostMapping(TWO_FACTOR_VALIDATION_URI) String validate(Model model, @RequestParam String verificationCode); @GetMapping(TWO_FACTOR_ACTIVATION_URI) String activation(Model model); @PostMapping(TWO_FACTOR_ACTIVATION_AUTHENTICATE_URI) String authenticate(
      Model model, @RequestParam String verificationCode, @RequestParam String secretKey); @PostMapping(TWO_FACTOR_RECOVER_URI) String recoverAccount(Model model, @RequestParam String recoveryCode); static final String URI; static final String TWO_FACTOR_ACTIVATION_URI; static final String ATTRIBUTE_2FA_SECRET_KEY; static final String TWO_FACTOR_CONFIGURED_URI; }