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:no.norrs.projects.andronary.tasks.DictLookupTask.java

@Override
protected List<SearchResult> doInBackground(String... lookup) {
    try {//from w  w w  . j  av a 2  s.c  o m
        System.out.println(
                String.format("%s : %s : %s : %s : %s", lookup[0], lookup[1], lookup[2], lookup[3], lookup[4]));
        if (lookup[0] == null) {
            dl.showError(new Exception("Press menu and configure up webservice.."), null);
            return null;
        }
        UsernamePasswordCredentials creds = null;
        if (lookup[1] != null && lookup[2] != null) {
            creds = new UsernamePasswordCredentials(lookup[1], lookup[2]);
        }
        DictonaryParser dp = new DictonaryParser();
        return (List<SearchResult>) dp.lookup(
                Uri.parse(String.format("%s/lookup?word=%s&dict=%s", lookup[0], lookup[3].trim(), lookup[4])),
                creds);
    } catch (IOException ex) {
        Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JSONException ex) {
        Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex);
    } catch (URISyntaxException ex) {
        Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:main.java.com.surevine.rssimporter.connection.BuddycloudClient.java

public BuddycloudClient(String host, String username, String password) throws MalformedURLException {
    this.host = host;
    httpClient = new DefaultHttpClient();
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(new URL(host).getHost(), 443),
            new UsernamePasswordCredentials(username, password));
}

From source file:com.pm.myshop.controller.CardController.java

@RequestMapping(value = "/validatecard", method = RequestMethod.GET)
public @ResponseBody String authenticateCard(@RequestParam("cardNo") String cardNo,
        @RequestParam("balance") double balance, @RequestParam("cvv") String cvv) throws IOException {

    DefaultHttpClient httpClient = new DefaultHttpClient();

    String encCard = encryptCardNumber(cardNo);

    HttpGet getRequest = new HttpGet("http://localhost:8080/Team4_CardValidator/validate?cardNo=" + encCard
            + "&balance=" + balance + "&cvv=" + cvv);

    getRequest.addHeader(//  w  w  w .j  a v  a  2  s  . c  o  m
            BasicScheme.authenticate(new UsernamePasswordCredentials("admin", "admin"), "UTF-8", false));

    HttpResponse response = httpClient.execute(getRequest);

    if (response.getStatusLine().getStatusCode() != 200) {
        session.setAttribute("cardvalidation", "fail");
        return "fail";
    }

    BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
    String output;

    while ((output = br.readLine()) != null) {
        session.setAttribute("cardvalidation", output);
        return output;
    }

    httpClient.getConnectionManager().shutdown();

    session.setAttribute("cardvalidation", "fail");
    return "fail";
}

From source file:com.fredhopper.core.connector.index.upload.impl.RestTemplateProvider.java

public RestTemplate createTemplate(final String host, final Integer port, final String username,
        final String password) {
    Preconditions.checkArgument(StringUtils.isNotBlank(host));
    Preconditions.checkArgument(port != null);
    Preconditions.checkArgument(StringUtils.isNotBlank(username));
    Preconditions.checkArgument(StringUtils.isNotBlank(password));

    final AuthScope authscope = new AuthScope(host, port.intValue());
    final Credentials credentials = new UsernamePasswordCredentials(username, password);
    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(authscope, credentials);

    final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    final CloseableHttpClient httpClient = clientBuilder.build();

    final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(httpClient);

    return new RestTemplate(requestFactory);
}

From source file:org.dasein.security.joyent.BasicSchemeHttpAuth.java

public void addPreemptiveAuth(@Nonnull HttpRequest request) throws CloudException, InternalException {
    if (providerContext == null) {
        throw new CloudException("No context was defined for this request");
    }/*  ww w .  j a  v a2s.  com*/
    try {
        String username = new String(providerContext.getAccessPublic(), "utf-8");
        String password = new String(providerContext.getAccessPrivate(), "utf-8");
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
        request.addHeader(new BasicScheme().authenticate(creds, request));
    } catch (UnsupportedEncodingException e) {
        throw new InternalException(e);
    } catch (AuthenticationException e) {
        throw new InternalException(e);
    }
}

From source file:org.sonatype.nexus.repository.httpclient.UsernameAuthenticationConfig.java

@Override
public Credentials getCredentials() {
    return new UsernamePasswordCredentials(username, password);
}

From source file:jobhunter.api.infojobs.Client.java

public Client() {
    provider = new BasicCredentialsProvider();
    provider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
            new UsernamePasswordCredentials(clientId, privateKey));
}

From source file:com.muhardin.endy.training.ws.aplikasi.absen.rest.client.AbsenRestClient.java

public AbsenRestClient() {
    try {//from w  w w .  j a  v  a 2  s .com
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());

        CredentialsProvider provider = new BasicCredentialsProvider();
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("endy", "123");
        provider.setCredentials(AuthScope.ANY, credentials);
        HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider)
                .setSSLSocketFactory(sslsf).build();

        restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(client));
        restTemplate.setErrorHandler(new AbsenRestClientErrorHandler());
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) {
        Logger.getLogger(AbsenRestClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.janusgraph.diskstorage.es.rest.util.BasicAuthHttpClientConfigCallback.java

public BasicAuthHttpClientConfigCallback(final String realm, final String username, final String password) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(username),
            "HTTP Basic Authentication: username must be provided");
    Preconditions.checkArgument(StringUtils.isNotEmpty(password),
            "HTTP Basic Authentication: password must be provided");

    credentialsProvider = new BasicCredentialsProvider();

    final AuthScope authScope;
    if (StringUtils.isNotEmpty(realm)) {
        authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME);
    } else {// w ww . ja  va2  s .  c om
        authScope = AuthScope.ANY;
    }
    credentialsProvider.setCredentials(authScope, new UsernamePasswordCredentials(username, password));
}

From source file:com.openshift.internal.restclient.authorization.OpenShiftCredentialsProvider.java

@Override
public void visit(BasicAuthorizationStrategy strategy) {
    creds.put(IAuthorizationContext.AUTHSCHEME_BASIC.toLowerCase(),
            new UsernamePasswordCredentials(strategy.getUsername(), strategy.getPassword()));
    scheme = IAuthorizationContext.AUTHSCHEME_BASIC;
    token = strategy.getToken();/*from   w  w w  .  j a  v a 2 s.  c  o m*/
}