mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15: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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (isFirstStart()) {
|
if (shouldCreateAdminAccount()) {
|
||||||
createAdminAccount();
|
createAdminAccount();
|
||||||
}
|
}
|
||||||
if (anonymousUserRequiredButNotExists()) {
|
if (anonymousUserRequiredButNotExists()) {
|
||||||
@@ -73,8 +73,12 @@ public class SetupContextListener implements ServletContextListener {
|
|||||||
return scmConfiguration.isAnonymousAccessEnabled() && !userManager.contains(SCMContext.USER_ANONYMOUS);
|
return scmConfiguration.isAnonymousAccessEnabled() && !userManager.contains(SCMContext.USER_ANONYMOUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFirstStart() {
|
private boolean shouldCreateAdminAccount() {
|
||||||
return userManager.getAll().isEmpty();
|
return userManager.getAll().isEmpty() || onlyAnonymousUserExists();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean onlyAnonymousUserExists() {
|
||||||
|
return userManager.getAll().size() == 1 && userManager.contains(SCMContext.USER_ANONYMOUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAdminAccount() {
|
private void createAdminAccount() {
|
||||||
|
|||||||
@@ -70,7 +70,19 @@ class SetupContextListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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");
|
when(passwordService.encryptPassword("scmadmin")).thenReturn("secret");
|
||||||
|
|
||||||
setupContextListener.contextInitialized(null);
|
setupContextListener.contextInitialized(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user