Example usage for org.apache.commons.httpclient.auth CredentialsNotAvailableException CredentialsNotAvailableException

List of usage examples for org.apache.commons.httpclient.auth CredentialsNotAvailableException CredentialsNotAvailableException

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.auth CredentialsNotAvailableException CredentialsNotAvailableException.

Prototype

public CredentialsNotAvailableException(String paramString) 

Source Link

Usage

From source file:com.eviware.soapui.impl.wsdl.submit.filters.WsdlRequestCredentialsProvider.java

public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {
    if (checkedCredentials)
        throw new CredentialsNotAvailableException("Missing valid credentials");

    if (authscheme == null) {
        return null;
    }/*  w w  w .  j  a  va 2  s.c o  m*/
    try {
        String password = wsdlRequest.getPassword();
        if (password == null)
            password = "";

        if (authscheme instanceof NTLMScheme) {
            logger.info(host + ":" + port + " requires Windows authentication");
            return new NTCredentials(wsdlRequest.getUsername(), password, host, wsdlRequest.getDomain());
        } else if (authscheme instanceof RFC2617Scheme) {
            logger.info(host + ":" + port + " requires authentication with the realm '" + authscheme.getRealm()
                    + "'");
            return new UsernamePasswordCredentials(wsdlRequest.getUsername(), password);
        } else {
            throw new CredentialsNotAvailableException(
                    "Unsupported authentication scheme: " + authscheme.getSchemeName());
        }
    } catch (IOException e) {
        throw new CredentialsNotAvailableException(e.getMessage(), e);
    } finally {
        checkedCredentials = true;
    }
}

From source file:net.adamcin.httpsig.http.apache3.SignerCredentialsProvider.java

public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {

    if (Constants.SCHEME.equals(scheme.getSchemeName())) {
        if (signer == null) {
            throw new CredentialsNotAvailableException("SSHKey Signer not available");
        } else {/*w ww.  j a v a  2s  . c  o  m*/
            return new SignerCredentials(signer);
        }
    } else {
        if (this.delegatee != null) {
            return this.delegatee.getCredentials(scheme, host, port, proxy);
        }
    }
    return null;
}

From source file:com.globalsight.everest.webapp.applet.util.AuthenticationPrompter.java

/**
 * Returns the appropriate credentials for authentication. This method
 * may be called many times, but the username,password entered the first
 * time is re-used so the user is not prompted multiple times if the connection
 * isn't kept alive.//from   ww  w. j  a v  a  2  s  .  c  o m
 * 
 * @param authscheme
 * @param host
 * @param port
 * @param proxy
 * @return Credentials
 * @exception CredentialsNotAvailableException
 */
public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {
    if (authscheme == null) {
        System.out.println("----No Proxy Authentication Required.");
        return null;
    }
    try {
        if (authscheme instanceof NTLMScheme) {
            System.out.println("----" + host + ":" + port + " requires Windows authentication");
            if (m_askForAuth)
                askForAuthentication();
            return new NTCredentials(m_username, m_password, host, m_domain);
        } else if (authscheme instanceof RFC2617Scheme) {
            System.out.println("----" + host + ":" + port + " requires authentication with the realm '"
                    + authscheme.getRealm() + "'");
            if (m_askForAuth)
                askForAuthentication();
            return new UsernamePasswordCredentials(m_username, m_password);
        } else {
            throw new CredentialsNotAvailableException(
                    "Unsupported authentication scheme: " + authscheme.getSchemeName());
        }
    } catch (Exception e) {
        throw new CredentialsNotAvailableException(e.getMessage(), e);
    }
}

From source file:com.sun.jersey.client.apache.config.DefaultCredentialsProvider.java

public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {
    if (scheme == null) {
        return null;
    }//from w ww.ja  v  a 2s  .  c  o  m

    try {
        JTextField userField = new JTextField();
        JPasswordField passwordField = new JPasswordField();
        int response;

        if (scheme instanceof NTLMScheme) {
            JTextField domainField = new JTextField();
            Object[] msg = { host + ":" + port + " requires Windows authentication", "Domain", domainField,
                    "User Name", userField, "Password", passwordField };
            response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION);

            if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) {
                throw new CredentialsNotAvailableException("User cancled windows authentication.");
            }

            return new NTCredentials(userField.getText(), new String(passwordField.getPassword()), host,
                    domainField.getText());

        } else if (scheme instanceof RFC2617Scheme) {
            Object[] msg = {
                    host + ":" + port + " requires authentication with the realm '" + scheme.getRealm() + "'",
                    "User Name", userField, "Password", passwordField };

            response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION);

            if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) {
                throw new CredentialsNotAvailableException("User cancled windows authentication.");
            }

            return new UsernamePasswordCredentials(userField.getText(),
                    new String(passwordField.getPassword()));

        } else {

            throw new CredentialsNotAvailableException(
                    "Unsupported authentication scheme: " + scheme.getSchemeName());

        }
    } catch (IOException ioe) {

        throw new CredentialsNotAvailableException(ioe.getMessage(), ioe);

    }
}

