Package org.netbeans.lib.cvsclient.connection

Examples of org.netbeans.lib.cvsclient.connection.AuthenticationException


            connection.connect();
        }
        catch ( IOException e )
        {
            String message = "Cannot connect. Reason: " + e.getMessage();
            throw new AuthenticationException( message, e, message );
        }

        File privateKey = getPrivateKey();

        try
        {
            boolean authenticated;
            if ( privateKey != null && privateKey.exists() )
            {
                authenticated = connection.authenticateWithPublicKey( userName, privateKey, getPassphrase() );
            }
            else
            {
                authenticated = connection.authenticateWithPassword( userName, password );
            }

            if ( !authenticated )
            {
                String message = "Authentication failed.";
                throw new AuthenticationException( message, message );
            }
        }
        catch ( IOException e )
        {
            closeConnection();
            String message = "Cannot authenticate. Reason: " + e.getMessage();
            throw new AuthenticationException( message, e, message );
        }

        try
        {
            session = connection.openSession();
View Full Code Here


            close();
        }
        catch ( Exception e )
        {
            String message = "Failed to verify the connection: " + e.getMessage();
            throw new AuthenticationException( message, e, message );
        }
    }
View Full Code Here

            connection.connect();
        }
        catch ( IOException e )
        {
            String message = "Cannot connect. Reason: " + e.getMessage();
            throw new AuthenticationException( message, e, message );
        }

        File privateKey = getPrivateKey();

        try
        {
            boolean authenticated;
            if ( privateKey != null && privateKey.exists() )
            {
                authenticated = connection.authenticateWithPublicKey( userName, privateKey, getPassphrase() );
            }
            else
            {
                authenticated = connection.authenticateWithPassword( userName, password );
            }

            if ( !authenticated )
            {
                String message = "Authentication failed.";
                throw new AuthenticationException( message, message );
            }
        }
        catch ( IOException e )
        {
            closeConnection();
            String message = "Cannot authenticate. Reason: " + e.getMessage();
            throw new AuthenticationException( message, e, message );
        }

        try
        {
            session = connection.openSession();
View Full Code Here

            close();
        }
        catch ( Exception e )
        {
            String message = "Failed to verify the connection: " + e.getMessage();
            throw new AuthenticationException( message, e, message );
        }
    }
View Full Code Here

     */
    private void openConnection(String preamble, String postamble)
            throws AuthenticationException, CommandAbortedException {
        if (hostName == null) {
            String locMessage = "The hostname was null, can't continue."; //NOI18N
            throw new AuthenticationException("HostIsNull", locMessage); //NOI18N
        }

        try {
            SocketFactory sf = (socketFactory != null) ? socketFactory : SocketFactory.getDefault();
            socket = sf.createSocket(hostName, port);

            BufferedOutputStream bos =
                    new BufferedOutputStream(socket.getOutputStream(), 32768);
            LoggedDataOutputStream outputStream = new LoggedDataOutputStream(bos);
            setOutputStream(outputStream);

            BufferedInputStream bis =
                    new BufferedInputStream(socket.getInputStream(), 32768);
            LoggedDataInputStream inputStream = new LoggedDataInputStream(bis);
            setInputStream(inputStream);
     
            outputStream.writeBytes(preamble, "US-ASCII");
            outputStream.writeBytes(getRepository() + "\n"); //NOI18N
            outputStream.writeBytes(userName + "\n"); //NOI18N
            outputStream.writeBytes(getEncodedPasswordNotNull() + "\n", "US-ASCII"); //NOI18N
            outputStream.writeBytes(postamble, "US-ASCII");
            outputStream.flush();

            if (Thread.interrupted()) {
                reset();
                String localMsg = CommandException.getLocalMessage("Client.connectionAborted", null); //NOI18N
                throw new CommandAbortedException("Aborted during connecting to the server.", localMsg); // NOI18N
            }

            // read first 11 bytes only (AUTHENTICATION_SUCCEEDED_RESPONSE\n)
            // I observed lock caused by missing '\n' in reponse
            // this method then blocks forever
            byte rawResponse[] = inputStream.readBytes(AUTHENTICATION_SUCCEEDED_RESPONSE_RAW.length());
            String response = new String(rawResponse, "utf8")// NOI18N

            if (Thread.interrupted()) {
                reset();
                String localMsg = CommandException.getLocalMessage("Client.connectionAborted", null); //NOI18N
                throw new CommandAbortedException("Aborted during connecting to the server.", localMsg); // NOI18N
            }

            if (AUTHENTICATION_SUCCEEDED_RESPONSE_RAW.equals(response)) {
                return;
            }

            if (AUTHENTICATION_FAILED_RESPONSE_RAW.equals(response)) {
                String localizedMsg = getLocalMessage("AuthenticationException.badPassword",
                                                      null);
                throw new AuthenticationException("AuthenticationFailed", //NOI18N
                                                  localizedMsg);
            }

            if (response == null) response = ""; // NOI18N
            String locMessage = getLocalMessage("AuthenticationException.AuthenticationFailed", //NOI18N
                                                new Object[]{ response });
            throw new AuthenticationException("AuthenticationFailed", //NOI18N
                                              locMessage);
        }
        catch (AuthenticationException ex) {
            reset();
            throw ex;
        }
        catch (ConnectException ex) {
            reset();
            String locMessage =
                    getLocalMessage("AuthenticationException.ConnectException", //NOI18N
                                    new Object[]{hostName, Integer.toString(port)});
            throw new AuthenticationException("ConnectException", ex, //NOI18N
                                              locMessage);
        }
        catch (NoRouteToHostException ex) {
            reset();
            String locMessage =
                    getLocalMessage("AuthenticationException.NoRouteToHostException", //NOI18N
                                    new Object[]{hostName});
            throw new AuthenticationException("NoRouteToHostException", ex, //NOI18N
                                              locMessage);
        }
        catch (IOException ex) {
            reset();
            String locMessage =
                    getLocalMessage("AuthenticationException.IOException", //NOI18N
                                    new Object[]{hostName});
            throw new AuthenticationException("IOException", ex, locMessage); //NOI18N
        }
/*        catch (Throwable t) {
            reset();
            String locMessage = AuthenticationException.getBundleString(
                    "AuthenticationException.Throwable"); //NOI18N
View Full Code Here

        try {
            socket.close();
        }
        catch (IOException exc) {
            String locMessage = "An IO Exception occured when verifying: " + exc.getMessage(); //NOI18N
            throw new AuthenticationException("General error", exc, locMessage); //NOI18N
        }
        finally {
            reset();
        }
    }
View Full Code Here

TOP

Related Classes of org.netbeans.lib.cvsclient.connection.AuthenticationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.