@Test void testGenerateRecoveryCodes() { RecoveryCode code1 = mock(RecoveryCode.class); when(code1.getCode()).thenReturn("code1"); RecoveryCode code2 = mock(RecoveryCode.class); when(code2.getCode()).thenReturn("code2"); when(recoveryService.generateRecoveryCodes()).thenReturn(Stream.of(code1, code2)); assertEquals( of("recoveryCodes", ImmutableList.of("code1", "code2")), userAccountController.generateRecoveryCodes()); }
@ApiOperation("Generate recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse( code = 200, message = "Returns a list of generated recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong generating the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("generateRecoveryCodes") @ResponseBody public Map<String, List<String>> generateRecoveryCodes() { Stream<RecoveryCode> recoveryCodes = recoveryService.generateRecoveryCodes(); return convertToRecoveryCodesMap(recoveryCodes.map(RecoveryCode::getCode).collect(toList())); }
UserAccountController extends PluginController { @ApiOperation("Generate recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse( code = 200, message = "Returns a list of generated recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong generating the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("generateRecoveryCodes") @ResponseBody public Map<String, List<String>> generateRecoveryCodes() { Stream<RecoveryCode> recoveryCodes = recoveryService.generateRecoveryCodes(); return convertToRecoveryCodesMap(recoveryCodes.map(RecoveryCode::getCode).collect(toList())); } }
UserAccountController extends PluginController { @ApiOperation("Generate recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse( code = 200, message = "Returns a list of generated recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong generating the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("generateRecoveryCodes") @ResponseBody public Map<String, List<String>> generateRecoveryCodes() { Stream<RecoveryCode> recoveryCodes = recoveryService.generateRecoveryCodes(); return convertToRecoveryCodesMap(recoveryCodes.map(RecoveryCode::getCode).collect(toList())); } UserAccountController(
      UserAccountService userAccountService,
      RecoveryService recoveryService,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      AuthenticationSettings authenticationSettings,
      LocaleResolver localeResolver); }
UserAccountController extends PluginController { @ApiOperation("Generate recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse( code = 200, message = "Returns a list of generated recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong generating the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("generateRecoveryCodes") @ResponseBody public Map<String, List<String>> generateRecoveryCodes() { Stream<RecoveryCode> recoveryCodes = recoveryService.generateRecoveryCodes(); return convertToRecoveryCodesMap(recoveryCodes.map(RecoveryCode::getCode).collect(toList())); } UserAccountController(
      UserAccountService userAccountService,
      RecoveryService recoveryService,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      AuthenticationSettings authenticationSettings,
      LocaleResolver localeResolver); @ApiOperation("Show account") @ApiResponses({ @ApiResponse(code = 200, message = "Return the view of the account", response = String.class) }) @GetMapping String showAccount(
      Model model, @RequestParam(value = "showCodes", defaultValue = "false") boolean showCodes); @ApiOperation("Updates the selected user language") @ApiResponses({ @ApiResponse(code = 204, message = "Update succeeded"), @ApiResponse( code = 403, message = "Access denied. You need write permission on the UserAccount plugin", response = ErrorMessageResponse.class), @ApiResponse( code = 400, message = "Bad request. You need to provide a valid language code", response = ErrorMessageResponse.class) }) @PostMapping(value = "/language/update", produces = APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.NO_CONTENT) void updateUserLanguage(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("languageCode") String languageCode); @ApiOperation("Updated the useraccount") @ApiResponses({ @ApiResponse(code = 200, message = "Account is updated"), @ApiResponse( code = 400, message = "Invalid password entered", response = ErrorMessageResponse.class) }) @PostMapping(value = "/update", headers = "Content-Type=application/x-www-form-urlencoded") @ResponseStatus(HttpStatus.NO_CONTENT) void updateAccount(@Valid @NotNull AccountUpdateRequest updateRequest); @ApiOperation("Enable two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Two factor authentication enabled"), @ApiResponse(code = 400, message = "Could not enable two factor authentication for user") }) @PostMapping(TWO_FACTOR_AUTHENTICATION + "/enable") String enableTwoFactorAuthentication(); @ApiOperation("Disable two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Two factor authentication disabled"), @ApiResponse( code = 400, message = "Could not disable two factor authentication for user", response = ErrorMessageResponse.class) }) @PostMapping(TWO_FACTOR_AUTHENTICATION + "/disable") String disableTwoFactorAuthentication(Model model); @ApiOperation("Reset two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Two factor authentication is reset"), @ApiResponse( code = 400, message = "Could not rest two factor authentication for user", response = ErrorMessageResponse.class) }) @PostMapping(TWO_FACTOR_AUTHENTICATION + "/reset") String resetTwoFactorAuthentication(); @ApiOperation("Get recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Returns a list of recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong retrieving the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("recoveryCodes") @ResponseBody Map<String, List<String>> getRecoveryCodes(); @ApiOperation("Generate recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse( code = 200, message = "Returns a list of generated recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong generating the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("generateRecoveryCodes") @ResponseBody Map<String, List<String>> generateRecoveryCodes(); }
UserAccountController extends PluginController { @ApiOperation("Generate recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse( code = 200, message = "Returns a list of generated recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong generating the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("generateRecoveryCodes") @ResponseBody public Map<String, List<String>> generateRecoveryCodes() { Stream<RecoveryCode> recoveryCodes = recoveryService.generateRecoveryCodes(); return convertToRecoveryCodesMap(recoveryCodes.map(RecoveryCode::getCode).collect(toList())); } UserAccountController(
      UserAccountService userAccountService,
      RecoveryService recoveryService,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      AuthenticationSettings authenticationSettings,
      LocaleResolver localeResolver); @ApiOperation("Show account") @ApiResponses({ @ApiResponse(code = 200, message = "Return the view of the account", response = String.class) }) @GetMapping String showAccount(
      Model model, @RequestParam(value = "showCodes", defaultValue = "false") boolean showCodes); @ApiOperation("Updates the selected user language") @ApiResponses({ @ApiResponse(code = 204, message = "Update succeeded"), @ApiResponse( code = 403, message = "Access denied. You need write permission on the UserAccount plugin", response = ErrorMessageResponse.class), @ApiResponse( code = 400, message = "Bad request. You need to provide a valid language code", response = ErrorMessageResponse.class) }) @PostMapping(value = "/language/update", produces = APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.NO_CONTENT) void updateUserLanguage(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("languageCode") String languageCode); @ApiOperation("Updated the useraccount") @ApiResponses({ @ApiResponse(code = 200, message = "Account is updated"), @ApiResponse( code = 400, message = "Invalid password entered", response = ErrorMessageResponse.class) }) @PostMapping(value = "/update", headers = "Content-Type=application/x-www-form-urlencoded") @ResponseStatus(HttpStatus.NO_CONTENT) void updateAccount(@Valid @NotNull AccountUpdateRequest updateRequest); @ApiOperation("Enable two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Two factor authentication enabled"), @ApiResponse(code = 400, message = "Could not enable two factor authentication for user") }) @PostMapping(TWO_FACTOR_AUTHENTICATION + "/enable") String enableTwoFactorAuthentication(); @ApiOperation("Disable two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Two factor authentication disabled"), @ApiResponse( code = 400, message = "Could not disable two factor authentication for user", response = ErrorMessageResponse.class) }) @PostMapping(TWO_FACTOR_AUTHENTICATION + "/disable") String disableTwoFactorAuthentication(Model model); @ApiOperation("Reset two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Two factor authentication is reset"), @ApiResponse( code = 400, message = "Could not rest two factor authentication for user", response = ErrorMessageResponse.class) }) @PostMapping(TWO_FACTOR_AUTHENTICATION + "/reset") String resetTwoFactorAuthentication(); @ApiOperation("Get recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse(code = 200, message = "Returns a list of recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong retrieving the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("recoveryCodes") @ResponseBody Map<String, List<String>> getRecoveryCodes(); @ApiOperation("Generate recoverycodes for two factor authentication") @ApiResponses({ @ApiResponse( code = 200, message = "Returns a list of generated recoverycodes", response = Map.class), @ApiResponse( code = 500, message = "Something went wrong generating the recoverycodes", response = ErrorMessageResponse.class) }) @GetMapping("generateRecoveryCodes") @ResponseBody Map<String, List<String>> generateRecoveryCodes(); static final String ID; static final String URI; static final String TWO_FACTOR_AUTHENTICATION; }