]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8208 Remove property "sonar.authenticator.createUser"
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 3 Feb 2017 08:52:54 +0000 (09:52 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 6 Feb 2017 15:07:41 +0000 (16:07 +0100)
it/it-tests/src/test/java/it/user/RealmAuthenticationTest.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-server/src/main/java/org/sonar/server/authentication/RealmAuthenticator.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java
server/sonar-server/src/test/java/org/sonar/server/authentication/RealmAuthenticatorTest.java
sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index bbf78cb077eecbd0700ff53db2c018919873c6fb..defd825a670af8a7e74096e1faa363e9a20aed2f 100644 (file)
@@ -24,7 +24,6 @@ import com.google.common.collect.Maps;
 import com.sonar.orchestrator.Orchestrator;
 import java.util.Map;
 import javax.annotation.CheckForNull;
-import org.apache.commons.lang.RandomStringUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -85,7 +84,6 @@ public class RealmAuthenticationTest {
   public void resetData() throws Exception {
     setServerProperty(orchestrator, USERS_PROPERTY, null);
     setServerProperty(orchestrator, "sonar.security.updateUserAttributes", null);
-    setServerProperty(orchestrator, "sonar.authenticator.createUsers", null);
     USER_RULE.resetUsers();
   }
 
@@ -215,30 +213,6 @@ public class RealmAuthenticationTest {
     verifyAuthenticationIsNotOk(username, "wrong");
   }
 
-  /**
-   * SONAR-1334 (createUsers=false)
-   */
-  @Test
-  public void shouldNotCreateNewUsers() {
-    // Given clean Sonar installation and no users in external system
-    setServerProperty(orchestrator, "sonar.authenticator.createUsers", "false");
-    // Use a random user name because if we use existing disabled user then it doesn't work because rails doesn't handle this case
-    // (it's using User.find_by_login to know if user exists or not
-    String username = RandomStringUtils.randomAlphanumeric(20);
-    String password = "1234567";
-    Map<String, String> users = Maps.newHashMap();
-
-    // When user not exists in external system
-    // Then
-    verifyAuthenticationIsNotOk(username, password);
-
-    // When user created in external system
-    users.put(username + ".password", password);
-    updateUsersInExtAuth(users);
-    // Then
-    verifyAuthenticationIsNotOk(username, password);
-  }
-
   // SONAR-3258
   @Test
   public void shouldAutomaticallyReactivateDeletedUser() throws Exception {
index b2329a2c1b8c6191757df2236eacedf58386e1df..391e632c06336f6ec5e71d5857ee728c824f55c5 100644 (file)
@@ -109,7 +109,7 @@ public class ComputeEngineContainerImplTest {
         + 25 // level 1
         + 47 // content of DaoModule
         + 3 // content of EsSearchModule
-        + 61 // content of CorePropertyDefinitions
+        + 60 // content of CorePropertyDefinitions
         + 1 // content of CePropertyDefinitions
     );
     assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
index e8b7b0cd9ddbfbc412f2081f48c76d6cded22c8f..26dd2d1a09c0848c79b97cee35500ff41dcce1a3 100644 (file)
@@ -45,7 +45,6 @@ import org.sonar.server.user.SecurityRealmFactory;
 import static java.util.Objects.requireNonNull;
 import static org.apache.commons.lang.StringUtils.isEmpty;
 import static org.apache.commons.lang.StringUtils.trimToNull;
-import static org.sonar.api.CoreProperties.CORE_AUTHENTICATOR_CREATE_USERS;
 import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
 import static org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY;
 
@@ -150,7 +149,7 @@ public class RealmAuthenticator implements Startable {
     return userLogin;
   }
 
-  private class ExternalIdentityProvider implements IdentityProvider {
+  private static class ExternalIdentityProvider implements IdentityProvider {
     @Override
     public String getKey() {
       return SQ_AUTHORITY;
@@ -173,7 +172,7 @@ public class RealmAuthenticator implements Startable {
 
     @Override
     public boolean allowsUsersToSignUp() {
-      return settings.getBoolean(CORE_AUTHENTICATOR_CREATE_USERS);
+      return true;
     }
   }
 
index a9c2bf37104188482257d7c97641a54002b4fb9b..b7f56c837603f184c052d85c5efb9d0ff7ba8b39 100644 (file)
@@ -102,10 +102,6 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
       .collect(Collectors.toList());
   }
 
-  private boolean getAutomaticUserCreation() {
-    return settings.getBoolean(CoreProperties.CORE_AUTHENTICATOR_CREATE_USERS);
-  }
-
   private boolean getForceAuthentication() {
     return settings.getBoolean(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY);
   }
@@ -131,7 +127,6 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
     addIfNotNull("External User Authentication", getExternalUserAuthentication(), attributes);
     addIfNotEmpty("Accepted external identity providers", getEnabledIdentityProviders(), attributes);
     addIfNotEmpty("External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders(), attributes);
-    attributes.put("Automatic User Creation", getAutomaticUserCreation());
     attributes.put("Force authentication", getForceAuthentication());
     attributes.put("Official Distribution", isOfficialDistribution());
     attributes.put("Home Dir", settings.getString(ProcessProperties.PATH_HOME));
index 23d54777ac16bd957df45a0ff62d42df17ad9bf3..b2e42f842175360522c450829499904b4a72a36b 100644 (file)
@@ -180,30 +180,6 @@ public class RealmAuthenticatorTest {
     verify(authenticationEvent).loginSuccess(request, LOGIN, Source.realm(BASIC, REALM_NAME));
   }
 
-  @Test
-  public void allow_to_sign_up_property() throws Exception {
-    settings.setProperty("sonar.authenticator.createUsers", true);
-    when(userIdentityAuthenticator.authenticate(any(UserIdentity.class), any(IdentityProvider.class), any(Source.class))).thenReturn(USER);
-    executeStartWithoutGroupSync();
-    executeAuthenticate();
-
-    verify(userIdentityAuthenticator).authenticate(userIdentityArgumentCaptor.capture(), identityProviderArgumentCaptor.capture(), sourceCaptor.capture());
-    assertThat(identityProviderArgumentCaptor.getValue().allowsUsersToSignUp()).isTrue();
-    verify(authenticationEvent).loginSuccess(request, LOGIN, Source.realm(BASIC, REALM_NAME));
-  }
-
-  @Test
-  public void does_not_allow_to_sign_up_property() throws Exception {
-    settings.setProperty("sonar.authenticator.createUsers", false);
-    when(userIdentityAuthenticator.authenticate(any(UserIdentity.class), any(IdentityProvider.class), any(Source.class))).thenReturn(USER);
-    executeStartWithoutGroupSync();
-    executeAuthenticate();
-
-    verify(userIdentityAuthenticator).authenticate(userIdentityArgumentCaptor.capture(), identityProviderArgumentCaptor.capture(), sourceCaptor.capture());
-    assertThat(identityProviderArgumentCaptor.getValue().allowsUsersToSignUp()).isFalse();
-    verify(authenticationEvent).loginSuccess(request, LOGIN, Source.realm(BASIC, REALM_NAME));
-  }
-
   @Test
   public void use_downcase_login() throws Exception {
     settings.setProperty("sonar.authenticator.downcase", true);
index 12bbe0a1185447f7c9c9f1ef1f4f3c3466eafc92..ffac9913d82d20a0256c9dadcf0ecd89dd50a77c 100644 (file)
@@ -135,13 +135,6 @@ public class CorePropertyDefinitions {
         .defaultValue(String.valueOf(false))
         .hidden()
         .build(),
-      PropertyDefinition.builder(CoreProperties.CORE_AUTHENTICATOR_CREATE_USERS)
-        .name("Create user accounts")
-        .description("Create accounts when authenticating users via an external system")
-        .type(PropertyType.BOOLEAN)
-        .defaultValue(String.valueOf(true))
-        .hidden()
-        .build(),
       PropertyDefinition.builder(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE)
         .name("Ignore failures during authenticator startup")
         .type(PropertyType.BOOLEAN)
index b1198a6ef83c888220a0e2801114ebf9e64812a2..01f3d1bf9d222a156b2fc82a436e0d846e558f2b 100644 (file)
  */
 package org.sonar.core.config;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
 import java.util.List;
-import javax.annotation.Nonnull;
+import java.util.Optional;
 import org.junit.Test;
 import org.sonar.api.PropertyType;
 import org.sonar.api.config.PropertyDefinition;
-import org.sonar.api.database.DatabaseProperties;
 
-import static com.google.common.collect.FluentIterable.from;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.database.DatabaseProperties.PROP_PASSWORD;
 
 public class CorePropertyDefinitionsTest {
+
   @Test
   public void all() {
     List<PropertyDefinition> defs = CorePropertyDefinitions.all();
-    assertThat(defs).hasSize(63);
+    assertThat(defs).hasSize(62);
   }
 
   @Test
   public void jdbc_password_property_has_password_type() {
     List<PropertyDefinition> defs = CorePropertyDefinitions.all();
-    Optional<PropertyDefinition> prop = from(defs).filter(new HasKeyPredicate(DatabaseProperties.PROP_PASSWORD)).first();
+
+    Optional<PropertyDefinition> prop = defs.stream().filter(def -> PROP_PASSWORD.equals(def.key())).findFirst();
     assertThat(prop.get().type()).isEqualTo(PropertyType.PASSWORD);
   }
 
-  private final class HasKeyPredicate implements Predicate<PropertyDefinition> {
-    private final String key;
-
-    HasKeyPredicate(String key) {
-      this.key = key;
-    }
-
-    @Override
-    public boolean apply(@Nonnull PropertyDefinition input) {
-      return key.equals(input.key());
-    }
-  }
 }
index f5e43721afd5dba85a463318de3e64392656ccf0..2ca7280bea8dc67b2bba1b5e1225e8991c1cb283 100644 (file)
@@ -207,6 +207,12 @@ public interface CoreProperties {
   String CORE_AUTHENTICATOR_REALM = "sonar.security.realm";
 
   String CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE = "sonar.authenticator.ignoreStartupFailure";
+
+  /**
+   * @deprecated since 6.3. This feature is not supported anymore
+   * @see <a href="https://jira.sonarsource.com/browse/SONAR-8208">SONAR-8208/a>
+   */
+  @Deprecated
   String CORE_AUTHENTICATOR_CREATE_USERS = "sonar.authenticator.createUsers";
 
   /**