use of org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult 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()));
}
use of org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult in project sonarlint-core by SonarSource.
the class AuthenticationChecker method validateCredentials.
public ValidationResult validateCredentials() {
try (var response = serverApiHelper.rawGet("api/authentication/validate?format=json")) {
var code = response.code();
if (response.isSuccessful()) {
var responseStr = response.bodyAsString();
var validateResponse = new Gson().fromJson(responseStr, ValidateResponse.class);
return new DefaultValidationResult(validateResponse.valid, validateResponse.valid ? "Authentication successful" : "Authentication failed");
} else {
return new DefaultValidationResult(false, "HTTP Connection failed (" + code + "): " + response.bodyAsString());
}
}
}
Aggregations