Search in sources :

Example 1 with AuthenticationChecker

use of org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker in project sonarlint-core by SonarSource.

the class ConnectionValidator method validateConnection.

public CompletableFuture<ValidationResult> validateConnection() {
    var serverChecker = new ServerVersionAndStatusChecker(helper);
    var authChecker = new AuthenticationChecker(helper);
    return serverChecker.checkVersionAndStatusAsync().thenApply(check -> {
        var validateCredentials = authChecker.validateCredentials();
        var organizationKey = helper.getOrganizationKey();
        if (validateCredentials.success() && organizationKey.isPresent()) {
            var organization = new ServerApi(helper).organization().fetchOrganization(organizationKey.get(), new ProgressMonitor(null));
            if (organization.isEmpty()) {
                return new DefaultValidationResult(false, "No organizations found for key: " + organizationKey.get());
            }
        }
        return validateCredentials;
    }).exceptionally(e -> new DefaultValidationResult(false, e.getCause().getMessage()));
}
Also used : AuthenticationChecker(org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker) ServerOrganization(org.sonarsource.sonarlint.core.serverapi.organization.ServerOrganization) ValidationResult(org.sonarsource.sonarlint.core.serverapi.system.ValidationResult) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) DefaultValidationResult(org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker) AuthenticationChecker(org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker) DefaultValidationResult(org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi)

Aggregations

Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)1 ServerApi (org.sonarsource.sonarlint.core.serverapi.ServerApi)1 ServerApiHelper (org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)1 AuthenticationChecker (org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker)1 ServerOrganization (org.sonarsource.sonarlint.core.serverapi.organization.ServerOrganization)1 DefaultValidationResult (org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult)1 ServerVersionAndStatusChecker (org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker)1 ValidationResult (org.sonarsource.sonarlint.core.serverapi.system.ValidationResult)1