PasswordAuthentication (final String host, final String prompt) { if (AUTHENTICATION_CANCELLED) { return null; } final String password = getPlainProxyPassword(); if (PROXY_AUTHENTICATION) { final String login = getSecure("proxy.login"); if (!StringUtil.isEmptyOrSpaces(login) && !StringUtil.isEmptyOrSpaces(password)) { return new PasswordAuthentication(login, password.toCharArray()); } } // do not try to show any dialogs if application is exiting if (ApplicationManager.getApplication() == null || ApplicationManager.getApplication().isDisposed()) { return null; } if (ApplicationManager.getApplication().isUnitTestMode()) { return null; } final PasswordAuthentication[] value = new PasswordAuthentication[1]; runAboveAll(() -> { if (AUTHENTICATION_CANCELLED) { return; } // password might have changed, and the check below is for that final String password1 = getPlainProxyPassword(); if (PROXY_AUTHENTICATION) { final String login = getSecure("proxy.login"); if (!StringUtil.isEmptyOrSpaces(login) && !StringUtil.isEmptyOrSpaces(password1)) { value[0] = new PasswordAuthentication(login, password1.toCharArray()); return; } } AuthenticationDialog dialog = new AuthenticationDialog( PopupUtil.getActiveComponent(), IdeBundle.message("dialog.title.proxy.authentication", host), IdeBundle.message("dialog.message.please.enter.credentials.for", prompt), getSecure("proxy.login"), "", KEEP_PROXY_PASSWORD ); dialog.show(); if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) { PROXY_AUTHENTICATION = true; AuthenticationPanel panel = dialog.getPanel(); final boolean keepPass = panel.isRememberPassword(); KEEP_PROXY_PASSWORD = keepPass; storeSecure("proxy.login", StringUtil.nullize(panel.getLogin())); if (keepPass) { setPlainProxyPassword(String.valueOf(panel.getPassword())); } else { removeSecure("proxy.password"); } value[0] = new PasswordAuthentication(panel.getLogin(), panel.getPassword()); } else { AUTHENTICATION_CANCELLED = true; } }); return value[0]; }