diff --git a/src/main/java/stirling/software/SPDF/config/security/UserService.java b/src/main/java/stirling/software/SPDF/config/security/UserService.java index 155ed76b0..f3627d499 100644 --- a/src/main/java/stirling/software/SPDF/config/security/UserService.java +++ b/src/main/java/stirling/software/SPDF/config/security/UserService.java @@ -205,6 +205,7 @@ public class UserService implements UserServiceInterface { user.setPassword(passwordEncoder.encode(password)); user.setEnabled(true); user.setAuthenticationType(AuthenticationType.WEB); + user.addAuthority(new Authority(Role.USER.getRoleId(), user)); userRepository.save(user); databaseService.exportDatabase(); } @@ -230,6 +231,22 @@ public class UserService implements UserServiceInterface { saveUser(username, password, role, false); } + public void saveUser(String username, String password, boolean firstLogin, boolean enabled) + throws IllegalArgumentException, SQLException, UnsupportedProviderException { + if (!isUsernameValid(username)) { + throw new IllegalArgumentException(getInvalidUsernameMessage()); + } + User user = new User(); + user.setUsername(username); + user.setPassword(passwordEncoder.encode(password)); + user.addAuthority(new Authority(Role.USER.getRoleId(), user)); + user.setEnabled(enabled); + user.setAuthenticationType(AuthenticationType.WEB); + user.setFirstLogin(firstLogin); + userRepository.save(user); + databaseService.exportDatabase(); + } + public void deleteUser(String username) { Optional userOpt = findByUsernameIgnoreCase(username); if (userOpt.isPresent()) { @@ -352,6 +369,7 @@ public class UserService implements UserServiceInterface { List notAllowedUserList = new ArrayList<>(); notAllowedUserList.add("ALL_USERS".toLowerCase()); + notAllowedUserList.add("anonymoususer"); boolean notAllowedUser = notAllowedUserList.contains(username.toLowerCase()); return (isValidSimpleUsername || isValidEmail) && !notAllowedUser; }