Search in sources :

Example 1 with AuthenticationException

use of org.netbeans.lib.cvsclient.connection.AuthenticationException in project intellij-community by JetBrains.

the class ExtConnection method check.

@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" })
private void check(ICvsCommandStopper stopper, String expectedResult) throws IOException, AuthenticationException {
    InputStreamWrapper streamWrapper = new InputStreamWrapper(myInputStream, stopper, new ReadWriteStatistics());
    try {
        StringBuilder buffer = new StringBuilder();
        while (true) {
            int i = streamWrapper.read();
            if (i == -1 || i == '\n' || i == ' ' || i == '\r')
                break;
            buffer.append((char) i);
        }
        String read = buffer.toString().trim();
        if (!expectedResult.equals(read)) {
            if (StringUtil.startsWithConcatenation(read, myUserName, "@", myHost)) {
                throw new AuthenticationException(CvsBundle.message("exception.text.ext.server.rejected.access"), null);
            } else {
                if (myErrorText.length() > 0) {
                    throw new AuthenticationException(myErrorText.toString(), null);
                } else {
                    throw new AuthenticationException(CvsBundle.message("exception.text.ext.cannot.establish.external.connection"), null);
                }
            }
        }
    } finally {
        streamWrapper.close();
    }
}
Also used : InputStreamWrapper(com.intellij.cvsSupport2.javacvsImpl.io.InputStreamWrapper) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) ReadWriteStatistics(com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics)

Example 2 with AuthenticationException

use of org.netbeans.lib.cvsclient.connection.AuthenticationException in project intellij-community by JetBrains.

the class CvsRootConfiguration method testConnection.

