@Test @WithMockUser(value = USERNAME, roles = ROLE_SU) void activationTest() { Model model = new ExtendedModelMap(); when(twoFactorAuthenticationService.generateSecretKey()).thenReturn("secret"); String viewTemplate = twoFactorAuthenticationController.activation(model); assertEquals("view-2fa-activation-modal", viewTemplate); }
@GetMapping(TWO_FACTOR_ACTIVATION_URI) public String activation(Model model) { try { String secretKey = twoFactorAuthenticationService.generateSecretKey(); model.addAttribute(ATTRIBUTE_2FA_SECRET_KEY, secretKey); model.addAttribute( ATTRIBUTE_2FA_AUTHENTICATOR_URI, otpService.getAuthenticatorURI(secretKey)); } catch (IllegalStateException err) { model.addAttribute( MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(err)); } return VIEW_2FA_ACTIVATION_MODAL; }
TwoFactorAuthenticationController { @GetMapping(TWO_FACTOR_ACTIVATION_URI) public String activation(Model model) { try { String secretKey = twoFactorAuthenticationService.generateSecretKey(); model.addAttribute(ATTRIBUTE_2FA_SECRET_KEY, secretKey); model.addAttribute( ATTRIBUTE_2FA_AUTHENTICATOR_URI, otpService.getAuthenticatorURI(secretKey)); } catch (IllegalStateException err) { model.addAttribute( MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(err)); } return VIEW_2FA_ACTIVATION_MODAL; } }
TwoFactorAuthenticationController { @GetMapping(TWO_FACTOR_ACTIVATION_URI) public String activation(Model model) { try { String secretKey = twoFactorAuthenticationService.generateSecretKey(); model.addAttribute(ATTRIBUTE_2FA_SECRET_KEY, secretKey); model.addAttribute( ATTRIBUTE_2FA_AUTHENTICATOR_URI, otpService.getAuthenticatorURI(secretKey)); } catch (IllegalStateException err) { model.addAttribute( MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(err)); } return VIEW_2FA_ACTIVATION_MODAL; } TwoFactorAuthenticationController(
      TwoFactorAuthenticationProvider authenticationProvider,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      RecoveryAuthenticationProvider recoveryAuthenticationProvider,
      OtpService otpService); }
TwoFactorAuthenticationController { @GetMapping(TWO_FACTOR_ACTIVATION_URI) public String activation(Model model) { try { String secretKey = twoFactorAuthenticationService.generateSecretKey(); model.addAttribute(ATTRIBUTE_2FA_SECRET_KEY, secretKey); model.addAttribute( ATTRIBUTE_2FA_AUTHENTICATOR_URI, otpService.getAuthenticatorURI(secretKey)); } catch (IllegalStateException err) { model.addAttribute( MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(err)); } return VIEW_2FA_ACTIVATION_MODAL; } 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 { @GetMapping(TWO_FACTOR_ACTIVATION_URI) public String activation(Model model) { try { String secretKey = twoFactorAuthenticationService.generateSecretKey(); model.addAttribute(ATTRIBUTE_2FA_SECRET_KEY, secretKey); model.addAttribute( ATTRIBUTE_2FA_AUTHENTICATOR_URI, otpService.getAuthenticatorURI(secretKey)); } catch (IllegalStateException err) { model.addAttribute( MolgenisLoginController.ERROR_MESSAGE_ATTRIBUTE, determineErrorMessage(err)); } return VIEW_2FA_ACTIVATION_MODAL; } 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; }