Search in sources :

Example 1 with SVNAuthenticationException

use of org.tmatesoft.svn.core.SVNAuthenticationException 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 SVNAuthenticationException

use of org.tmatesoft.svn.core.SVNAuthenticationException in project omegat by omegat-org.

the class SVNRemoteRepository2 method isSVNRepository.

/**
 * Determines whether or not the supplied URL represents a valid Subversion repository.
 *
 * <p>
 * Does the equivalent of <code>svn info <i>url</i></code>.
 *
 * @param url
 *            URL of supposed remote repository
 * @return true if repository appears to be valid, false otherwise
 */
public static boolean isSVNRepository(String url) {
    // Heuristics to save some waiting time
    try {
        ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
        SVNClientManager ourClientManager = SVNClientManager.newInstance(options, (ISVNAuthenticationManager) null);
        ourClientManager.getWCClient().doInfo(SVNURL.parseURIEncoded(SVNEncodingUtil.autoURIEncode(url)), SVNRevision.HEAD, SVNRevision.HEAD);
    } catch (SVNAuthenticationException ex) {
        // https://twitter.com/amadlonkay/status/699716236372889600
        return true;
    } catch (SVNException ex) {
        return false;
    }
    return true;
}
Also used : ISVNOptions(org.tmatesoft.svn.core.wc.ISVNOptions) SVNAuthenticationException(org.tmatesoft.svn.core.SVNAuthenticationException) SVNException(org.tmatesoft.svn.core.SVNException) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager)

Example 3 with SVNAuthenticationException

use of org.tmatesoft.svn.core.SVNAuthenticationException in project sonarqube by SonarSource.

the class SvnBlameCommand method blame.

@VisibleForTesting
void blame(SVNClientManager clientManager, InputFile inputFile, BlameOutput output) {
    String filename = inputFile.relativePath();
    LOG.debug("Process file {}", filename);
    AnnotationHandler handler = new AnnotationHandler();
    try {
        if (!checkStatus(clientManager, inputFile)) {
            return;
        }
        SVNLogClient logClient = clientManager.getLogClient();
        logClient.setDiffOptions(new SVNDiffOptions(true, true, true));
        logClient.doAnnotate(inputFile.file(), SVNRevision.UNDEFINED, SVNRevision.create(1), SVNRevision.BASE, true, true, handler, null);
    } catch (SVNAuthenticationException e) {
        if (configuration.isEmpty()) {
            LOG.warn("Authentication to SVN server is required but no authentication data was passed to the scanner");
        }
        throw new IllegalStateException("Authentication error when executing blame for file " + filename, e);
    } catch (SVNException e) {
        throw new IllegalStateException("Error when executing blame for file " + filename, e);
    }
    List<BlameLine> lines = handler.getLines();
    if (lines.size() == inputFile.lines() - 1) {
        // SONARPLUGINS-3097 SVN do not report blame on last empty line
        lines.add(lines.get(lines.size() - 1));
    }
    output.blameResult(inputFile, lines);
}
Also used : BlameLine(org.sonar.api.batch.scm.BlameLine) SVNAuthenticationException(org.tmatesoft.svn.core.SVNAuthenticationException) SVNDiffOptions(org.tmatesoft.svn.core.wc.SVNDiffOptions) SVNException(org.tmatesoft.svn.core.SVNException) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

SVNAuthenticationException (org.tmatesoft.svn.core.SVNAuthenticationException)3 SVNException (org.tmatesoft.svn.core.SVNException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HttpConfigurable (com.intellij.util.net.HttpConfigurable)1 CommonProxy (com.intellij.util.proxy.CommonProxy)1 BlameLine (org.sonar.api.batch.scm.BlameLine)1 SVNCancelException (org.tmatesoft.svn.core.SVNCancelException)1 SVNAuthentication (org.tmatesoft.svn.core.auth.SVNAuthentication)1 ISVNOptions (org.tmatesoft.svn.core.wc.ISVNOptions)1 SVNClientManager (org.tmatesoft.svn.core.wc.SVNClientManager)1 SVNDiffOptions (org.tmatesoft.svn.core.wc.SVNDiffOptions)1 SVNLogClient (org.tmatesoft.svn.core.wc.SVNLogClient)1