diff --git a/src/main/java/stirling/software/SPDF/config/security/InitialSecuritySetup.java b/src/main/java/stirling/software/SPDF/config/security/InitialSecuritySetup.java index 9ec02e17..452de53e 100644 --- a/src/main/java/stirling/software/SPDF/config/security/InitialSecuritySetup.java +++ b/src/main/java/stirling/software/SPDF/config/security/InitialSecuritySetup.java @@ -54,10 +54,8 @@ public class InitialSecuritySetup { && !initialPassword.isEmpty() && !userService.findByUsernameIgnoreCase(initialUsername).isPresent()) { try { - if (userService.isUsernameValid(initialUsername)) { - userService.saveUser(initialUsername, initialPassword, Role.ADMIN.getRoleId()); - logger.info("Admin user created: " + initialUsername); - } + userService.saveUser(initialUsername, initialPassword, Role.ADMIN.getRoleId()); + logger.info("Admin user created: " + initialUsername); } catch (IllegalArgumentException e) { logger.error("Failed to initialize security setup", e); System.exit(1); 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 1fcf63f8..0a6898f8 100644 --- a/src/main/java/stirling/software/SPDF/config/security/UserService.java +++ b/src/main/java/stirling/software/SPDF/config/security/UserService.java @@ -197,7 +197,13 @@ public class UserService implements UserServiceInterface { } public boolean hasUsers() { - return userRepository.count() > 0; + long userCount = userRepository.count(); + if (userRepository + .findByUsernameIgnoreCase(Role.INTERNAL_API_USER.getRoleId()) + .isPresent()) { + userCount -= 1; + } + return userCount > 0; } public void updateUserSettings(String username, Map updates) {