return mapper(dbSession).selectByExternalIdAndIdentityProvider(externalId, externalIdentityProvider);
}
+ public List<String> selectExternalIdentityProviders(DbSession dbSession) {
+ return mapper(dbSession).selectExternalIdentityProviders();
+ }
+
public List<UserDto> selectByExternalIdsAndIdentityProvider(DbSession dbSession, Collection<String> externalIds, String externalIdentityProvider) {
return executeLargeInputs(externalIds, e -> mapper(dbSession).selectByExternalIdsAndIdentityProvider(e, externalIdentityProvider));
}
@CheckForNull
UserDto selectByExternalLoginAndIdentityProvider(@Param("externalLogin") String externalLogin, @Param("externalIdentityProvider") String externalExternalIdentityProvider);
+ List<String> selectExternalIdentityProviders();
+
void scrollAll(ResultHandler<UserDto> handler);
/**
AND u.active=${_true}
</select>
+ <select id="selectExternalIdentityProviders" resultType="string">
+ SELECT distinct(external_identity_provider) from users
+ </select>
+
<select id="selectByExternalIdAndIdentityProvider" parameterType="map" resultType="User">
SELECT
<include refid="userColumns"/>
assertThat(user).isNull();
}
+ @Test
+ public void selectExternalIdentityProviders() {
+ db.users().insertUser(user -> user.setLogin("user1").setExternalIdentityProvider("github"));
+ db.users().insertUser(user -> user.setLogin("user2").setExternalIdentityProvider("sonarqube"));
+ db.users().insertUser(user -> user.setLogin("user3").setExternalIdentityProvider("github"));
+
+ assertThat(underTest.selectExternalIdentityProviders(session)).containsExactlyInAnyOrder("github", "sonarqube");
+ }
+
@Test
public void selectUserByLogin_not_found() {
db.users().insertUser(user -> user.setLogin("user"));
private final Map<String, Long> projectCountByLanguage;
private final Map<String, Long> almIntegrationCountByAlm;
private final Map<String, Long> nclocByLanguage;
+ 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;
}
public String getServerId() {
return customSecurityConfigs;
}
+ public List<String> getExternalAuthenticationProviders() {
+ return externalAuthenticationProviders;
+ }
+
static Builder builder() {
return new Builder();
}
private Boolean hasUnanalyzedC;
private Boolean hasUnanalyzedCpp;
private List<String> customSecurityConfigs;
+ private List<String> externalAuthenticationProviders;
private Builder() {
// enforce static factory method
}
+ Builder setExternalAuthenticationProviders(List<String> providers) {
+ this.externalAuthenticationProviders = providers;
+ return this;
+ }
+
Builder setServerId(String serverId) {
this.serverId = serverId;
return this;
requireNonNull(ncloc);
requireNonNull(database);
requireNonNull(usingBranches);
+ 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", statistics.getInstallationDate());
}
.setNclocByLanguage(Collections.emptyMap())
.build())
.setNcloc(42L)
+ .setExternalAuthenticationProviders(Arrays.asList("github", "gitlab"))
.setDatabase(new TelemetryData.Database("H2", "11"))
.setUsingBranches(true);
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) {
});
data.setAlmIntegrationCountByAlm(countAlmUsage(dbSession));
+ data.setExternalAuthenticationProviders(dbClient.userDao().selectExternalIdentityProviders(dbSession));
+
}
setSecurityCustomConfigIfPresent(data);
+ "\"Search Nodes\":[{\"Name\":\"searchNodes\",\"\":{\"name\":\"searchNodes\"}}],"
+ "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],"
+ "\"userCount\":0,\"projectCount\":0,\"usingBranches\":false,\"ncloc\":0,\"projectCountByLanguage\":[]," +
- "\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}");
+ "\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"externalAuthProviders\":[],\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}");
}
private static NodeInfo createNodeInfo(String name) {
// response does not contain empty "Section Three"
assertThat(writer.toString()).isEqualTo("{\"Health\":\"GREEN\",\"Health Causes\":[],\"Section One\":{\"foo\":\"bar\"},\"Section Two\":{\"one\":1,\"two\":2}," +
"\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],\"userCount\":0,\"projectCount\":0,\"usingBranches\":false," +
- "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}");
+ "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"externalAuthProviders\":[],\"installationDate\":0," +
+ "\"installationVersion\":\"\",\"docker\":false}}");
}
private void logInAsSystemAdministrator() {
.setNclocByLanguage(Collections.emptyMap())
.build())
.setNcloc(42L)
+ .setExternalAuthenticationProviders(Collections.emptyList())
.setDatabase(new TelemetryData.Database("H2", "11"))
.setUsingBranches(true)
.build();
when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER));
int userCount = 3;
- IntStream.range(0, userCount).forEach(i -> db.users().insertUser());
- db.users().insertUser(u -> u.setActive(false));
+ IntStream.range(0, userCount).forEach(i -> db.users().insertUser(u -> u.setExternalIdentityProvider("provider" + i)));
+ db.users().insertUser(u -> u.setActive(false).setExternalIdentityProvider("provider0"));
userIndexer.indexAll();
MetricDto lines = db.measures().insertMetric(m -> m.setKey(LINES_KEY));
.containsEntry("gitlab_cloud", 1L)
.containsEntry("github_cloud", 1L)
.containsEntry("github_server", 1L);
+ assertThat(data.getExternalAuthenticationProviders()).containsExactlyInAnyOrder("provider0", "provider1", "provider2");
}
private void assertDatabaseMetadata(TelemetryData.Database database) {