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

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

Introduction

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

Prototype

public UsernamePasswordCredentials(final String userName, final String password) 

Source Link

Document

The constructor with the username and password arguments.

Usage

From source file:jetbrains.buildServer.commitPublisher.github.api.impl.GitHubApiFactoryImpl.java

@NotNull
public GitHubApi openGitHubForUser(@NotNull final String url, @NotNull final String username,
        @NotNull final String password) {
    return new GitHubApiImpl(myWrapper, new GitHubApiPaths(url)) {
        @Override//from  ww w .j  a v a 2 s .  c  o  m
        protected void setAuthentication(@NotNull HttpRequest request) throws AuthenticationException {
            request.addHeader(new BasicScheme()
                    .authenticate(new UsernamePasswordCredentials(username, password), request));
        }
    };
}

From source file:se.vgregion.pubsub.twitter.impl.PreemptiveBasicAuth.java

public void process(HttpRequest request, HttpContext context) {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);

    // If not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        Credentials creds = new UsernamePasswordCredentials(username, password);
        authState.setAuthScheme(new BasicScheme());
        authState.setCredentials(creds);
    }/*from   w  ww .ja  v a2 s. c  om*/
}

From source file:org.apache.ambari.view.hive.client.HttpBasicAuthInterceptor.java

public HttpBasicAuthInterceptor(String username, String password, CookieStore cookieStore, String cn,
        boolean isSSL, Map<String, String> additionalHeaders) {
    super(cookieStore, cn, isSSL, additionalHeaders);
    this.authScheme = new BasicScheme();
    if (username != null) {
        this.credentials = new UsernamePasswordCredentials(username, password);
    }/* www.  j av a2 s .  c o  m*/
}

From source file:org.commonjava.util.jhttpc.auth.BasicAuthenticator.java

@Override
public HttpClientContext decoratePrototypeContext(final AuthScope scope, SiteConfig location, PasswordType type,
        HttpClientContext ctx) {//from   w ww.jav a 2 s  . co  m
    CredentialsProvider creds = ctx.getCredentialsProvider();
    if (creds == null || !(creds instanceof BasicCredentialsProvider)) {
        creds = new BasicCredentialsProvider();
        ctx.setCredentialsProvider(creds);
    }

    if (PasswordType.USER == type) {
        final String password = passwords.lookup(new PasswordKey(location, PasswordType.USER));
        creds.setCredentials(scope, new UsernamePasswordCredentials(location.getUser(), password));
    } else if (PasswordType.PROXY == type) {
        final String password = passwords.lookup(new PasswordKey(location, PasswordType.PROXY));
        creds.setCredentials(scope, new UsernamePasswordCredentials(location.getProxyUser(), password));
    }

    return ctx;
}

From source file:org.piraso.client.net.HttpBasicAuthentication.java

public void authenticate() {
    validate();/*  w  ww  .  j ava2 s . c om*/

    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password);

    httpClient.getCredentialsProvider()
            .setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials);

    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();

    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);

    context.setAttribute(ClientContext.AUTH_CACHE, authCache);
}

From source file:lyrics.crawler.webClient.ContentDownloader.java

public void setupProxyWithCredentials(String proxyHostname, int proxyPort, String username, String password) {
    setupProxy(proxyHostname, proxyPort);

    client.getCredentialsProvider().setCredentials(new AuthScope(proxyHostname, proxyPort),
            new UsernamePasswordCredentials(username, password));
}

From source file:org.apache.jena.jdbc.remote.results.TestRemoteEndpointResultsWithAuth.java

/**
 * Setup for the tests by allocating a Fuseki instance to work with
 * /* w  ww .j  a v a  2s . com*/
 * @throws SQLException
 * @throws IOException
 */
@BeforeClass
public static void setup() throws SQLException, IOException {
    SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD);
    FusekiTestAuth.setupServer(true, sh);

    BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
    credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, PASSWORD));
    client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();

    connection = new RemoteEndpointConnection(FusekiTestAuth.serviceQuery(), FusekiTestAuth.serviceUpdate(),
            null, null, null, null, client, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null,
            null);
    connection.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
}

From source file:com.asakusafw.shafu.internal.core.net.ShafuCredentialsProvider.java

@Override
public Credentials getCredentials(AuthScope authscope) {
    String host = authscope.getHost();
    if (host != AuthScope.ANY_HOST) {
        Scope scope = new Scope(authscope.getScheme(), host, authscope.getPort(), authscope.getRealm());
        for (IHttpCredentialsProvider provider : Activator.getExtensions().createHttpCredentialsProvider()) {
            try {
                IHttpCredentials creds = provider.find(scope);
                if (creds != null) {
                    return new UsernamePasswordCredentials(creds.getUserName(), creds.getPassword());
                }/*from w ww.j av a2  s .c o  m*/
            } catch (CoreException e) {
                LogUtil.log(e.getStatus());
            }
        }
    }
    return super.getCredentials(authscope);
}

From source file:org.datacleaner.util.http.HttpBasicMonitorHttpClient.java

public HttpBasicMonitorHttpClient(HttpClient httpClient, String hostname, int port, String username,
        String password) {//from w ww  .  ja  v a 2 s.c  o  m
    _httpClient = (DefaultHttpClient) httpClient;

    final CredentialsProvider credentialsProvider = _httpClient.getCredentialsProvider();

    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

    final List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    authpref.add(AuthPolicy.DIGEST);
    _httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);

    credentialsProvider.setCredentials(new AuthScope(hostname, port), credentials);
}

From source file:com.rastating.droidbeard.net.HttpClientManager.java

private void setupHttpCredentials() {
    try {/*www.j a  v a  2  s  .  co  m*/
        Preferences preferences = new Preferences(Application.getContext());
        Credentials credentials = new UsernamePasswordCredentials(preferences.getHttpUsername(),
                preferences.getHttpPassword());
        ((AbstractHttpClient) mClient).getCredentialsProvider()
                .setCredentials(new AuthScope(preferences.getAddress(), preferences.getPort()), credentials);
    } catch (Exception e) {
        e.printStackTrace();
    }
}