Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 02794200C16 for ; Wed, 25 Jan 2017 12:39:25 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 01014160B5A; Wed, 25 Jan 2017 11:39:25 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2779C160B50 for ; Wed, 25 Jan 2017 12:39:24 +0100 (CET) Received: (qmail 86198 invoked by uid 500); 25 Jan 2017 11:39:23 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 86140 invoked by uid 99); 25 Jan 2017 11:39:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jan 2017 11:39:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3B3F7DFDC6; Wed, 25 Jan 2017 11:39:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ptupitsyn@apache.org To: commits@ignite.apache.org Date: Wed, 25 Jan 2017 11:39:24 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/6] ignite git commit: IGNITE-4520 Added credential request for authentication on proxy. archived-at: Wed, 25 Jan 2017 11:39:25 -0000 IGNITE-4520 Added credential request for authentication on proxy. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ef04f35f Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ef04f35f Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ef04f35f Branch: refs/heads/ignite-2.0 Commit: ef04f35fad5a8e74ee3e5f7fb6085a8e101d19ef Parents: d4d5976 Author: Andrey Novikov Authored: Wed Jan 25 13:58:57 2017 +0700 Committer: Andrey Novikov Committed: Wed Jan 25 13:58:57 2017 +0700 ---------------------------------------------------------------------- .../web-agent/bin/ignite-web-agent.bat | 4 +- .../web-agent/bin/ignite-web-agent.sh | 2 + .../ignite/console/agent/AgentLauncher.java | 90 ++++++++++++++++++-- 3 files changed, 88 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/ef04f35f/modules/web-console/web-agent/bin/ignite-web-agent.bat ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/bin/ignite-web-agent.bat b/modules/web-console/web-agent/bin/ignite-web-agent.bat index 8291b55..1f1b52d 100644 --- a/modules/web-console/web-agent/bin/ignite-web-agent.bat +++ b/modules/web-console/web-agent/bin/ignite-web-agent.bat @@ -60,7 +60,9 @@ if %ERRORLEVEL% equ 0 ( if "%JVM_OPTS%" == "" set JVM_OPTS=-Xms1g -Xmx1g -server -XX:+AggressiveOpts -XX:MaxMetaspaceSize=256m ) -"%JAVA_HOME%\bin\java.exe" %JVM_OPTS% -cp "*" org.apache.ignite.console.agent.AgentLauncher %* +set JVM_OPTS=%JVM_OPTS% -Djava.net.useSystemProxies=true + +"%JAVA_HOME%\bin\java.exe" %JVM_OPTS% -cp "*" org.apache.ignite.console.agent.AgentLauncher %* set JAVA_ERRORLEVEL=%ERRORLEVEL% http://git-wip-us.apache.org/repos/asf/ignite/blob/ef04f35f/modules/web-console/web-agent/bin/ignite-web-agent.sh ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/bin/ignite-web-agent.sh b/modules/web-console/web-agent/bin/ignite-web-agent.sh index 2e9f041..c2958fc 100644 --- a/modules/web-console/web-agent/bin/ignite-web-agent.sh +++ b/modules/web-console/web-agent/bin/ignite-web-agent.sh @@ -88,4 +88,6 @@ if [ -z "$JVM_OPTS" ] ; then fi fi +JVM_OPTS="${JVM_OPTS} -Djava.net.useSystemProxies=true" + "$JAVA" ${JVM_OPTS} -cp "*" org.apache.ignite.console.agent.AgentLauncher "$@" http://git-wip-us.apache.org/repos/asf/ignite/blob/ef04f35f/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java index 0c03d77..049791f 100644 --- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/AgentLauncher.java @@ -25,11 +25,15 @@ import io.socket.client.Socket; import io.socket.emitter.Emitter; import java.io.File; import java.io.IOException; +import java.net.Authenticator; import java.net.ConnectException; +import java.net.PasswordAuthentication; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.UnknownHostException; import java.util.Arrays; +import java.util.Scanner; import java.util.concurrent.CountDownLatch; import java.util.jar.Attributes; import java.util.jar.Manifest; @@ -76,9 +80,6 @@ public class AgentLauncher { /** */ private static final String EVENT_AGENT_CLOSE = "agent:close"; - /** */ - private static final int RECONNECT_INTERVAL = 3000; - /** * Create a trust manager that trusts all certificates It is not using a particular keyStore */ @@ -121,6 +122,15 @@ public class AgentLauncher { System.exit(1); } + ignore = X.cause(e, UnknownHostException.class); + + if (ignore != null) { + log.error("Failed to establish connection to server, due to errors with DNS or missing proxy settings."); + log.error("Documentation for proxy configuration can be found here: http://apacheignite.readme.io/docs/web-agent#section-proxy-configuration"); + + System.exit(1); + } + ignore = X.cause(e, IOException.class); if (ignore != null && "404".equals(ignore.getMessage())) { @@ -129,6 +139,29 @@ public class AgentLauncher { return; } + if (ignore != null && "407".equals(ignore.getMessage())) { + log.error("Failed to establish connection to server, due to proxy requires authentication."); + + String userName = System.getProperty("https.proxyUsername", System.getProperty("http.proxyUsername")); + + if (userName == null || userName.trim().isEmpty()) + userName = readLine("Enter proxy user name: "); + else + System.out.println("Read username from system properties: " + userName); + + char[] pwd = readPassword("Enter proxy password: "); + + final PasswordAuthentication pwdAuth = new PasswordAuthentication(userName, pwd); + + Authenticator.setDefault(new Authenticator() { + @Override protected PasswordAuthentication getPasswordAuthentication() { + return pwdAuth; + } + }); + + return; + } + log.error("Connection error.", e); } } @@ -144,6 +177,32 @@ public class AgentLauncher { }; /** + * @param fmt Format string. + * @param args Arguments. + */ + private static String readLine(String fmt, Object ... args) { + if (System.console() != null) + return System.console().readLine(fmt, args); + + System.out.print(String.format(fmt, args)); + + return new Scanner(System.in).nextLine(); + } + + /** + * @param fmt Format string. + * @param args Arguments. + */ + private static char[] readPassword(String fmt, Object ... args) { + if (System.console() != null) + return System.console().readPassword(fmt, args); + + System.out.print(String.format(fmt, args)); + + return new Scanner(System.in).nextLine().toCharArray(); + } + + /** * @param args Args. */ @SuppressWarnings("BusyWait") @@ -214,9 +273,9 @@ public class AgentLauncher { System.out.println("Security token is required to establish connection to the web console."); System.out.println(String.format("It is available on the Profile page: https://%s/profile", webHost)); - System.out.print("Enter security tokens separated by comma: "); + String tokens = String.valueOf(readPassword("Enter security tokens separated by comma: ")); - cfg.tokens(Arrays.asList(System.console().readLine().trim().split(","))); + cfg.tokens(Arrays.asList(tokens.trim().split(","))); } final RestHandler restHnd = new RestHandler(cfg); @@ -226,12 +285,29 @@ public class AgentLauncher { URI uri = URI.create(cfg.serverUri()); + // Create proxy authenticator using passed properties. + switch (uri.getScheme()) { + case "http": + case "https": + final String username = System.getProperty(uri.getScheme() + ".proxyUsername"); + final char[] pwd = System.getProperty(uri.getScheme() + ".proxyPassword", "").toCharArray(); + + Authenticator.setDefault(new Authenticator() { + @Override protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, pwd); + } + }); + + break; + + default: + // No-op. + } + IO.Options opts = new IO.Options(); opts.path = "/agents"; - opts.reconnectionDelay = RECONNECT_INTERVAL; - // Workaround for use self-signed certificate if (Boolean.getBoolean("trust.all")) { SSLContext ctx = SSLContext.getInstance("TLS");