@Test void testUpdateAccountNoOldPassword() { AccountUpdateRequest accountUpdateRequest = new AccountUpdateRequest(); accountUpdateRequest.setNewpwd("abc"); Exception exception = assertThrows( MolgenisUserException.class, () -> userAccountController.updateAccount(accountUpdateRequest)); assertThat(exception.getMessage()) .containsPattern("Please enter old password to update your password."); }
@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) public void updateAccount(@Valid @NotNull AccountUpdateRequest updateRequest) { String newPassword = validatePasswordInUpdateRequest(updateRequest); User user = userAccountService.getCurrentUser(); if (isNotEmpty(newPassword)) user.setPassword(newPassword); if (isNotEmpty(updateRequest.getPhone())) user.setPhone(updateRequest.getPhone()); if (isNotEmpty(updateRequest.getFax())) user.setFax(updateRequest.getFax()); if (isNotEmpty(updateRequest.getTollFreePhone())) { user.setTollFreePhone(updateRequest.getTollFreePhone()); } if (isNotEmpty(updateRequest.getAddress())) user.setAddress(updateRequest.getAddress()); if (isNotEmpty(updateRequest.getTitle())) user.setTitle(updateRequest.getTitle()); if (isNotEmpty(updateRequest.getFirstname())) user.setFirstName(updateRequest.getFirstname()); if (isNotEmpty(updateRequest.getMiddleNames())) user.setMiddleNames(updateRequest.getMiddleNames()); if (isNotEmpty(updateRequest.getLastname())) user.setLastName(updateRequest.getLastname()); if (isNotEmpty(updateRequest.getInstitute())) user.setAffiliation(updateRequest.getInstitute()); if (isNotEmpty(updateRequest.getDepartment())) user.setDepartment(updateRequest.getDepartment()); if (isNotEmpty(updateRequest.getPosition())) user.setRole(updateRequest.getPosition()); if (isNotEmpty(updateRequest.getCity())) user.setCity(updateRequest.getCity()); if (isNotEmpty(updateRequest.getCountry())) { user.setCountry(CountryCodes.get(updateRequest.getCountry())); } userAccountService.updateCurrentUser(user); }
UserAccountController extends PluginController { @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) public void updateAccount(@Valid @NotNull AccountUpdateRequest updateRequest) { String newPassword = validatePasswordInUpdateRequest(updateRequest); User user = userAccountService.getCurrentUser(); if (isNotEmpty(newPassword)) user.setPassword(newPassword); if (isNotEmpty(updateRequest.getPhone())) user.setPhone(updateRequest.getPhone()); if (isNotEmpty(updateRequest.getFax())) user.setFax(updateRequest.getFax()); if (isNotEmpty(updateRequest.getTollFreePhone())) { user.setTollFreePhone(updateRequest.getTollFreePhone()); } if (isNotEmpty(updateRequest.getAddress())) user.setAddress(updateRequest.getAddress()); if (isNotEmpty(updateRequest.getTitle())) user.setTitle(updateRequest.getTitle()); if (isNotEmpty(updateRequest.getFirstname())) user.setFirstName(updateRequest.getFirstname()); if (isNotEmpty(updateRequest.getMiddleNames())) user.setMiddleNames(updateRequest.getMiddleNames()); if (isNotEmpty(updateRequest.getLastname())) user.setLastName(updateRequest.getLastname()); if (isNotEmpty(updateRequest.getInstitute())) user.setAffiliation(updateRequest.getInstitute()); if (isNotEmpty(updateRequest.getDepartment())) user.setDepartment(updateRequest.getDepartment()); if (isNotEmpty(updateRequest.getPosition())) user.setRole(updateRequest.getPosition()); if (isNotEmpty(updateRequest.getCity())) user.setCity(updateRequest.getCity()); if (isNotEmpty(updateRequest.getCountry())) { user.setCountry(CountryCodes.get(updateRequest.getCountry())); } userAccountService.updateCurrentUser(user); } }
UserAccountController extends PluginController { @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) public void updateAccount(@Valid @NotNull AccountUpdateRequest updateRequest) { String newPassword = validatePasswordInUpdateRequest(updateRequest); User user = userAccountService.getCurrentUser(); if (isNotEmpty(newPassword)) user.setPassword(newPassword); if (isNotEmpty(updateRequest.getPhone())) user.setPhone(updateRequest.getPhone()); if (isNotEmpty(updateRequest.getFax())) user.setFax(updateRequest.getFax()); if (isNotEmpty(updateRequest.getTollFreePhone())) { user.setTollFreePhone(updateRequest.getTollFreePhone()); } if (isNotEmpty(updateRequest.getAddress())) user.setAddress(updateRequest.getAddress()); if (isNotEmpty(updateRequest.getTitle())) user.setTitle(updateRequest.getTitle()); if (isNotEmpty(updateRequest.getFirstname())) user.setFirstName(updateRequest.getFirstname()); if (isNotEmpty(updateRequest.getMiddleNames())) user.setMiddleNames(updateRequest.getMiddleNames()); if (isNotEmpty(updateRequest.getLastname())) user.setLastName(updateRequest.getLastname()); if (isNotEmpty(updateRequest.getInstitute())) user.setAffiliation(updateRequest.getInstitute()); if (isNotEmpty(updateRequest.getDepartment())) user.setDepartment(updateRequest.getDepartment()); if (isNotEmpty(updateRequest.getPosition())) user.setRole(updateRequest.getPosition()); if (isNotEmpty(updateRequest.getCity())) user.setCity(updateRequest.getCity()); if (isNotEmpty(updateRequest.getCountry())) { user.setCountry(CountryCodes.get(updateRequest.getCountry())); } userAccountService.updateCurrentUser(user); } UserAccountController(
      UserAccountService userAccountService,
      RecoveryService recoveryService,
      TwoFactorAuthenticationService twoFactorAuthenticationService,
      AuthenticationSettings authenticationSettings,
      LocaleResolver localeResolver); }