From source file:br.org.acessobrasil.silvinha.vista.panels.PainelSenha.java

public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {
    if (authscheme == null) {
        return null;
    }// w ww  .  j  a  va 2 s  .  c o  m
    try {
        if (authscheme instanceof NTLMScheme) {
            this.getPassword();
            if (cancelAuth) {
                return null;
            }
            return new NTCredentials(this.user, this.password, host, host);
        } else if (authscheme instanceof RFC2617Scheme) {
            this.getPassword();
            if (cancelAuth) {
                return null;
            }
            return new UsernamePasswordCredentials(user, password);
        } else {
            throw new CredentialsNotAvailableException(
                    "Unsupported authentication scheme: " + authscheme.getSchemeName());
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new CredentialsNotAvailableException(e.getMessage(), e);
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

/**
 * Implementation method for the CredentialsProvider interface.
 * <p>//  w ww . j a  v  a 2s .  c o m
 * Based on sample code:
 * <a href="http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/InteractiveAuthenticationExample.java?view=markup">InteractiveAuthenticationExample</a>
 *
 */
public Credentials getCredentials(AuthScheme authscheme, String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {
    if (authscheme == null) {
        return null;
    }
    try {
        Credentials credentials = null;

        if (authscheme instanceof NTLMScheme) {
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html>Host <b>" + host + ":" + port + "</b> requires Windows authentication</html>", true);
            pwDialog.setVisible(true);
            if (pwDialog.getUser().length() > 0) {
                credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), host,
                        pwDialog.getDomain());
            }
            pwDialog.dispose();
        } else if (authscheme instanceof RFC2617Scheme) {
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html><center>Host <b>" + host + ":" + port + "</b>"
                            + " requires authentication for the realm:<br><b>" + authscheme.getRealm()
                            + "</b></center></html>",
                    false);
            pwDialog.setVisible(true);
            if (pwDialog.getUser().length() > 0) {
                credentials = new UsernamePasswordCredentials(pwDialog.getUser(), pwDialog.getPassword());
            }
            pwDialog.dispose();
        } else {
            throw new CredentialsNotAvailableException(
                    "Unsupported authentication scheme: " + authscheme.getSchemeName());
        }
        return credentials;
    } catch (IOException e) {
        throw new CredentialsNotAvailableException(e.getMessage(), e);
    }
}

From source file:org.jets3t.apps.synchronize.CommandLineCredentialsProvider.java

/**
 * Implementation method for the CredentialsProvider interface.
 * <p>//from w w  w . ja  v a 2s.  c  om
 * Based on sample code:  
 * <a href="http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/InteractiveAuthenticationExample.java?view=markup">InteractiveAuthenticationExample</a> 
 * 
 */
public Credentials getCredentials(AuthScheme authscheme, String host, int port, boolean proxy)
        throws CredentialsNotAvailableException {
    if (authscheme == null) {
        return null;
    }
    try {
        Credentials credentials = null;
        BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));

        if (authscheme instanceof NTLMScheme) {
            System.out.println("Proxy Authentication Required -- " + "Host " + host + ":" + port
                    + " requires Windows authentication");
            System.out.print("Username: ");
            String username = inputReader.readLine();
            System.out.print("Password: ");
            String password = inputReader.readLine();
            System.out.print("Domain: ");
            String domain = inputReader.readLine();

            credentials = new NTCredentials(username, password, host, domain);
        } else if (authscheme instanceof RFC2617Scheme) {
            System.out.println("Proxy Authentication Required -- " + "Host " + host + ":" + port
                    + " requires authentication for the realm: " + authscheme.getRealm());
            System.out.print("Username: ");
            String username = inputReader.readLine();
            System.out.print("Password: ");
            String password = inputReader.readLine();

            credentials = new UsernamePasswordCredentials(username, password);
        } else {
            throw new CredentialsNotAvailableException(
                    "Unsupported authentication scheme: " + authscheme.getSchemeName());
        }
        return credentials;
    } catch (IOException e) {
        throw new CredentialsNotAvailableException(e.getMessage(), e);
    }
}