Search in sources :

Example 1 with SVNAuthentication

use of org.tmatesoft.svn.core.auth.SVNAuthentication 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 2 with SVNAuthentication

use of org.tmatesoft.svn.core.auth.SVNAuthentication in project intellij-community by JetBrains.

the class AuthenticationService method requestCredentials.

@Nullable
public SVNAuthentication requestCredentials(final SVNURL repositoryUrl, final String type) {
    SVNAuthentication authentication = null;
    if (repositoryUrl != null) {
        final String realm = repositoryUrl.toDecodedString();
        authentication = requestCredentials(realm, type, () -> myConfiguration.getInteractiveManager(myVcs).getInnerProvider().requestClientAuthentication(type, repositoryUrl, realm, null, null, true));
    }
    if (authentication == null) {
        LOG.warn("Could not get authentication. Type - " + type + ", Url - " + repositoryUrl);
    }
    return authentication;
}
Also used : SVNAuthentication(org.tmatesoft.svn.core.auth.SVNAuthentication) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with SVNAuthentication

use of org.tmatesoft.svn.core.auth.SVNAuthentication in project intellij-community by JetBrains.

the class SvnConfiguration method getPassiveAuthenticationManager.

public SvnAuthenticationManager getPassiveAuthenticationManager(@NotNull SvnVcs svnVcs) {
    if (myPassiveAuthManager == null) {
        myPassiveAuthManager = new SvnAuthenticationManager(svnVcs, new File(getConfigurationDirectory()));
        myPassiveAuthManager.setAuthenticationProvider(new ISVNAuthenticationProvider() {

            @Override
            public SVNAuthentication requestClientAuthentication(String kind, SVNURL url, String realm, SVNErrorMessage errorMessage, SVNAuthentication previousAuth, boolean authMayBeStored) {
                return null;
            }

            @Override
            public int acceptServerAuthentication(SVNURL url, String realm, Object certificate, boolean resultMayBeStored) {
                return REJECTED;
            }
        });
        myPassiveAuthManager.setRuntimeStorage(RUNTIME_AUTH_CACHE);
    }
    return myPassiveAuthManager;
}
Also used : SvnAuthenticationManager(org.jetbrains.idea.svn.auth.SvnAuthenticationManager) SVNURL(org.tmatesoft.svn.core.SVNURL) SVNConfigFile(org.tmatesoft.svn.core.internal.wc.SVNConfigFile) File(java.io.File) ISVNAuthenticationProvider(org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider) SVNErrorMessage(org.tmatesoft.svn.core.SVNErrorMessage) SVNAuthentication(org.tmatesoft.svn.core.auth.SVNAuthentication)

Aggregations

SVNAuthentication (org.tmatesoft.svn.core.auth.SVNAuthentication)3 HttpConfigurable (com.intellij.util.net.HttpConfigurable)1 CommonProxy (com.intellij.util.proxy.CommonProxy)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1 SvnAuthenticationManager (org.jetbrains.idea.svn.auth.SvnAuthenticationManager)1 SVNAuthenticationException (org.tmatesoft.svn.core.SVNAuthenticationException)1 SVNCancelException (org.tmatesoft.svn.core.SVNCancelException)1 SVNErrorMessage (org.tmatesoft.svn.core.SVNErrorMessage)1 SVNException (org.tmatesoft.svn.core.SVNException)1 SVNURL (org.tmatesoft.svn.core.SVNURL)1 ISVNAuthenticationProvider (org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider)1 SVNConfigFile (org.tmatesoft.svn.core.internal.wc.SVNConfigFile)1