Skip to content

Commit 4f01bb8

Browse files
SNOW-1708383: Fix opening external browser on win (#2053)
1 parent 9e1a5ac commit 4f01bb8

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
repos:
22
- repo: [email protected]:snowflakedb/casec_precommit.git
3-
rev: v1.11
3+
rev: v1.35.5
44
hooks:
55
- id: secret-scanner

src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.databind.JsonNode;
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.google.common.base.Strings;
9+
import java.awt.Desktop;
910
import java.io.BufferedReader;
1011
import java.io.IOException;
1112
import java.io.InputStreamReader;
@@ -69,24 +70,22 @@ public HttpPost build(URI uri) {
6970

7071
@Override
7172
public void openBrowser(String ssoUrl) throws SFException {
73+
if (!URLUtil.isValidURL(ssoUrl)) {
74+
throw new SFException(ErrorCode.INVALID_CONNECTION_URL, "Invalid SSOUrl found - " + ssoUrl);
75+
}
7276
try {
7377
// start web browser
74-
if (!URLUtil.isValidURL(ssoUrl)) {
75-
throw new SFException(
76-
ErrorCode.INVALID_CONNECTION_URL, "Invalid SSOUrl found - " + ssoUrl);
77-
}
78-
if (java.awt.Desktop.isDesktopSupported()) {
79-
URI uri = new URI(ssoUrl);
80-
java.awt.Desktop.getDesktop().browse(uri);
78+
Runtime runtime = Runtime.getRuntime();
79+
Constants.OS os = Constants.getOS();
80+
if (Desktop.isDesktopSupported()
81+
&& Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
82+
Desktop.getDesktop().browse(new URI(ssoUrl));
83+
} else if (os == Constants.OS.MAC) {
84+
runtime.exec("open " + ssoUrl);
85+
} else if (os == Constants.OS.WINDOWS) {
86+
runtime.exec(new String[] {"rundll32", "url.dll,FileProtocolHandler", ssoUrl});
8187
} else {
82-
Runtime runtime = Runtime.getRuntime();
83-
Constants.OS os = Constants.getOS();
84-
if (os == Constants.OS.MAC) {
85-
runtime.exec("open " + ssoUrl);
86-
} else {
87-
// linux?
88-
runtime.exec("xdg-open " + ssoUrl);
89-
}
88+
runtime.exec("xdg-open " + ssoUrl);
9089
}
9190
} catch (URISyntaxException | IOException ex) {
9291
throw new SFException(ex, ErrorCode.NETWORK_ERROR, ex.getMessage());

0 commit comments

Comments
 (0)