//nothing to do
}
+ public static class GsonAppInstallation {
+ @SerializedName("id")
+ long id;
+ @SerializedName("account")
+ GsonAppOrgAccount account;
+
+ public GsonAppInstallation() {
+ // even if empty constructor is not required for Gson, it is strongly
+ // recommended:
+ // http://stackoverflow.com/a/18645370/229031
+ }
+
+ public GsonAppInstallation(long id, GsonAppOrgAccount account) {
+ this.id = id;
+ this.account = account;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public GsonAppOrgAccount getAccount() {
+ return account;
+ }
+ }
+
+ public static class GsonAppOrgAccount {
+ @SerializedName("login")
+ String name;
+ @SerializedName("type")
+ String type;
+
+ public GsonAppOrgAccount() {
+ // even if empty constructor is not required for Gson, it is strongly
+ // recommended:
+ // http://stackoverflow.com/a/18645370/229031
+ }
+
+ public GsonAppOrgAccount(String name, String type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+ }
+
public static class GsonInstallations {
@SerializedName("total_count")
int totalCount;
import static org.sonar.auth.github.GitHubSettings.definitions;
public class GitHubModule extends Module {
+ private static final List<Class<?>> COMPONENT_CLASSES = List.of(
+ GitHubIdentityProvider.class,
+ GitHubSettings.class,
+ GitHubRestClient.class,
+ UserIdentityFactoryImpl.class,
+ ScribeGitHubApi.class
+ );
@Override
protected void configureModule() {
- add(
- GitHubIdentityProvider.class,
- GitHubSettings.class,
- GitHubManagedInstanceService.class,
- GitHubRestClient.class,
- UserIdentityFactoryImpl.class,
- ScribeGitHubApi.class);
+ add(COMPONENT_CLASSES);
List<PropertyDefinition> definitions = definitions();
add(definitions.toArray(new Object[definitions.size()]));
}
-
}
public static final String ALLOW_USERS_TO_SIGN_UP = "sonar.auth.github.allowUsersToSignUp";
public static final String GROUPS_SYNC = "sonar.auth.github.groupsSync";
public static final String API_URL = "sonar.auth.github.apiUrl";
+ public static final String DEFAULT_API_URL = "https://api.github.com/";
public static final String WEB_URL = "sonar.auth.github.webUrl";
+ public static final String DEFAULT_WEB_URL = "https://github.com/";
public static final String ORGANIZATIONS = "sonar.auth.github.organizations";
@VisibleForTesting
static final String PROVISIONING = "provisioning.github.enabled";
return configuration.get(CLIENT_SECRET).orElse("");
}
- String appId() {
+ public String appId() {
return configuration.get(APP_ID).orElse("");
}
- String privateKey() {
+ public String privateKey() {
return configuration.get(PRIVATE_KEY).orElse("");
}
}
@CheckForNull
- String apiURL() {
+ public String apiURL() {
return urlWithEndingSlash(configuration.get(API_URL).orElse(""));
}
.build(),
PropertyDefinition.builder(API_URL)
.name("The API url for a GitHub instance.")
- .description("The API url for a GitHub instance. https://api.github.com/ for Github.com, https://github.company.com/api/v3/ when using Github Enterprise")
+ .description(String.format("The API url for a GitHub instance. %s for Github.com, https://github.company.com/api/v3/ when using Github Enterprise", DEFAULT_API_URL))
.category(CATEGORY)
.subCategory(SUBCATEGORY)
.type(STRING)
- .defaultValue("https://api.github.com/")
+ .defaultValue(DEFAULT_API_URL)
.index(index++)
.build(),
PropertyDefinition.builder(WEB_URL)
.name("The WEB url for a GitHub instance.")
- .description("The WEB url for a GitHub instance. " +
- "https://github.com/ for Github.com, https://github.company.com/ when using GitHub Enterprise.")
+ .description(String.format("The WEB url for a GitHub instance. %s for Github.com, https://github.company.com/ when using GitHub Enterprise.", DEFAULT_WEB_URL))
.category(CATEGORY)
.subCategory(SUBCATEGORY)
.type(STRING)
- .defaultValue("https://github.com/")
+ .defaultValue(DEFAULT_WEB_URL)
.index(index++)
.build(),
PropertyDefinition.builder(ORGANIZATIONS)
public void verify_count_of_added_components() {
ListContainer container = new ListContainer();
new GitHubModule().configure(container);
- assertThat(container.getAddedObjects()).hasSize(16);
+ assertThat(container.getAddedObjects()).hasSize(15);
}
}
@Test
public void isProvisioningEnabled_ifProvisioningEnabledAndGithubAuthEnabled_returnsTrue() {
- enableGithubAuthentication();
+ enableGithubAuthenticationWithGithubApp();
when(internalProperties.read(GitHubSettings.PROVISIONING)).thenReturn(Optional.of(Boolean.TRUE.toString()));
assertThat(underTest.isProvisioningEnabled()).isTrue();
}
settings.setProperty("sonar.auth.github.clientSecret.secured", "secret");
settings.setProperty("sonar.auth.github.enabled", true);
}
+
+ private void enableGithubAuthenticationWithGithubApp() {
+ enableGithubAuthentication();
+ settings.setProperty("sonar.auth.github.appId", "id");
+ settings.setProperty("sonar.auth.github.privateKey.secured", "secret");
+ }
}