Enforce password size limit

This commit is contained in:
Paulo Gustavo Veiga
2023-07-02 10:13:42 -07:00
parent ae633022ab
commit 30098527b5
10 changed files with 97 additions and 41 deletions

View File

@@ -18,6 +18,7 @@
package com.wisemapping.rest;
import com.wisemapping.exceptions.PasswordTooLongException;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.Collaboration;
import com.wisemapping.model.Label;
@@ -55,11 +56,15 @@ public class AccountController extends BaseController {
@RequestMapping(method = RequestMethod.PUT, value = "account/password", consumes = {"text/plain"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void changePassword(@RequestBody String password) {
public void changePassword(@RequestBody String password) throws PasswordTooLongException {
if (password == null) {
throw new IllegalArgumentException("Password can not be null");
}
if (password.length() > User.MAX_PASSWORD_LENGTH_SIZE) {
throw new PasswordTooLongException();
}
final User user = Utils.getUser(true);
user.setPassword(password);
userService.changePassword(user);