UserAccountController extends PluginController { @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) public void updateAccount(@Valid @NotNull AccountUpdateRequest updateRequest) { String newPassword = validatePasswordInUpdateRequest(updateRequest); User user = userAccountService.getCurrentUser(); if (isNotEmpty(newPassword)) user.setPassword(newPassword); if (isNotEmpty(updateRequest.getPhone())) user.setPhone(updateRequest.getPhone()); if (isNotEmpty(updateRequest.getFax())) user.setFax(updateRequest.getFax()); if (isNotEmpty(updateRequest.getTollFreePhone())) { user.setTollFreePhone(updateRequest.getTollFreePhone()); } if (isNotEmpty(updateRequest.getAddress())) user.setAddress(updateRequest.getAddress()); if (isNotEmpty(updateRequest.getTitle())) user.setTitle(updateRequest.getTitle()); if (isNotEmpty(updateRequest.getFirstname())) user.setFirstName(updateRequest.getFirstname()); if (isNotEmpty(updateRequest.getMiddleNames())) user.setMiddleNames(updateRequest.getMiddleNames()); if (isNotEmpty(updateRequest.getLastname())) user.setLastName(updateRequest.getLastname()); if (isNotEmpty(updateRequest.getInstitute())) user.setAffiliation(updateRequest.getInstitute()); if (isNotEmpty(updateRequest.getDepartment())) user.setDepartment(updateRequest.getDepartment()); if (isNotEmpty(updateRequest.getPosition())) user.setRole(updateRequest.getPosition()); if (isNotEmpty(updateRequest.getCity())) user.setCity(updateRequest.getCity()); if (isNotEmpty(updateRequest.getCountry())) { user.setCountry(CountryCodes.get(updateRequest.getCountry())); } userAccountService.updateCurrentUser(user); } 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("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) public void updateAccount(@Valid @NotNull AccountUpdateRequest updateRequest) { String newPassword = validatePasswordInUpdateRequest(updateRequest); User user = userAccountService.getCurrentUser(); if (isNotEmpty(newPassword)) user.setPassword(newPassword); if (isNotEmpty(updateRequest.getPhone())) user.setPhone(updateRequest.getPhone()); if (isNotEmpty(updateRequest.getFax())) user.setFax(updateRequest.getFax()); if (isNotEmpty(updateRequest.getTollFreePhone())) { user.setTollFreePhone(updateRequest.getTollFreePhone()); } if (isNotEmpty(updateRequest.getAddress())) user.setAddress(updateRequest.getAddress()); if (isNotEmpty(updateRequest.getTitle())) user.setTitle(updateRequest.getTitle()); if (isNotEmpty(updateRequest.getFirstname())) user.setFirstName(updateRequest.getFirstname()); if (isNotEmpty(updateRequest.getMiddleNames())) user.setMiddleNames(updateRequest.getMiddleNames()); if (isNotEmpty(updateRequest.getLastname())) user.setLastName(updateRequest.getLastname()); if (isNotEmpty(updateRequest.getInstitute())) user.setAffiliation(updateRequest.getInstitute()); if (isNotEmpty(updateRequest.getDepartment())) user.setDepartment(updateRequest.getDepartment()); if (isNotEmpty(updateRequest.getPosition())) user.setRole(updateRequest.getPosition()); if (isNotEmpty(updateRequest.getCity())) user.setCity(updateRequest.getCity()); if (isNotEmpty(updateRequest.getCountry())) { user.setCountry(CountryCodes.get(updateRequest.getCountry())); } userAccountService.updateCurrentUser(user); } 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; }