public void testConnection(Project project) throws AuthenticationException, IOException {
    final IConnection connection = createSettings().createConnection(new ReadWriteStatistics());
    final ErrorMessagesProcessor errorProcessor = new ErrorMessagesProcessor();
    final CvsExecutionEnvironment cvsExecutionEnvironment = new CvsExecutionEnvironment(errorProcessor, CvsExecutionEnvironment.DUMMY_STOPPER, errorProcessor, PostCvsActivity.DEAF, project);
    final CvsResult result = new CvsResultEx();
    try {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final GetModulesListOperation operation = new GetModulesListOperation(createSettings());
            final CvsRootProvider cvsRootProvider = operation.getCvsRootProvider();
            try {
                if (connection instanceof SelfTestingConnection) {
                    ((SelfTestingConnection) connection).test(CvsListenerWithProgress.createOnProgress());
                }
                operation.execute(cvsRootProvider, cvsExecutionEnvironment, connection, DummyProgressViewer.INSTANCE);
            } catch (ValidRequestsExpectedException ex) {
                result.addError(new CvsException(ex, cvsRootProvider.getCvsRootAsString()));
            } catch (CommandException ex) {
                result.addError(new CvsException(ex.getUnderlyingException(), cvsRootProvider.getCvsRootAsString()));
            } catch (ProcessCanceledException ex) {
                result.setIsCanceled();
            } catch (BugLog.BugException e) {
                LOG.error(e);
            } catch (Exception e) {
                result.addError(new CvsException(e, cvsRootProvider.getCvsRootAsString()));
            }
        }, CvsBundle.message("operation.name.test.connection"), true, null);
        if (result.isCanceled())
            throw new ProcessCanceledException();
        if (result.hasErrors()) {
            final VcsException vcsException = result.composeError();
            throw new AuthenticationException(vcsException.getLocalizedMessage(), vcsException.getCause());
        }
        final List<VcsException> errors = errorProcessor.getErrors();
        if (!errors.isEmpty()) {
            final VcsException firstError = errors.get(0);
            throw new AuthenticationException(firstError.getLocalizedMessage(), firstError);
        }
    } finally {
        connection.close();
    }
}
Also used : AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) CvsException(com.intellij.cvsSupport2.errorHandling.CvsException) IConnection(org.netbeans.lib.cvsclient.connection.IConnection) CommandException(org.netbeans.lib.cvsclient.command.CommandException) ValidRequestsExpectedException(org.netbeans.lib.cvsclient.ValidRequestsExpectedException) ErrorMessagesProcessor(com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorMessagesProcessor) CvsResult(com.intellij.openapi.cvsIntegration.CvsResult) ValidRequestsExpectedException(org.netbeans.lib.cvsclient.ValidRequestsExpectedException) CvsException(com.intellij.cvsSupport2.errorHandling.CvsException) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VcsException(com.intellij.openapi.vcs.VcsException) CommandException(org.netbeans.lib.cvsclient.command.CommandException) IOException(java.io.IOException) BugLog(org.netbeans.lib.cvsclient.util.BugLog) CvsExecutionEnvironment(com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment) GetModulesListOperation(com.intellij.cvsSupport2.cvsoperations.cvsContent.GetModulesListOperation) VcsException(com.intellij.openapi.vcs.VcsException) CvsResultEx(com.intellij.cvsSupport2.CvsResultEx) ReadWriteStatistics(com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 3 with AuthenticationException

use of org.netbeans.lib.cvsclient.connection.AuthenticationException in project intellij-community by JetBrains.

the class CvsCommandOperation method execute.

public void execute(final CvsRootProvider root, final CvsExecutionEnvironment executionEnvironment, IConnection connection, IProgressViewer progressViewer) throws CommandException {
    final Command command = createCommand(root, executionEnvironment);
    if (command == null)
        return;
    LOG.assertTrue(connection != null, root.getCvsRootAsString());
    final CvsMessagesListener cvsMessagesListener = executionEnvironment.getCvsMessagesListener();
    final long start = System.currentTimeMillis();
    try {
        final IClientEnvironment clientEnvironment = createEnvironment(connection, root, myUpdatedFilesManager, executionEnvironment);
        myUpdatedFilesManager.setCvsFileSystem(clientEnvironment.getCvsFileSystem());
        final EventManager eventManager = new EventManager(CvsApplicationLevelConfiguration.getCharset());
        final IGlobalOptions globalOptions = command.getGlobalOptions();
        final IRequestProcessor requestProcessor = new RequestProcessor(clientEnvironment, globalOptions, eventManager, new StreamLogger(), executionEnvironment.getCvsCommandStopper(), PServerCvsSettings.getTimeoutMillis());
        eventManager.addFileInfoListener(this);
        eventManager.addEntryListener(this);
        eventManager.addMessageListener(this);
        eventManager.addModuleExpansionListener(this);
        final CvsMessagesTranslator cvsMessagesTranslator = new CvsMessagesTranslator(cvsMessagesListener, clientEnvironment.getCvsFileSystem(), myUpdatedFilesManager, root.getCvsRootAsString());
        cvsMessagesTranslator.registerTo(eventManager);
        final CvsEntriesManager cvsEntriesManager = CvsEntriesManager.getInstance();
        if (shouldMakeChangesOnTheLocalFileSystem()) {
            eventManager.addEntryListener(new MergeSupportingEntryListener(clientEnvironment, cvsEntriesManager, myUpdatedFilesManager));
            eventManager.addMessageListener(myUpdatedFilesManager);
        }
        modifyOptions(command.getGlobalOptions());
        final String commandString = composeCommandString(root, command);
        cvsMessagesListener.commandStarted(commandString);
        setProgressText(CvsBundle.message("progress.text.command.running.for.file", getOperationName(), root.getCvsRootAsString()));
        try {
            command.execute(requestProcessor, eventManager, eventManager, clientEnvironment, progressViewer);
        } catch (AuthenticationException e) {
            throw root.processException(new CommandException(e, "Authentication problem"));
        }
        cvsMessagesTranslator.operationCompleted();
    } catch (CommandException t) {
        throw root.processException(t);
    } finally {
        cvsMessagesListener.commandFinished(composeCommandString(root, command), System.currentTimeMillis() - start);
        executeFinishActions();
    }
}
Also used : IRequestProcessor(org.netbeans.lib.cvsclient.IRequestProcessor) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) IgnoreFileFilterBasedOnCvsEntriesManager(com.intellij.cvsSupport2.cvsIgnore.IgnoreFileFilterBasedOnCvsEntriesManager) CvsEntriesManager(com.intellij.cvsSupport2.application.CvsEntriesManager) CvsMessagesTranslator(com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesTranslator) IClientEnvironment(org.netbeans.lib.cvsclient.IClientEnvironment) CvsMessagesListener(com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesListener) RequestProcessor(org.netbeans.lib.cvsclient.RequestProcessor) IRequestProcessor(org.netbeans.lib.cvsclient.IRequestProcessor)

