mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
create scmadmin also if only _anonymous user exists
This commit is contained in:
@@ -61,7 +61,7 @@ public class SetupContextListener implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (isFirstStart()) {
|
||||
if (shouldCreateAdminAccount()) {
|
||||
createAdminAccount();
|
||||
}
|
||||
if (anonymousUserRequiredButNotExists()) {
|
||||
@@ -73,8 +73,12 @@ public class SetupContextListener implements ServletContextListener {
|
||||
return scmConfiguration.isAnonymousAccessEnabled() && !userManager.contains(SCMContext.USER_ANONYMOUS);
|
||||
}
|
||||
|
||||
private boolean isFirstStart() {
|
||||
return userManager.getAll().isEmpty();
|
||||
private boolean shouldCreateAdminAccount() {
|
||||
return userManager.getAll().isEmpty() || onlyAnonymousUserExists();
|
||||
}
|
||||
|
||||
private boolean onlyAnonymousUserExists() {
|
||||
return userManager.getAll().size() == 1 && userManager.contains(SCMContext.USER_ANONYMOUS);
|
||||
}
|
||||
|
||||
private void createAdminAccount() {
|
||||
|
||||
@@ -70,7 +70,19 @@ class SetupContextListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateAdminAccountAndAssignPermissions() {
|
||||
void shouldCreateAdminAccountIfNoUserExistsAndAssignPermissions() {
|
||||
when(passwordService.encryptPassword("scmadmin")).thenReturn("secret");
|
||||
|
||||
setupContextListener.contextInitialized(null);
|
||||
|
||||
verifyAdminCreated();
|
||||
verifyAdminPermissionsAssigned();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateAdminAccountIfOnlyAnonymousUserExistsAndAssignPermissions() {
|
||||
when(userManager.getAll()).thenReturn(Lists.newArrayList(SCMContext.ANONYMOUS));
|
||||
when(userManager.contains(SCMContext.USER_ANONYMOUS)).thenReturn(true);
|
||||
when(passwordService.encryptPassword("scmadmin")).thenReturn("secret");
|
||||
|
||||
setupContextListener.contextInitialized(null);
|
||||
|
||||
Reference in New Issue
Block a user