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;
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();
}
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 {
+ 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();
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;
return userLogin;
}
- private class ExternalIdentityProvider implements IdentityProvider {
+ private static class ExternalIdentityProvider implements IdentityProvider {
@Override
public String getKey() {
return SQ_AUTHORITY;
@Override
public boolean allowsUsersToSignUp() {
- return settings.getBoolean(CORE_AUTHENTICATOR_CREATE_USERS);
+ return true;
}
}
.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);
}
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));
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);
.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)
*/
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());
- }
- }
}
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";
/**