Example 4 with AuthenticationException

use of org.netbeans.lib.cvsclient.connection.AuthenticationException in project intellij-community by JetBrains.

the class ConnectionOnProcess method execute.

protected synchronized void execute(GeneralCommandLine commandLine) throws AuthenticationException {
    try {
        commandLine.withParentEnvironmentType(ParentEnvironmentType.CONSOLE);
        myProcess = commandLine.createProcess();
        myErrThread = new ReadProcessThread(new BufferedReader(new InputStreamReader(myProcess.getErrorStream(), EncodingManager.getInstance().getDefaultCharset()))) {

            protected void textAvailable(String s) {
                myErrorText.append(s);
                myErrorRegistry.registerError(s);
                myContainsError = true;
            }
        };
        final Application application = ApplicationManager.getApplication();
        myStdErrFuture = application.executeOnPooledThread(myErrThread);
        myInputStream = myProcess.getInputStream();
        myOutputStream = myProcess.getOutputStream();
        waitForProcess(application);
    } catch (Exception e) {
        closeInternal();
        throw new AuthenticationException(e.getLocalizedMessage(), e);
    }
}
Also used : AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) Application(com.intellij.openapi.application.Application) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with AuthenticationException

use of org.netbeans.lib.cvsclient.connection.AuthenticationException in project intellij-community by JetBrains.

the class LocalConnection method verifyServerCapability.

private void verifyServerCapability() throws AuthenticationException {
    final GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(myLocalSettings.PATH_TO_CVS_CLIENT);
    commandLine.addParameter("-v");
    execute(commandLine);
    try {
        StringBuilder responseBuilder = new StringBuilder();
        while (true) {
            int c = myInputStream.read();
            if (c == -1) {
                break;
            }
            responseBuilder.append((char) c);
        }
        String[] lines = responseBuilder.toString().split("\n");
        for (String line : lines) {
            // check that the first non-empty line does not end with (client)
            if (line.trim().endsWith("(client)")) {
                throw new AuthenticationException("CVS client does not support server mode operation", null);
            }
            if (line.trim().length() > 0) {
                break;
            }
        }
    } catch (IOException e) {
        throw new AuthenticationException("Can't read CVS version", e);
    }
    closeInternal();
}
Also used : AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) IOException(java.io.IOException)

Aggregations

AuthenticationException (org.netbeans.lib.cvsclient.connection.AuthenticationException)6 IOException (java.io.IOException)3 ReadWriteStatistics (com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics)2 CvsResultEx (com.intellij.cvsSupport2.CvsResultEx)1 CvsEntriesManager (com.intellij.cvsSupport2.application.CvsEntriesManager)1 IgnoreFileFilterBasedOnCvsEntriesManager (com.intellij.cvsSupport2.cvsIgnore.IgnoreFileFilterBasedOnCvsEntriesManager)1 CvsExecutionEnvironment (com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment)1 GetModulesListOperation (com.intellij.cvsSupport2.cvsoperations.cvsContent.GetModulesListOperation)1 ErrorMessagesProcessor (com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorMessagesProcessor)1 CvsMessagesListener (com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesListener)1 CvsMessagesTranslator (com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesTranslator)1 CvsException (com.intellij.cvsSupport2.errorHandling.CvsException)1 InputStreamWrapper (com.intellij.cvsSupport2.javacvsImpl.io.InputStreamWrapper)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 Application (com.intellij.openapi.application.Application)1 CvsResult (com.intellij.openapi.cvsIntegration.CvsResult)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 VcsException (com.intellij.openapi.vcs.VcsException)1 InteractiveCallback (com.trilead.ssh2.InteractiveCallback)1 ExecutionException (java.util.concurrent.ExecutionException)1