List of usage examples for org.apache.http.auth UsernamePasswordCredentials UsernamePasswordCredentials
public UsernamePasswordCredentials(final String userName, final String password)
From source file:org.mule.jenkins.Helper.java
public void setClientInfo() { client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); BasicScheme basicAuth = new BasicScheme(); context.setAttribute("preemptive-auth", basicAuth); client.addRequestInterceptor(new PreemptiveAuth(), 0); }
From source file:com.appdynamics.monitors.pingdom.communicator.PingdomCommunicator.java
@SuppressWarnings("rawtypes") private void getCredits(Map<String, Integer> metrics) { try {/*from w w w . ja v a2 s. c o m*/ HttpClient httpclient = new DefaultHttpClient(); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); HttpGet httpget = new HttpGet(baseAddress + "/api/2.0/credits"); httpget.addHeader(BasicScheme.authenticate(creds, "US-ASCII", false)); httpget.addHeader("App-Key", appkey); HttpResponse response; response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); // reading in the JSON response String result = ""; if (entity != null) { InputStream instream = entity.getContent(); int b; try { while ((b = instream.read()) != -1) { result += Character.toString((char) b); } } finally { instream.close(); } } // parsing the JSON response try { JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory() { public List creatArrayContainer() { return new LinkedList(); } public Map createObjectContainer() { return new LinkedHashMap(); } }; // retrieving the metrics and populating HashMap JSONObject obj = (JSONObject) parser.parse(result); if (obj.get("credits") == null) { logger.error("Error retrieving data. " + obj); return; } Map json = (Map) parser.parse(obj.get("credits").toString(), containerFactory); if (json.containsKey("autofillsms")) { if (json.get("autofillsms").toString().equals("false")) { metrics.put("Credits|autofillsms", 0); } else if (json.get("autofillsms").toString().equals("true")) { metrics.put("Credits|autofillsms", 1); } else { logger.error("can't determine whether Credits|autofillsms is true or false!"); } } if (json.containsKey("availablechecks")) { try { metrics.put("Credits|availablechecks", Integer.parseInt(json.get("availablechecks").toString())); } catch (NumberFormatException e) { logger.error("Error parsing metric value for Credits|availablechecks!"); } } if (json.containsKey("availablesms")) { try { metrics.put("Credits|availablesms", Integer.parseInt(json.get("availablesms").toString())); } catch (NumberFormatException e) { logger.error("Error parsing metric value for Credits|availablesms!"); } } if (json.containsKey("availablesmstests")) { try { metrics.put("Credits|availablesmstests", Integer.parseInt(json.get("availablesmstests").toString())); } catch (NumberFormatException e) { logger.error("Error parsing metric value for Credits|availablesmstests!"); } } if (json.containsKey("checklimit")) { try { metrics.put("Credits|checklimit", Integer.parseInt(json.get("checklimit").toString())); } catch (NumberFormatException e) { logger.error("Error parsing metric value for Credits|checklimit!"); } } } catch (ParseException e) { logger.error("JSON Parsing error: " + e.getMessage()); } catch (Throwable e) { logger.error(e.getMessage()); } } catch (IOException e1) { logger.error(e1.getMessage()); } catch (Throwable t) { logger.error(t.getMessage()); } }
From source file:com.microsoft.alm.plugin.authentication.AuthHelperTest.java
@Test public void createAuthInfo() { final Credentials credentials = new UsernamePasswordCredentials("userName", "password"); final AuthenticationInfo info = AuthHelper.createAuthenticationInfo("server", credentials); Assert.assertEquals("userName", info.getUserName()); Assert.assertEquals("password", info.getPassword()); Assert.assertEquals("server", info.getServerUri()); Assert.assertEquals("userName", info.getUserNameForDisplay()); }
From source file:ca.sqlpower.enterprise.ClientSideSessionUtils.java
public static HttpClient createHttpClient(SPServerInfo serviceInfo, CookieStore cookieStore) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 2000); DefaultHttpClient httpClient = new DefaultHttpClient(params); httpClient.setCookieStore(cookieStore); httpClient.getCredentialsProvider().setCredentials( new AuthScope(serviceInfo.getServerAddress(), AuthScope.ANY_PORT), new UsernamePasswordCredentials(serviceInfo.getUsername(), serviceInfo.getPassword())); return httpClient; }
From source file:org.apache.jena.atlas.web.auth.AbstractCredentialsAuthenticator.java
/** * Creates the credentials used to authenticate * <p>/* w w w. j av a 2 s. co m*/ * This default implementation simply returns a * {@link UsernamePasswordCredentials} instance, derived implementations may * need to override this * </p> * * @param target * Target URI * @return Credentials */ protected Credentials createCredentials(URI target) { String user = this.getUserName(target); char[] password = this.getPassword(target); return password != null ? new UsernamePasswordCredentials(user, new String(password)) : new UsernamePasswordCredentials(user, ""); }
From source file:net.netheos.pcsapi.oauth.PasswordSessionManager.java
public PasswordSessionManager(StorageBuilder builder) { super(builder.getUserCredentials()); this.httpClient = builder.getHttpClient(); this.userCredentialsRepo = builder.getUserCredentialsRepo(); usernamePasswordCredentials = new UsernamePasswordCredentials(userCredentials.getUserId(), userCredentials.getCredentials().getPassword()); // checks if we already have user_credentials: if (userCredentials != null) { PasswordCredentials credentials = userCredentials.getCredentials(); if (credentials.getPassword() == null) { throw new IllegalStateException("User credentials do not contain any password"); }/*w ww. j av a 2 s .c o m*/ } }
From source file:at.ac.univie.isc.asio.integration.IntegrationDsl.java
/** * Attach the given username/password pair as delegated credentials to the request. *//*from w ww .j ava2 s . c o m*/ public IntegrationDsl delegate(final String username, final String password) { this.delegated = new UsernamePasswordCredentials(username, password); return this; }
From source file:com.cognifide.qa.bb.provider.http.HttpClientProvider.java
private CredentialsProvider createCredentialsProvider(String url, String login, String password) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(getAuthScope(url), new UsernamePasswordCredentials(login, password)); return credentialsProvider; }
From source file:com.temenos.useragent.generic.http.DefaultHttpClientHelper.java
/** * Builds and returns the basic authentication provider. * //from w w w . j av a 2 s . co m * @return */ public static CredentialsProvider getBasicCredentialProvider() { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); ConnectionConfig config = ContextFactory.get().getContext().connectionCongfig(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( config.getValue(ConnectionConfig.USER_NAME), config.getValue(ConnectionConfig.PASS_WORD))); return credentialsProvider; }
From source file:org.qucosa.camel.component.sword.SwordConnection.java
private HttpClient prepareHttpClient() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager) .setDefaultCredentialsProvider(credentialsProvider).build(); return client; }