Java 类com.intellij.util.proxy.CommonProxy 实例源码

项目:intellij-ce-playground    文件:AuthenticationService.java   
@Nullable
public static Proxy getIdeaDefinedProxy(@NotNull final SVNURL url) {
  // SVNKit authentication implementation sets repositories as noProxy() to provide custom proxy authentication logic - see for instance,
  // SvnAuthenticationManager.getProxyManager(). But noProxy() setting is not cleared correctly in all cases - so if svn command
  // (for command line) is executed on thread where repository url was added as noProxy() => proxies are not retrieved for such commands
  // and execution logic is incorrect.

  // To prevent such behavior repositoryUrl is manually removed from noProxy() list (for current thread).
  // NOTE, that current method is only called from code flows for executing commands through command line client and should not be called
  // from SVNKit code flows.
  CommonProxy.getInstance().removeNoProxy(url.getProtocol(), url.getHost(), url.getPort());

  final List<Proxy> proxies = CommonProxy.getInstance().select(URI.create(url.toString()));
  if (proxies != null && !proxies.isEmpty()) {
    for (Proxy proxy : proxies) {
      if (HttpConfigurable.isRealProxy(proxy) && Proxy.Type.HTTP.equals(proxy.type())) {
        return proxy;
      }
    }
  }
  return null;
}
项目:vso-intellij    文件:HTTPProxyInfo.java   
public static HTTPProxyInfo getCurrent() {
  // axis will override the higher-level settings with system properties, so explicitly clear them
  CommonProxy.isInstalledAssertion();

  if (TFSConfigurationManager.getInstance().useIdeaHttpProxy()) {
    final HttpConfigurable hc = HttpConfigurable.getInstance();
    if (hc.USE_HTTP_PROXY) {
      if (hc.PROXY_AUTHENTICATION) {
        // here we assume proxy auth dialog was shown if needed, see promptForPassword() caller
        return new HTTPProxyInfo(hc.PROXY_HOST, hc.PROXY_PORT, hc.PROXY_LOGIN, hc.getPlainProxyPassword());
      }
      else {
        return new HTTPProxyInfo(hc.PROXY_HOST, hc.PROXY_PORT, null, null);
      }
    }
  }
  return new HTTPProxyInfo(null, -1, null, null);
}
项目:tools-idea    文件:HttpConfigurable.java   
@Override
public void writeExternal(Element element) throws WriteExternalException {
  CommonProxy.isInstalledAssertion();
  XmlSerializer.serializeInto(getState(), element);
  if (USE_PROXY_PAC && USE_HTTP_PROXY && ! ApplicationManager.getApplication().isDisposed()) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        final IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
        if (frame != null) {
          USE_PROXY_PAC = false;
          Messages.showMessageDialog(frame.getComponent(), "Proxy: both 'use proxy' and 'autodetect proxy' settings were set." +
                                                           "\nOnly one of these options should be selected.\nPlease re-configure.",
                                     "Proxy setup", Messages.getWarningIcon());
          editConfigurable(frame.getComponent());
        }
      }
    }, ModalityState.NON_MODAL);
  }
}
项目:tools-idea    文件:HttpConfigurable.java   
/**
 * todo [all] It is NOT nessesary to call anything if you obey common IDEA proxy settings;
 * todo if you want to define your own behaviour, refer to {@link com.intellij.util.proxy.CommonProxy}
 *
 * also, this method is useful in a way that it test connection to the host [through proxy]
 *
 * @param url URL for HTTP connection
 * @throws IOException
 */
