Search in sources :

Example 1 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project intellij-plugins by StepicOrg.

the class StepikAuthManager method initStepikApiClient.

@NotNull
private static synchronized StepikApiClient initStepikApiClient() {
    String osName = System.getProperty("os.name");
    String jre = System.getProperty("java.version");
    String userAgent = String.format("Stepik Union/%s (%s) StepikApiClient/%s %s/%s JRE/%s", getVersion(), osName, StepikApiClient.getVersion(), getCurrentProduct(), getCurrentProductVersion(), jre);
    logger.info(userAgent);
    HttpConfigurable instance = HttpConfigurable.getInstance();
    StepikApiClient client;
    if (instance.USE_HTTP_PROXY) {
        logger.info(String.format("Uses proxy: Host = %s, Port = %s", instance.PROXY_HOST, instance.PROXY_PORT));
        HttpTransportClient transportClient;
        transportClient = HttpTransportClient.getInstance(instance.PROXY_HOST, instance.PROXY_PORT, userAgent);
        client = new StepikApiClient(transportClient);
    } else {
        client = new StepikApiClient(userAgent);
    }
    long lastUserId = getLastUser();
    TokenInfo tokenInfo = getTokenInfo(lastUserId, client);
    client.setTokenInfo(tokenInfo);
    return client;
}
Also used : StepikApiClient(org.stepik.api.client.StepikApiClient) HttpConfigurable(com.intellij.util.net.HttpConfigurable) HttpTransportClient(org.stepik.api.client.HttpTransportClient) TokenInfo(org.stepik.api.objects.auth.TokenInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project intellij-community by JetBrains.

the class SvnAuthenticationNotifier method validationImpl.

private static boolean validationImpl(final Project project, final SVNURL url, final SvnConfiguration configuration, final SvnAuthenticationManager manager, final boolean checkWrite, final String realm, final String kind, boolean interactive) {
    // we should also NOT show proxy credentials dialog if at least fixed proxy was used, so
    Proxy proxyToRelease = null;
    if (!interactive && configuration.isIsUseDefaultProxy()) {
        final HttpConfigurable instance = HttpConfigurable.getInstance();
        if (instance.USE_HTTP_PROXY && instance.PROXY_AUTHENTICATION && (StringUtil.isEmptyOrSpaces(instance.getProxyLogin()) || StringUtil.isEmptyOrSpaces(instance.getPlainProxyPassword()))) {
            return false;
        }
        if (instance.USE_PROXY_PAC) {
            final List<Proxy> select;
            try {
                select = CommonProxy.getInstance().select(new URI(url.toString()));
            } catch (URISyntaxException e) {
                LOG.info("wrong URL: " + url.toString());
                return false;
            }
            if (select != null && !select.isEmpty()) {
                for (Proxy proxy : select) {
                    if (HttpConfigurable.isRealProxy(proxy) && Proxy.Type.HTTP.equals(proxy.type())) {
                        final InetSocketAddress address = (InetSocketAddress) proxy.address();
                        final PasswordAuthentication password = HttpConfigurable.getInstance().getGenericPassword(address.getHostName(), address.getPort());
                        if (password == null) {
                            CommonProxy.getInstance().noAuthentication("http", address.getHostName(), address.getPort());
                            proxyToRelease = proxy;
                        }
                    }
                }
            }
        }
    }
    SvnInteractiveAuthenticationProvider.clearCallState();
    try {
        // start svnkit authentication cycle
        SvnVcs.getInstance(project).getSvnKitManager().createWCClient(manager).doInfo(url, SVNRevision.UNDEFINED, SVNRevision.HEAD);
    //SvnVcs.getInstance(project).getInfo(url, SVNRevision.HEAD, manager);
    } catch (SVNAuthenticationException | SVNCancelException e) {
        log(e);
        return false;
    } catch (final SVNException e) {
        if (e.getErrorMessage().getErrorCode().isAuthentication()) {
            log(e);
            return false;
        }
        LOG.info("some other exc", e);
        if (interactive) {
            showAuthenticationFailedWithHotFixes(project, configuration, e);
        }
        /// !!!! any exception means user should be notified that authorization failed
        return false;
    } finally {
        if (!interactive && configuration.isIsUseDefaultProxy() && proxyToRelease != null) {
            final InetSocketAddress address = (InetSocketAddress) proxyToRelease.address();
            CommonProxy.getInstance().noAuthentication("http", address.getHostName(), address.getPort());
        }
    }
    if (!checkWrite) {
        return true;
    }
    if (SvnInteractiveAuthenticationProvider.wasCalled() && SvnInteractiveAuthenticationProvider.wasCancelled())
        return false;
    if (SvnInteractiveAuthenticationProvider.wasCalled())
        return true;
    final SvnVcs svnVcs = SvnVcs.getInstance(project);
    final SvnInteractiveAuthenticationProvider provider = new SvnInteractiveAuthenticationProvider(svnVcs, manager);
    final SVNAuthentication svnAuthentication = provider.requestClientAuthentication(kind, url, realm, null, null, true);
    if (svnAuthentication != null) {
        configuration.acknowledge(kind, realm, svnAuthentication);
        try {
            configuration.getAuthenticationManager(svnVcs).acknowledgeAuthentication(true, kind, realm, null, svnAuthentication);
        } catch (SVNException e) {
            LOG.info(e);
        }
        return true;
    }
    return false;
}
Also used : SVNException(org.tmatesoft.svn.core.SVNException) CommonProxy(com.intellij.util.proxy.CommonProxy) HttpConfigurable(com.intellij.util.net.HttpConfigurable) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) SVNAuthenticationException(org.tmatesoft.svn.core.SVNAuthenticationException) SVNAuthentication(org.tmatesoft.svn.core.auth.SVNAuthentication)

