Github: select 'Host' part of url for list of trusted hosts

Before this commit we save 'https://mycompany.com/github' from settings and compare it with 'mycompany.com' from URI
This commit is contained in:
Aleksey Pivovarov
2013-09-28 17:29:36 +04:00
parent 64d03a138a
commit 5b7f0fcad3
2 changed files with 22 additions and 1 deletions
@@ -111,7 +111,13 @@ public class GithubSslSupport {
}
@CalledInAwt
public boolean askIfShouldProceed(final String host) {
public boolean askIfShouldProceed(final String url) {
String host = GithubUrlUtil.getHostFromUrl(url);
if (host == null) {
GithubUtil.LOG.warn("Bad SSL host: " + url);
return false;
}
final String BACK_TO_SAFETY = "No, I don't trust";
final String TRUST = "Proceed anyway";
//int choice = Messages.showDialog("The security certificate of " + host + " is not trusted. Do you want to proceed anyway?",
@@ -16,6 +16,8 @@
package org.jetbrains.plugins.github.util;
import com.intellij.openapi.util.text.StringUtil;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.github.api.GithubApiUtil;
@@ -71,6 +73,19 @@ public class GithubUrlUtil {
return "https://" + getGitHostWithoutProtocol();
}
/**
* E.g.: https://github.com/suffix/ -> github.com
*/
@Nullable
public static String getHostFromUrl(@NotNull String url) {
try {
return new URI(url, false).getHost();
}
catch (URIException e) {
return null;
}
}
/**
* E.g.: github.com
* my.company.url