import org.jetbrains.annotations.Nullable;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.regex.Pattern;
private JiraRemoteApi myApiVersion;
private String myJiraVersion;
+ private boolean myInCloud = false;
/**
* Serialization constructor
super(other);
mySearchQuery = other.mySearchQuery;
myJiraVersion = other.myJiraVersion;
+ myInCloud = other.myInCloud;
if (other.myApiVersion != null) {
myApiVersion = other.myApiVersion.getType().createApi(this);
}
if (!Comparing.equal(mySearchQuery, repository.getSearchQuery())) return false;
if (!Comparing.equal(myJiraVersion, repository.getJiraVersion())) return false;
+ if (!Comparing.equal(myInCloud, repository.isInCloud())) return false;
return true;
}
// when JIRA 4.x support will be dropped 'versionNumber' array in response
// may be used instead version string parsing
myJiraVersion = serverInfo.get("version").getAsString();
- LOG.info("JIRA version (from serverInfo): " + myJiraVersion);
- if (isOnDemand()) {
+ final boolean hostedInCloud = hostEndsWith(serverInfo.get("baseUrl").getAsString(), "atlassian.net");
+ // Legacy JIRA onDemand versions contained "OD" abbreviation
+ myInCloud = StringUtil.notNullize(myJiraVersion).contains("OD") || hostedInCloud;
+ LOG.info("JIRA version (from serverInfo): " + myJiraVersion + (myInCloud ? " (Cloud)" : ""));
+ if (isInCloud()) {
LOG.info("Connecting to JIRA on-Demand. Cookie authentication is enabled unless 'tasks.jira.basic.auth.only' VM flag is used.");
}
JiraRestApi restApi = JiraRestApi.fromJiraVersion(myJiraVersion, this);
return restApi;
}
+ private static boolean hostEndsWith(@NotNull String url, @NotNull String suffix) {
+ try {
+ final URL parsed = new URL(url);
+ return parsed.getHost().endsWith(suffix);
+ }
+ catch (MalformedURLException ignored) {
+ }
+ return false;
+ }
+
private JiraLegacyApi createLegacyApi() {
try {
XmlRpcClient client = new XmlRpcClient(getUrl());
// See https://confluence.atlassian.com/display/ONDEMANDKB/Getting+randomly+logged+out+of+OnDemand for details
// IDEA-128824, IDEA-128706 Use cookie authentication only for JIRA on-Demand
// TODO Make JiraVersion more suitable for such checks
- if (BASIC_AUTH_ONLY || !isOnDemand()) {
+ if (BASIC_AUTH_ONLY || !isInCloud()) {
// to override persisted settings
setUseHttpAuthentication(true);
}
throw new Exception(TaskBundle.message("failure.http.error", statusCode, statusText));
}
- public boolean isOnDemand() {
- return StringUtil.notNullize(myJiraVersion).contains("OD");
+ public boolean isInCloud() {
+ return myInCloud;
+ }
+
+ public void setInCloud(boolean inCloud) {
+ myInCloud = inCloud;
}
private static boolean containsCookie(@NotNull HttpClient client, @NotNull String cookieName) {
// reset remote API version, only if server URL was changed
if (!getUrl().equals(oldUrl)) {
myApiVersion = null;
+ myInCloud = false;
}
}