Example 3 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project intellij-community by JetBrains.

the class AuthenticationService method showFailedAuthenticateProxy.

private static void showFailedAuthenticateProxy() {
    HttpConfigurable instance = HttpConfigurable.getInstance();
    String message = instance.USE_HTTP_PROXY || instance.USE_PROXY_PAC ? "Failed to authenticate to proxy. You can change proxy credentials in HTTP proxy settings." : "Failed to authenticate to proxy.";
    PopupUtil.showBalloonForActiveComponent(message, MessageType.ERROR);
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable)

Example 4 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project intellij-community by JetBrains.

the class SvnAndProxyTest method setDefaultFixedProxySettings.

private static void setDefaultFixedProxySettings() {
    final HttpConfigurable h = HttpConfigurable.getInstance();
    h.USE_PROXY_PAC = false;
    h.USE_HTTP_PROXY = true;
    h.AUTHENTICATION_CANCELLED = false;
    // doesn't matter, only significant for serialization
    h.KEEP_PROXY_PASSWORD = false;
    h.LAST_ERROR = null;
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable)

Example 5 with HttpConfigurable

use of com.intellij.util.net.HttpConfigurable in project android by JetBrains.

the class GradleSyncTest method withIdeProxySettings.

// Verifies that the IDE, during sync, asks the user to copy IDE proxy settings to gradle.properties, if applicable.
// See https://code.google.com/p/android/issues/detail?id=65325
@Test
public void withIdeProxySettings() throws IOException {
    System.getProperties().setProperty("show.do.not.copy.http.proxy.settings.to.gradle", "true");
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    File gradlePropertiesPath = new File(ideFrame.getProjectPath(), "gradle.properties");
    createIfNotExists(gradlePropertiesPath);
    String host = "myproxy.test.com";
    int port = 443;
    HttpConfigurable ideSettings = HttpConfigurable.getInstance();
    ideSettings.USE_HTTP_PROXY = true;
    ideSettings.PROXY_HOST = host;
    ideSettings.PROXY_PORT = port;
    ideFrame.requestProjectSync();
    // Expect IDE to ask user to copy proxy settings.
    ProxySettingsDialogFixture proxyDialog = ProxySettingsDialogFixture.find(guiTest.robot());
    proxyDialog.setDoNotShowThisDialog(true);
    proxyDialog.clickOk();
    ideFrame.waitForGradleProjectSyncToStart().waitForGradleProjectSyncToFinish();
    // Verify gradle.properties has proxy settings.
    assertAbout(file()).that(gradlePropertiesPath).isFile();
    Properties gradleProperties = getProperties(gradlePropertiesPath);
    assertEquals(host, gradleProperties.getProperty("systemProp.http.proxyHost"));
    assertEquals(String.valueOf(port), gradleProperties.getProperty("systemProp.http.proxyPort"));
    // Verifies that the "Do not show this dialog in the future" does not show up. If it does show up the test will timeout and fail.
    ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) Properties(java.util.Properties) PropertiesFiles.getProperties(com.android.tools.idea.gradle.util.PropertiesFiles.getProperties) GradleProperties(com.android.tools.idea.gradle.util.GradleProperties) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) Test(org.junit.Test)

Aggregations

HttpConfigurable (com.intellij.util.net.HttpConfigurable)15 GradleProperties (com.android.tools.idea.gradle.util.GradleProperties)3 NotNull (org.jetbrains.annotations.NotNull)3 Test (org.junit.Test)3 ProxySettings (com.android.tools.idea.gradle.util.ProxySettings)2 ProxySettingsDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ProxySettingsDialogFixture)2 File (java.io.File)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)1 ProxySettingsDialog (com.android.tools.idea.gradle.project.ProxySettingsDialog)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 LocalProperties (com.android.tools.idea.gradle.util.LocalProperties)1 PropertiesFiles.getProperties (com.android.tools.idea.gradle.util.PropertiesFiles.getProperties)1 Pair (com.intellij.openapi.util.Pair)1 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ConfirmingTrustManager (com.intellij.util.net.ssl.ConfirmingTrustManager)1 CommonProxy (com.intellij.util.proxy.CommonProxy)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1