Example usage for org.apache.http.auth InvalidCredentialsException InvalidCredentialsException

List of usage examples for org.apache.http.auth InvalidCredentialsException InvalidCredentialsException

Introduction

In this page you can find the example usage for org.apache.http.auth InvalidCredentialsException InvalidCredentialsException.

Prototype

public InvalidCredentialsException(final String message) 

Source Link

Document

Creates a new InvalidCredentialsException with the specified message.

Usage

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Implementation method for the CredentialsProvider interface.
 * <p>/*from ww w . ja v  a 2s  .  co 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(AuthScope scope) {
    if (scope == null || scope.getScheme() == null) {
        return null;
    }
    Credentials credentials = mCredentialProvider.getCredentials(scope);
    if (credentials != null) {
        return credentials;
    }
    try {
        if (scope.getScheme().equals("ntlm")) {
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html>Host <b>" + scope.getHost() + ":" + scope.getPort()
                            + "</b> requires Windows authentication</html>",
                    true);
            pwDialog.setVisible(true);
            if (pwDialog.getUser().length() > 0) {
                credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), scope.getHost(),
                        pwDialog.getDomain());
            }
            pwDialog.dispose();
        } else if (scope.getScheme().equals("basic") || scope.getScheme().equals("digest")) {
            //authscheme instanceof RFC2617Scheme
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html><center>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b>"
                            + " requires authentication for the realm:<br><b>" + scope.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 InvalidCredentialsException("Unsupported authentication scheme: " + scope.getScheme());
        }
        if (credentials != null) {
            mCredentialProvider.setCredentials(scope, credentials);
        }
        return credentials;
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}