public class UserTelemetryDto {
- private String uuid;
+ private String uuid = null;
private boolean active = true;
+ private String externalIdentityProvider = null;
@Nullable
- private Long lastConnectionDate;
+ private Long lastConnectionDate = null;
@Nullable
- private Long lastSonarlintConnectionDate;
+ private Long lastSonarlintConnectionDate = null;
public String getUuid() {
return uuid;
return this;
}
+ public String getExternalIdentityProvider() {
+ return externalIdentityProvider;
+ }
+
+ public UserTelemetryDto setExternalIdentityProvider(String externalIdentityProvider) {
+ this.externalIdentityProvider = externalIdentityProvider;
+ return this;
+ }
+
@Nullable
public Long getLastConnectionDate() {
return lastConnectionDate;
SELECT
u.uuid as uuid,
u.active as "active",
+ u.external_identity_provider as "externalIdentityProvider",
u.last_connection_date as "lastConnectionDate",
u.last_sonarlint_connection as "lastSonarlintConnectionDate"
FROM users u
private final String version;
private final Map<String, String> plugins;
private final Database database;
- private final List<String> externalAuthenticationProviders;
private final EditionProvider.Edition edition;
private final String licenseType;
private final Long installationDate;
hasUnanalyzedC = builder.hasUnanalyzedC;
hasUnanalyzedCpp = builder.hasUnanalyzedCpp;
customSecurityConfigs = builder.customSecurityConfigs == null ? emptyList() : builder.customSecurityConfigs;
- externalAuthenticationProviders = builder.externalAuthenticationProviders;
users = builder.users;
projects = builder.projects;
projectStatistics = builder.projectStatistics;
return customSecurityConfigs;
}
- public List<String> getExternalAuthenticationProviders() {
- return externalAuthenticationProviders;
- }
-
public List<UserTelemetryDto> getUserTelemetries() {
return users;
}
private Boolean hasUnanalyzedC;
private Boolean hasUnanalyzedCpp;
private List<String> customSecurityConfigs;
- private List<String> externalAuthenticationProviders;
private List<UserTelemetryDto> users;
private List<Project> projects;
private List<ProjectStatistics> projectStatistics;
// enforce static factory method
}
- Builder setExternalAuthenticationProviders(List<String> providers) {
- this.externalAuthenticationProviders = providers;
- return this;
- }
-
Builder setServerId(String serverId) {
this.serverId = serverId;
return this;
requireNonNull(version);
requireNonNull(plugins);
requireNonNull(database);
- requireNonNull(externalAuthenticationProviders);
return new TelemetryData(this);
}
statistics.hasUnanalyzedC().ifPresent(hasUnanalyzedC -> json.prop("hasUnanalyzedC", hasUnanalyzedC));
statistics.hasUnanalyzedCpp().ifPresent(hasUnanalyzedCpp -> json.prop("hasUnanalyzedCpp", hasUnanalyzedCpp));
- json.name("externalAuthProviders");
- json.beginArray();
- statistics.getExternalAuthenticationProviders().forEach(json::value);
- json.endArray();
-
if (statistics.getInstallationDate() != null) {
json.prop("installationDate", toUtc(statistics.getInstallationDate()));
}
json.beginObject();
json.prop("userUuid", DigestUtils.sha3_224Hex(user.getUuid()));
json.prop("status", user.isActive() ? "active" : "inactive");
+ json.prop("identityProvider", user.getExternalIdentityProvider());
if (user.getLastConnectionDate() != null) {
json.prop("lastActivity", toUtc(user.getLastConnectionDate()));
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.user.UserTelemetryDto;
-import static java.util.Arrays.asList;
import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
.setServerId("foo")
.setVersion("bar")
.setPlugins(Collections.emptyMap())
- .setExternalAuthenticationProviders(asList("github", "gitlab"))
.setDatabase(new TelemetryData.Database("H2", "11"));
private final Random random = new Random();
assertThat(json).doesNotContain("edition");
}
- @Test
- public void write_external_auth_providers() {
- TelemetryData data = SOME_TELEMETRY_DATA.build();
-
- String json = writeTelemetryData(data);
-
- assertJson(json).isSimilarTo("{ \"externalAuthProviders\": [ \"github\", \"gitlab\" ] }");
- }
-
@Test
@UseDataProvider("allEditions")
public void writes_edition_if_non_null(EditionProvider.Edition edition) {
" {" +
" \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-0") + "\"," +
" \"lastActivity\":\"1970-01-01T00:00:00+0000\"," +
+ " \"identityProvider\":\"gitlab\"," +
" \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," +
" \"status\":\"active\"" +
" }," +
" {" +
" \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-1") + "\"," +
" \"lastActivity\":\"1970-01-01T00:00:00+0000\"," +
+ " \"identityProvider\":\"gitlab\"," +
" \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," +
" \"status\":\"inactive\"" +
" }," +
" {" +
" \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-2") + "\"," +
" \"lastActivity\":\"1970-01-01T00:00:00+0000\"," +
+ " \"identityProvider\":\"gitlab\"," +
" \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," +
" \"status\":\"active\"" +
" }" +
@NotNull
private static List<UserTelemetryDto> getUsers() {
- return IntStream.range(0, 3).mapToObj(i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L).setLastSonarlintConnectionDate(2L))
+ return IntStream.range(0, 3)
+ .mapToObj(
+ i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L).setLastSonarlintConnectionDate(2L).setExternalIdentityProvider("gitlab"))
.collect(Collectors.toList());
}
data.setHasUnanalyzedCpp(numberOfUnanalyzedCppMeasures > 0);
});
- data.setExternalAuthenticationProviders(dbClient.userDao().selectExternalIdentityProviders(dbSession));
-
Map<String, String> scmByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDSCM);
Map<String, String> ciByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDCI);
Map<String, ProjectAlmKeyAndProject> almAndUrlByProject = getAlmAndUrlByProject(dbSession);
import org.sonar.server.util.GlobalLockManager;
import org.sonar.server.util.GlobalLockManagerImpl;
-import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
.setServerId("foo")
.setVersion("bar")
.setPlugins(Collections.emptyMap())
- .setExternalAuthenticationProviders(singletonList("github"))
- .setExternalAuthenticationProviders(Collections.emptyList())
.setDatabase(new TelemetryData.Database("H2", "11"))
.build();
assertThat(data.getPlugins()).containsOnly(
entry("java", "4.12.0.11033"), entry("scmgit", "1.2"), entry("other", "undefined"));
assertThat(data.isInDocker()).isFalse();
- assertThat(data.getExternalAuthenticationProviders()).containsExactlyInAnyOrder("provider0", "provider1", "provider2");
assertThat(data.getUserTelemetries())
.extracting(UserTelemetryDto::getUuid, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate, UserTelemetryDto::isActive)