public void prepareURL (String url) throws IOException {
  //setAuthenticator();
  CommonProxy.isInstalledAssertion();

  final URLConnection connection = openConnection(url);
  try {
    connection.setConnectTimeout(3 * 1000);
    connection.setReadTimeout(3 * 1000);
    connection.connect();
    connection.getInputStream();
  }
  catch (Throwable e) {
    if (e instanceof IOException) {
      throw (IOException)e;
    }
  } finally {
    if (connection instanceof HttpURLConnection) {
      ((HttpURLConnection)connection).disconnect();
    }
  }
}
项目:tools-idea    文件:HttpConfigurable.java   
public URLConnection openConnection(@NotNull String location) throws IOException {
  CommonProxy.isInstalledAssertion();
  final URL url = new URL(location);
  URLConnection urlConnection = null;
  final List<Proxy> proxies = CommonProxy.getInstance().select(url);
  if (proxies == null || proxies.isEmpty()) {
    urlConnection = url.openConnection();
  } else {
    IOException ioe = null;
    for (Proxy proxy : proxies) {
      try {
        urlConnection = url.openConnection(proxy);
      } catch (IOException e) {
        // continue iteration
        ioe = e;
      }
    }
    if (urlConnection == null && ioe != null) {
      throw ioe;
    }
  }
  return urlConnection;
}
项目:intellij-ce-playground    文件:HttpProxySettingsUi.java   
@Override
public void reset(@NotNull HttpConfigurable settings) {
  myNoProxyRb.setSelected(true);  // default
  myAutoDetectProxyRb.setSelected(settings.USE_PROXY_PAC);
  myPacUrlCheckBox.setSelected(settings.USE_PAC_URL);
  myPacUrlTextField.setText(settings.PAC_URL);
  myUseHTTPProxyRb.setSelected(settings.USE_HTTP_PROXY);
  myProxyAuthCheckBox.setSelected(settings.PROXY_AUTHENTICATION);

  enableProxy(settings.USE_HTTP_PROXY);

  myProxyLoginTextField.setText(settings.PROXY_LOGIN);
  myProxyPasswordTextField.setText(settings.getPlainProxyPassword());

  myProxyPortTextField.setNumber(settings.PROXY_PORT);
  myProxyHostTextField.setText(settings.PROXY_HOST);
  myProxyExceptions.setText(StringUtil.notNullize(settings.PROXY_EXCEPTIONS));

  myRememberProxyPasswordCheckBox.setSelected(settings.KEEP_PROXY_PASSWORD);
  mySocks.setSelected(settings.PROXY_TYPE_IS_SOCKS);
  myHTTP.setSelected(!settings.PROXY_TYPE_IS_SOCKS);

  boolean showError = !StringUtil.isEmptyOrSpaces(settings.LAST_ERROR);
  myErrorLabel.setVisible(showError);
  myErrorLabel.setText(showError ? errorText(settings.LAST_ERROR) : null);

  final String oldStyleText = CommonProxy.getMessageFromProps(CommonProxy.getOldStyleProperties());
  myOtherWarning.setVisible(oldStyleText != null);
  if (oldStyleText != null) {
    myOtherWarning.setText(oldStyleText);
    myOtherWarning.setIcon(Messages.getWarningIcon());
  }
}
项目:intellij-ce-playground    文件:HttpConfigurable.java   
@Override
public HttpConfigurable getState() {
  CommonProxy.isInstalledAssertion();

  HttpConfigurable state = new HttpConfigurable();
  XmlSerializerUtil.copyBean(this, state);
  if (!KEEP_PROXY_PASSWORD) {
    state.PROXY_PASSWORD_CRYPT = null;
  }
  correctPasswords(state);
  return state;
}
项目:intellij-ce-playground    文件:HttpConfigurable.java   
@Override
public void initComponent() {
  mySelector = new IdeaWideProxySelector(this);
  String name = getClass().getName();
  CommonProxy.getInstance().setCustom(name, mySelector);
  CommonProxy.getInstance().setCustomAuth(name, new IdeaWideAuthenticator(this));
}
项目:intellij-ce-playground    文件:HttpConfigurable.java   
private void correctPasswords(@NotNull HttpConfigurable to) {
  synchronized (myLock) {
    to.myGenericPasswords.retainEntries(new TObjectObjectProcedure<CommonProxy.HostInfo, ProxyInfo>() {
      @Override
      public boolean execute(CommonProxy.HostInfo hostInfo, ProxyInfo proxyInfo) {
        return proxyInfo.isStore();
      }
    });
  }
}
项目:intellij-ce-playground    文件:HttpConfigurable.java   
public PasswordAuthentication getGenericPassword(@NotNull String host, int port) {
  final ProxyInfo proxyInfo;
  synchronized (myLock) {
    proxyInfo = myGenericPasswords.get(new CommonProxy.HostInfo(null, host, port));
  }
  if (proxyInfo == null) {
    return null;
  }
  return new PasswordAuthentication(proxyInfo.getUsername(), decode(String.valueOf(proxyInfo.getPasswordCrypt())).toCharArray());
}
项目:intellij-ce-playground    文件:IdeaWideProxySelector.java   
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
  if (myHttpConfigurable.USE_PROXY_PAC) {
    myHttpConfigurable.removeGeneric(new CommonProxy.HostInfo(uri.getScheme(), uri.getHost(), uri.getPort()));
    LOG.debug("generic proxy credentials (if were saved) removed");
    return;
  }

  final InetSocketAddress isa = sa instanceof InetSocketAddress ? (InetSocketAddress) sa : null;
  if (myHttpConfigurable.USE_HTTP_PROXY && isa != null && Comparing.equal(myHttpConfigurable.PROXY_HOST, isa.getHostName())) {
    LOG.debug("connection failed message passed to http configurable");
    myHttpConfigurable.LAST_ERROR = ioe.getMessage();
  }
}
项目:intellij-ce-playground    文件:IdeaWideAuthenticator.java   
@Override
public PasswordAuthentication getPasswordAuthentication() {
  final String host = CommonProxy.getHostNameReliably(getRequestingHost(), getRequestingSite(), getRequestingURL());
  final boolean isProxy = Authenticator.RequestorType.PROXY.equals(getRequestorType());
  final String prefix = isProxy ? "Proxy authentication: " : "Server authentication: ";
  Application application = ApplicationManager.getApplication();
  if (isProxy) {
    // according to idea-wide settings
    if (myHttpConfigurable.USE_HTTP_PROXY) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return common defined proxy");
      return myHttpConfigurable.getPromptedAuthentication(host + ":" + getRequestingPort(), getRequestingPrompt());
    }
    else if (myHttpConfigurable.USE_PROXY_PAC) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return autodetected proxy");
      if (myHttpConfigurable.isGenericPasswordCanceled(host, getRequestingPort())) return null;
      // same but without remembering the results..
      final PasswordAuthentication password = myHttpConfigurable.getGenericPassword(host, getRequestingPort());
      if (password != null) {
        return password;
      }
      // do not try to show any dialogs if application is exiting
      if (application == null || application.isDisposeInProgress() ||
          application.isDisposed()) {
        return null;
      }

      return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), true);
    }
  }

  // do not try to show any dialogs if application is exiting
  if (application == null || application.isDisposeInProgress() || application.isDisposed()) {
    return null;
  }

  LOG.debug("CommonAuthenticator.getPasswordAuthentication generic authentication will be asked");
  //return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), false);
  return null;
}
项目:intellij-ce-playground    文件:SocksAuthenticatorManager.java   
public void register(final ConnectionSettings connectionSettings) {
  SshLogger.debug("register in authenticator");
  ensureRegistered();
  mySelector.register(connectionSettings.getHostName(), connectionSettings.getPort(),
                      connectionSettings.getProxyHostName(), connectionSettings.getProxyPort(),
                      connectionSettings.getProxyLogin(), connectionSettings.getProxyPassword());
  CommonProxy.getInstance().setCustomAuth(getClass().getName(), mySelector.getAuthenticator());
}
项目:intellij-ce-playground    文件:SocksAuthenticatorManager.java   
public void unregister(final ConnectionSettings connectionSettings) {
  SshLogger.debug("unregister in authenticator");
  if (!connectionSettings.isUseProxy()) return;
  final int proxyType = connectionSettings.getProxyType();
  if (proxyType != ProxySettings.SOCKS4 && proxyType != ProxySettings.SOCKS5) return;
  mySelector.unregister(connectionSettings.getHostName(), connectionSettings.getPort());
  CommonProxy.getInstance().removeCustomAuth(getClass().getName());
}
项目:intellij-ce-playground    文件:SocksAuthenticatorManager.java   
private void ensureRegistered() {
  // safe double check
  if (mySelector == null) {
    synchronized (myLock) {
      if (mySelector == null) {
        mySelector = new CvsProxySelector();
        CommonProxy.getInstance().setCustom("com.intellij.cvsSupport2.connections.ssh.CvsSocksSelector", mySelector);
      }
    }
  }
}
项目:intellij-ce-playground    文件:SvnAuthenticationManager.java   
@Override
public void acknowledgeAuthentication(boolean accepted,
                                      String kind,
                                      String realm,
                                      SVNErrorMessage errorMessage,
                                      SVNAuthentication authentication,
                                      SVNURL url) throws SVNException {
  showSshAgentErrorIfAny(errorMessage, authentication);

  SSLExceptionsHelper.removeInfo();
  ourThreadLocalProvider.remove();
  if (url != null) {
    CommonProxy.getInstance().removeNoProxy(url.getProtocol(), url.getHost(), url.getPort());
  }
  boolean successSaving = false;
  myListener.getMulticaster().acknowledge(accepted, kind, realm, errorMessage, authentication);
  try {
    final boolean authStorageEnabled = getHostOptionsProvider().getHostOptions(authentication.getURL()).isAuthStorageEnabled();
    final SVNAuthentication proxy = ProxySvnAuthentication.proxy(authentication, authStorageEnabled, myArtificialSaving);
    super.acknowledgeAuthentication(accepted, kind, realm, errorMessage, proxy);
    successSaving = true;
  } finally {
    mySavePermissions.remove();
    if (myArtificialSaving) {
      myArtificialSaving = false;
      throw new CredentialsSavedException(successSaving);
    }
  }
}
项目:intellij-ce-playground    文件:SvnAuthenticationManager.java   
public ISVNProxyManager getProxyManager(SVNURL url) throws SVNException {
  SSLExceptionsHelper.addInfo("Accessing URL: " + url.toString());
  ourThreadLocalProvider.set(myProvider);
  // in proxy creation, we need proxy information from common proxy. but then we should forbid common proxy to intercept
  final ISVNProxyManager proxy = createProxy(url);
  CommonProxy.getInstance().noProxy(url.getProtocol(), url.getHost(), url.getPort());
  return proxy;
}
项目:tools-idea    文件:HTTPProxySettingsPanel.java   
public void reset() {
  myNoProxyRb.setSelected(true);  // default
  HttpConfigurable httpConfigurable = myHttpConfigurable;
  myAutoDetectProxyRb.setSelected(httpConfigurable.USE_PROXY_PAC);
  myUseHTTPProxyRb.setSelected(httpConfigurable.USE_HTTP_PROXY);
  myProxyAuthCheckBox.setSelected(httpConfigurable.PROXY_AUTHENTICATION);

  enableProxy(httpConfigurable.USE_HTTP_PROXY);

  myProxyLoginTextField.setText(httpConfigurable.PROXY_LOGIN);
  myProxyPasswordTextField.setText(httpConfigurable.getPlainProxyPassword());

  myProxyPortTextField.setText(Integer.toString(httpConfigurable.PROXY_PORT));
  myProxyHostTextField.setText(httpConfigurable.PROXY_HOST);
  myProxyExceptions.setText(httpConfigurable.PROXY_EXCEPTIONS);

  myRememberProxyPasswordCheckBox.setSelected(httpConfigurable.KEEP_PROXY_PASSWORD);
  mySocks.setSelected(httpConfigurable.PROXY_TYPE_IS_SOCKS);
  myHTTP.setSelected(!httpConfigurable.PROXY_TYPE_IS_SOCKS);

  final boolean showError = !StringUtil.isEmptyOrSpaces(httpConfigurable.LAST_ERROR);
  myErrorLabel.setVisible(showError);
  myErrorLabel.setText(showError ? errorText(httpConfigurable.LAST_ERROR) : "");

  final String oldStyleText = CommonProxy.getMessageFromProps(CommonProxy.getOldStyleProperties());
  myOtherWarning.setVisible(oldStyleText != null);
  if (oldStyleText != null) {
    myOtherWarning.setText(oldStyleText);
    myOtherWarning.setUI(new MultiLineLabelUI());
    myOtherWarning.setIcon(Messages.getWarningIcon());
  }
}
项目:tools-idea    文件:HttpConfigurable.java   
@Override
public void initComponent() {
  mySelector = new IdeaWideProxySelector(this);
  myAuthenticator = new IdeaWideAuthenticator(this);
  final String name = getClass().getName();
  CommonProxy.getInstance().setCustom(name, mySelector);
  CommonProxy.getInstance().setCustomAuth(name, myAuthenticator);
}
项目:tools-idea    文件:HttpConfigurable.java   
private void correctPasswords(HttpConfigurable from, HttpConfigurable to) {
  synchronized (myLock) {
    to.myGenericPasswords = new HashMap<CommonProxy.HostInfo, ProxyInfo>();
    for (Map.Entry<CommonProxy.HostInfo, ProxyInfo> entry : from.myGenericPasswords.entrySet()) {
      if (Boolean.TRUE.equals(entry.getValue().isStore())) {
        to.myGenericPasswords.put(entry.getKey(), entry.getValue());
      }
    }
  }
}
项目:tools-idea    文件:HttpConfigurable.java   
public PasswordAuthentication getGenericPassword(final String host, final int port) {
  final ProxyInfo proxyInfo;
  synchronized (myLock) {
    proxyInfo = myGenericPasswords.get(new CommonProxy.HostInfo("", host, port));
  }
  if (proxyInfo == null) return null;
  return new PasswordAuthentication(proxyInfo.getUsername(), decode(String.valueOf(proxyInfo.getPasswordCrypt())).toCharArray());
}
项目:tools-idea    文件:HttpConfigurable.java   
public void putGenericPassword(final String host, final int port, final PasswordAuthentication authentication, final boolean remember) {
  final PasswordAuthentication coded = new PasswordAuthentication(authentication.getUserName(), encode(String.valueOf(authentication.getPassword())).toCharArray());
  synchronized (myLock) {
    myGenericPasswords.put(new CommonProxy.HostInfo("", host, port), new ProxyInfo(remember, coded.getUserName(), String.valueOf(
      coded.getPassword())));
  }
}
项目:tools-idea    文件:IdeaWideProxySelector.java   
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
  if (myHttpConfigurable.USE_PROXY_PAC) {
    myHttpConfigurable.removeGeneric(new CommonProxy.HostInfo(uri.getScheme(), uri.getHost(), uri.getPort()));
    LOG.debug("generic proxy credentials (if were saved) removed");
    return;
  }
  final InetSocketAddress isa = sa instanceof InetSocketAddress ? (InetSocketAddress) sa : null;
  if (myHttpConfigurable.USE_HTTP_PROXY && isa != null && Comparing.equal(myHttpConfigurable.PROXY_HOST, isa.getHostName())) {
    LOG.debug("connection failed message passed to http configurable");
    myHttpConfigurable.LAST_ERROR = ioe.getMessage();
  }
}
项目:tools-idea    文件:IdeaWideAuthenticator.java   
@Override
public PasswordAuthentication getPasswordAuthentication() {
  final String host = CommonProxy.getHostNameReliably(getRequestingHost(), getRequestingSite(), getRequestingURL());
  final boolean isProxy = Authenticator.RequestorType.PROXY.equals(getRequestorType());
  final String prefix = isProxy ? "Proxy authentication: " : "Server authentication: ";
  if (isProxy) {
    // according to idea-wide settings
    if (myHttpConfigurable.USE_HTTP_PROXY) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return common defined proxy");
      return myHttpConfigurable.getPromptedAuthentication(host + ":" + getRequestingPort(), getRequestingPrompt());
    } else if (myHttpConfigurable.USE_PROXY_PAC) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return autodetected proxy");
      if (myHttpConfigurable.isGenericPasswordCanceled(host, getRequestingPort())) return null;
      // same but without remembering the results..
      final PasswordAuthentication password = myHttpConfigurable.getGenericPassword(host, getRequestingPort());
      if (password != null) {
        return password;
      }
      // do not try to show any dialogs if application is exiting
      if (ApplicationManager.getApplication() == null || ApplicationManager.getApplication().isDisposeInProgress() ||
          ApplicationManager.getApplication().isDisposed()) return null;

      return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), true);
    }
  }

  // do not try to show any dialogs if application is exiting
  if (ApplicationManager.getApplication() == null || ApplicationManager.getApplication().isDisposeInProgress() ||
      ApplicationManager.getApplication().isDisposed()) return null;

  LOG.debug("CommonAuthenticator.getPasswordAuthentication generic authentication will be asked");
  //return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), false);
  return null;
}
项目:tools-idea    文件:GitHttpAdapter.java   
private static CommonProxy.HostInfo getHostInfo(String url) throws URISyntaxException {
  final boolean isSecure = url.startsWith("https");
  final String protocol = isSecure ? "https" : "http";
  final URI uri = new URI(url);
  int port = uri.getPort();
  port = port < 0 ? (isSecure ? 443 : 80) : port;
  return new CommonProxy.HostInfo(protocol, uri.getHost(), port);
}
项目:tools-idea    文件:SocksAuthenticatorManager.java   
public void register(final ConnectionSettings connectionSettings) {
  SshLogger.debug("register in authenticator");
  ensureRegistered();
  mySelector.register(connectionSettings.getHostName(), connectionSettings.getPort(),
                      connectionSettings.getProxyHostName(), connectionSettings.getProxyPort(),
                      connectionSettings.getProxyLogin(), connectionSettings.getProxyPassword());
  CommonProxy.getInstance().setCustomAuth(getClass().getName(), mySelector.getAuthenticator());
}
项目:tools-idea    文件:SocksAuthenticatorManager.java   
public void unregister(final ConnectionSettings connectionSettings) {
  SshLogger.debug("unregister in authenticator");
  if (!connectionSettings.isUseProxy()) return;
  final int proxyType = connectionSettings.getProxyType();
  if (proxyType != ProxySettings.SOCKS4 && proxyType != ProxySettings.SOCKS5) return;
  mySelector.unregister(connectionSettings.getHostName(), connectionSettings.getPort());
  CommonProxy.getInstance().removeCustomAuth(getClass().getName());
}
项目:tools-idea    文件:SocksAuthenticatorManager.java   
private void ensureRegistered() {
  // safe double check
  if (mySelector == null) {
    synchronized (myLock) {
      if (mySelector == null) {
        mySelector = new CvsProxySelector();
        CommonProxy.getInstance().setCustom("com.intellij.cvsSupport2.connections.ssh.CvsSocksSelector", mySelector);
      }
    }
  }
}
项目:tools-idea    文件:SvnAuthenticationManager.java   
@Override
public void acknowledgeAuthentication(boolean accepted,
                                      String kind,
                                      String realm,
                                      SVNErrorMessage errorMessage,
                                      SVNAuthentication authentication,
                                      SVNURL url) throws SVNException {
  SSLExceptionsHelper.removeInfo();
  ourThreadLocalProvider.remove();
  if (url != null) {
    CommonProxy.getInstance().removeNoProxy(url.getProtocol(), url.getHost(), url.getPort());
  }
  boolean successSaving = false;
  myListener.getMulticaster().acknowledge(accepted, kind, realm, errorMessage, authentication);
  try {
    final boolean authStorageEnabled = getHostOptionsProvider().getHostOptions(authentication.getURL()).isAuthStorageEnabled();
    final SVNAuthentication proxy = ProxySvnAuthentication.proxy(authentication, authStorageEnabled, myArtificialSaving);
    super.acknowledgeAuthentication(accepted, kind, realm, errorMessage, proxy);
    successSaving = true;
  } finally {
    mySavePermissions.remove();
    if (myArtificialSaving) {
      myArtificialSaving = false;
      throw new CredentialsSavedException(successSaving);
    }
  }
}
项目:tools-idea    文件:SvnAuthenticationManager.java   
public ISVNProxyManager getProxyManager(SVNURL url) throws SVNException {
  SSLExceptionsHelper.addInfo("Accessing URL: " + url.toString());
  ourThreadLocalProvider.set(myProvider);
  // in proxy creation, we need proxy information from common proxy. but then we should forbid common proxy to intercept
  final ISVNProxyManager proxy = createProxy(url);
  CommonProxy.getInstance().noProxy(url.getProtocol(), url.getHost(), url.getPort());
  return proxy;
}
项目:tools-idea    文件:IdeaSvnkitBasedAuthenticationCallback.java   
@Nullable
private static Proxy getIdeaDefinedProxy(final SVNURL url) throws URISyntaxException {
  final List<Proxy> proxies = CommonProxy.getInstance().select(new URI(url.toString()));
  if (proxies != null && ! proxies.isEmpty()) {
    for (Proxy proxy : proxies) {
      if (HttpConfigurable.isRealProxy(proxy) && Proxy.Type.HTTP.equals(proxy.type())) {
        return proxy;
      }
    }
  }
  return null;
}
项目:consulo    文件:HttpProxySettingsUi.java   
@Override
public void reset(@Nonnull HttpConfigurable settings) {
  myNoProxyRb.setSelected(true);  // default
  myAutoDetectProxyRb.setSelected(settings.USE_PROXY_PAC);
  myPacUrlCheckBox.setSelected(settings.USE_PAC_URL);
  myPacUrlTextField.setText(settings.PAC_URL);
  myUseHTTPProxyRb.setSelected(settings.USE_HTTP_PROXY);
  myProxyAuthCheckBox.setSelected(settings.PROXY_AUTHENTICATION);

  enableProxy(settings.USE_HTTP_PROXY);

  myProxyLoginTextField.setText(settings.getProxyLogin());
  myProxyPasswordTextField.setText(settings.getPlainProxyPassword());

  myProxyPortTextField.setNumber(settings.PROXY_PORT);
  myProxyHostTextField.setText(settings.PROXY_HOST);
  myProxyExceptions.setText(StringUtil.notNullize(settings.PROXY_EXCEPTIONS));

  myRememberProxyPasswordCheckBox.setSelected(settings.KEEP_PROXY_PASSWORD);
  mySocks.setSelected(settings.PROXY_TYPE_IS_SOCKS);
  myHTTP.setSelected(!settings.PROXY_TYPE_IS_SOCKS);

  boolean showError = !StringUtil.isEmptyOrSpaces(settings.LAST_ERROR);
  myErrorLabel.setVisible(showError);
  myErrorLabel.setText(showError ? errorText(settings.LAST_ERROR) : null);

  final String oldStyleText = CommonProxy.getMessageFromProps(CommonProxy.getOldStyleProperties());
  myOtherWarning.setVisible(oldStyleText != null);
  if (oldStyleText != null) {
    myOtherWarning.setText(oldStyleText);
    myOtherWarning.setIcon(Messages.getWarningIcon());
  }
}
项目:consulo    文件:HttpConfigurable.java   
@Override
public HttpConfigurable getState() {
  CommonProxy.isInstalledAssertion();

  HttpConfigurable state = new HttpConfigurable();
  XmlSerializerUtil.copyBean(this, state);
  if (!KEEP_PROXY_PASSWORD) {
    removeSecure("proxy.password");
  }
  correctPasswords(state);
  return state;
}
项目:consulo    文件:HttpConfigurable.java   
@Override
public void initComponent() {

  final HttpConfigurable currentState = getState();
  if (currentState != null) {
    final Element serialized = XmlSerializer.serializeIfNotDefault(currentState, new SkipDefaultsSerializationFilter());
    if (serialized == null) {
      // all settings are defaults
      // trying user's proxy configuration entered while obtaining the license
      final SharedProxyConfig.ProxyParameters cfg = SharedProxyConfig.load();
      if (cfg != null) {
        SharedProxyConfig.clear();
        if (cfg.host != null) {
          USE_HTTP_PROXY = true;
          PROXY_HOST = cfg.host;
          PROXY_PORT = cfg.port;
          if (cfg.login != null) {
            setPlainProxyPassword(new String(cfg.password));
            storeSecure("proxy.login", cfg.login);
            PROXY_AUTHENTICATION = true;
            KEEP_PROXY_PASSWORD = true;
          }
        }
      }
    }
  }


  mySelector = new IdeaWideProxySelector(this);
  String name = getClass().getName();
  CommonProxy.getInstance().setCustom(name, mySelector);
  CommonProxy.getInstance().setCustomAuth(name, new IdeaWideAuthenticator(this));
}
项目:consulo    文件:HttpConfigurable.java   
private void correctPasswords(@Nonnull HttpConfigurable to) {
  synchronized (myLock) {
    to.myGenericPasswords.retainEntries(new TObjectObjectProcedure<CommonProxy.HostInfo, ProxyInfo>() {
      @Override
      public boolean execute(CommonProxy.HostInfo hostInfo, ProxyInfo proxyInfo) {
        return proxyInfo.isStore();
      }
    });
  }
}
项目:consulo    文件:HttpConfigurable.java   
public PasswordAuthentication getGenericPassword(@Nonnull String host, int port) {
  final ProxyInfo proxyInfo;
  synchronized (myLock) {
    proxyInfo = myGenericPasswords.get(new CommonProxy.HostInfo(null, host, port));
  }
  if (proxyInfo == null) {
    return null;
  }
  return new PasswordAuthentication(proxyInfo.getUsername(), decode(String.valueOf(proxyInfo.getPasswordCrypt())).toCharArray());
}
项目:consulo    文件:IdeaWideProxySelector.java   
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
  if (myHttpConfigurable.USE_PROXY_PAC) {
    myHttpConfigurable.removeGeneric(new CommonProxy.HostInfo(uri.getScheme(), uri.getHost(), uri.getPort()));
    LOG.debug("generic proxy credentials (if were saved) removed");
    return;
  }

  final InetSocketAddress isa = sa instanceof InetSocketAddress ? (InetSocketAddress) sa : null;
  if (myHttpConfigurable.USE_HTTP_PROXY && isa != null && Comparing.equal(myHttpConfigurable.PROXY_HOST, isa.getHostName())) {
    LOG.debug("connection failed message passed to http configurable");
    myHttpConfigurable.LAST_ERROR = ioe.getMessage();
  }
}
项目:consulo    文件:IdeaWideAuthenticator.java   
@Override
public PasswordAuthentication getPasswordAuthentication() {
  final String host = CommonProxy.getHostNameReliably(getRequestingHost(), getRequestingSite(), getRequestingURL());
  final boolean isProxy = Authenticator.RequestorType.PROXY.equals(getRequestorType());
  final String prefix = isProxy ? "Proxy authentication: " : "Server authentication: ";
  Application application = ApplicationManager.getApplication();
  if (isProxy) {
    // according to idea-wide settings
    if (myHttpConfigurable.USE_HTTP_PROXY) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return common defined proxy");
      return myHttpConfigurable.getPromptedAuthentication(host + ":" + getRequestingPort(), getRequestingPrompt());
    }
    else if (myHttpConfigurable.USE_PROXY_PAC) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return autodetected proxy");
      if (myHttpConfigurable.isGenericPasswordCanceled(host, getRequestingPort())) return null;
      // same but without remembering the results..
      final PasswordAuthentication password = myHttpConfigurable.getGenericPassword(host, getRequestingPort());
      if (password != null) {
        return password;
      }
      // do not try to show any dialogs if application is exiting
      if (application == null || application.isDisposeInProgress() ||
          application.isDisposed()) {
        return null;
      }

      return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), true);
    }
  }

  // do not try to show any dialogs if application is exiting
  if (application == null || application.isDisposeInProgress() || application.isDisposed()) {
    return null;
  }

  LOG.debug("CommonAuthenticator.getPasswordAuthentication generic authentication will be asked");
  //return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), false);
  return null;
}
项目:intellij-ce-playground    文件:HttpConfigurable.java   
@Override
public void disposeComponent() {
  final String name = getClass().getName();
  CommonProxy.getInstance().removeCustom(name);
  CommonProxy.getInstance().removeCustomAuth(name);
}
项目:intellij-ce-playground    文件:HttpConfigurable.java   
public boolean isGenericPasswordCanceled(@NotNull String host, int port) {
  synchronized (myLock) {
    return myGenericCancelled.contains(new CommonProxy.HostInfo(null, host, port));
  }
}