Example usage for org.apache.http.auth Credentials getPassword

List of usage examples for org.apache.http.auth Credentials getPassword

Introduction

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

Prototype

String getPassword();

Source Link

Usage

From source file:org.apache.http.impl.auth.BasicScheme.java

/**
 * Returns a basic <tt>Authorization</tt> header value for the given
 * {@link Credentials} and charset.//w w w  . j  a  v a 2s  .  c om
 *
 * @param credentials The credentials to encode.
 * @param charset The charset to use for encoding the credentials
 *
 * @return a basic authorization header
 *
 * @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
 */
@Deprecated
public static Header authenticate(final Credentials credentials, final String charset, final boolean proxy) {
    Args.notNull(credentials, "Credentials");
    Args.notNull(charset, "charset");

    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.encodeBase64(EncodingUtils.getBytes(tmp.toString(), charset), false);

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (proxy) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}

From source file:org.callimachusproject.behaviours.SqlDatasourceSupport.java

private void registerConnectionDriver(String name, DriverConnectionPoolManager manager)
        throws SQLException, OpenRDFException, IOException {
    Exception cause = null;/*from   w  w w .  j  a va  2 s.  c om*/
    String url = this.getCalliJdbcUrl();
    List<String> classnames = new ArrayList<>(this.getCalliDriverClassName());
    ClassLoader cl = createClassLoader();
    for (String classname : classnames) {
        try {
            Object d = Class.forName(classname, true, cl).newInstance();
            if (!(d instanceof Driver)) {
                logger.error("{} is not a java.sql.Driver class", classname);
            }
            Driver driver = (Driver) d;
            if (driver.getClass().getClassLoader() == cl) {
                deregisterDriverOnReset(name, driver);
            }
            if (driver.acceptsURL(url)) {
                Config config = new Config();
                config.testOnBorrow = true;
                config.maxActive = intOrNeg(this.getCalliMaxActive());
                config.maxIdle = intOrNeg(this.getCalliMaxIdle());
                config.maxWait = intOrNeg(this.getCalliMaxWait());
                Properties props = new Properties();
                Credentials cred = getCredential(url);
                if (cred != null) {
                    props.setProperty("user", cred.getUserPrincipal().getName());
                    props.setProperty("password", cred.getPassword());
                }
                verifyDriver(url, driver, props);
                manager.registerDriver(name, driver, url, props, config, this.getCalliValidationQuery());
                return;
            }
        } catch (ClassNotFoundException e) {
            cause = e;
            logger.error("{} is not found in {}", classname, this.getCalliDriverJar());
        } catch (InstantiationException e) {
            cause = e;
            logger.error("Could not instaniate {}", classname);
        } catch (IllegalAccessException e) {
            cause = e;
            logger.error("Could not access {}", classname);
        } catch (Exception e) {
            cause = e;
            logger.error("Could not load driver {}", classname);
        }
    }
    reset();
    if (cause instanceof SQLException)
        throw (SQLException) cause;
    if (cause != null)
        throw new SQLException("Could not load driver " + classnames, cause);
    throw new SQLException("Could not load driver " + classnames);
}

From source file:test.com.xceptance.xlt.common.actions.LWSimpleURLTest.java

/**********************************************************************************
 * Check setting of credentials//from   w  ww . j ava2s  .c om
 * 
 * @throws IOException
 *********************************************************************************/
@Test
public void testCredentials_Set() throws IOException {
    final List<AbstractLightWeightPageAction> actions = mockIt(login, password, "URL", "{url}");
    final Credentials creds = actions.get(0).getWebClient().getCredentialsProvider()
            .getCredentials(AuthScope.ANY);

    Assert.assertEquals("Login does not match.", login, creds.getUserPrincipal().getName());
    Assert.assertEquals("Password does not match.", password, creds.getPassword());
}

From source file:test.com.xceptance.xlt.common.actions.SimpleURLTest.java

/**********************************************************************************
 * Check setting of credentials/*  w w  w.j av  a2s.c  o  m*/
 * 
 * @throws IOException
 *********************************************************************************/

@Test
public void testCredentials_Set() throws IOException {
    final List<AbstractHtmlPageAction> actions = mockIt(login, password, "URL", "{url}");
    final Credentials creds = actions.get(0).getWebClient().getCredentialsProvider()
            .getCredentials(AuthScope.ANY);

    Assert.assertEquals("Login does not match.", login, creds.getUserPrincipal().getName());
    Assert.assertEquals("Password does not match.", password, creds.getPassword());
}