private Credentials promptForCredentials( final AuthScheme authScheme, final HttpParams params, final AuthScope authscope) { LOG.debug("Credentials required"); Credentials creds = null; CredentialsProvider credProvider = (CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER); if (credProvider != null) { try { creds = credProvider.getCredentials( authScheme, authscope.getHost(), authscope.getPort(), false); } catch (CredentialsNotAvailableException e) { LOG.warn(e.getMessage()); } if (creds != null) { this.state.setCredentials(authscope, creds); if (LOG.isDebugEnabled()) { LOG.debug(authscope + " new credentials given"); } } } else { LOG.debug("Credentials provider not available"); } return creds; }
private void addHttpAuth(Settings settings, SecureSettings secureSettings, Object[] authSettings) { if (StringUtils.hasText(settings.getNetworkHttpAuthUser())) { HttpState state = (authSettings[1] != null ? (HttpState) authSettings[1] : new HttpState()); authSettings[1] = state; state.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getNetworkHttpAuthUser(), secureSettings.getSecureProperty(ConfigurationOptions.ES_NET_HTTP_AUTH_PASS))); if (log.isDebugEnabled()) { log.info("Using detected HTTP Auth credentials..."); } } }
if (credentials != null) { client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, credentials);
private void init(String host, int port, String userName, String password) { this.host = host; this.port = port; this.userName = userName; this.password = password; this.baseUrl = "http://" + host + ":" + port + "/kylin/api"; client = new HttpClient(); if (userName != null && password != null) { client.getParams().setAuthenticationPreemptive(true); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), creds); } }
private void resetCredentials() { client.getState().clearCredentials(); if (user != null && password != null) { AuthScope authscope = AuthScope.ANY; Credentials credentials = new UsernamePasswordCredentials(user, password); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(authscope, credentials); } else { client.getParams().setAuthenticationPreemptive(false); } }
private void resetCredentials() { client.getState().clearCredentials(); if (user != null && password != null) { AuthScope authscope = AuthScope.ANY; Credentials credentials = new UsernamePasswordCredentials(user, password); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(authscope, credentials); } else { client.getParams().setAuthenticationPreemptive(false); } }
public static InputStream getInputStreamFromUrl(String url, String user, String password) { try { Pair<String, Integer> hostAndPort = validateUrl(url); HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); if ((user != null) && (password != null)) { httpclient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } // Execute the method. GetMethod method = new GetMethod(url); int statusCode = httpclient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { s_logger.error("Failed to read from URL: " + url); return null; } return method.getResponseBodyAsStream(); } catch (Exception ex) { s_logger.error("Failed to read from URL: " + url); return null; } }
private void checkCredentials(String user, String password) { try { Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl); if ((user != null) && (password != null)) { client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } else { s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); } } catch (IllegalArgumentException iae) { errorString = iae.getMessage(); status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; inited = false; } }
/** * @param username * @param password * @param httpClient */ public static void setCredentials(String username, String password, HttpClient httpClient) { if (username != null && password != null && httpClient != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting credentials with username " + username + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort()); } httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getState().setCredentials( new AuthScope(httpClient.getHostConfiguration().getHost(), httpClient.getHostConfiguration().getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password)); } }
@Ignore @Test public void testRestAPI() throws IOException { HttpClient client = new HttpClient(); // To be avoided unless in debug mode Credentials defaultcreds = new UsernamePasswordCredentials("admin", "111111"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); PutMethod method = new PutMethod("http://localhost:8080/agent/api/36"); final HttpMethodParams params = new HttpMethodParams(); params.setParameter("action", "approve"); method.setParams(params); final int i = client.executeMethod(method); System.out.println(method.getResponseBodyAsString()); } }
/** * @param host * @param port * @param realm * @param schema * @param username * @param password */ public void setBasicAuth(String host, int port, String realm, String schema, String username, String password) { httpState.setCredentials(new AuthScope("www.verisign.com", 443, realm, schema), new UsernamePasswordCredentials("username", "password")); authEnabled = true; }
/** * @since 7.0RC1 */ public UsernamePasswordCredentials setDefaultCredentials(UsernamePasswordCredentials defaultCredentials) { UsernamePasswordCredentials currentCredentials = getDefaultCredentials(); this.httpClient.getState().setCredentials(AuthScope.ANY, defaultCredentials); return currentCredentials; }
public void setAlternateAuth(String host, int port, String username, String password, List<String> schemaList) { httpState.setCredentials(new AuthScope("www.verisign.com", 443), new UsernamePasswordCredentials("username", "password")); authEnabled = true; client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemaList); }
public void init() { ParameterCheck.mandatory("baseUrl", baseUrl); StringBuilder sb = new StringBuilder(); sb.append(baseUrl + "/admin/cores"); this.adminUrl = sb.toString(); httpClient = httpClientFactory.getHttpClient(); HttpClientParams params = httpClient.getParams(); params.setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true); httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin")); }
private void resetCredentials() { client.getState().clearCredentials(); if (user != null && password != null) { AuthScope authscope = AuthScope.ANY; Credentials credentials = new UsernamePasswordCredentials(user, password); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(authscope, credentials); } else { client.getParams().setAuthenticationPreemptive(false); } }
public void setBasicCredentials(String username, String password) { getClient().getParams().setAuthenticationPreemptive(true); getClient().getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); }
private void initCIISTSMSGateway() { final String CIIST_SMS_USERNAME = FenixEduAcademicConfiguration.getConfiguration().getCIISTSMSUsername(); final String CIIST_SMS_PASSWORD = FenixEduAcademicConfiguration.getConfiguration().getCIISTSMSPassword(); CIIST_SMS_GATEWAY_URL = FenixEduAcademicConfiguration.getConfiguration().getCIISTSMSGatewayUrl(); if (!StringUtils.isEmpty(CIIST_SMS_USERNAME) && !StringUtils.isEmpty(CIIST_SMS_PASSWORD)) { CIIST_CLIENT = new HttpClient(); Credentials credentials = new UsernamePasswordCredentials(CIIST_SMS_USERNAME, CIIST_SMS_PASSWORD); CIIST_CLIENT.getState().setCredentials(AuthScope.ANY, credentials); } }
public void configureHttpClient(HttpClient client) { Credentials credentials = new UsernamePasswordCredentials(username, password); if (proxy) { client.getState().setProxyCredentials(AuthScope.ANY, credentials); } else { client.getState().setCredentials(AuthScope.ANY, credentials); } }
private HttpClient getHttpClient() { HttpClient client = new HttpClient(); client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()); client.getState().setCredentials( new AuthScope(repositoryInfo.getHost(), repositoryInfo.getPort(), AuthScope.ANY_REALM), defaultcreds); return client; }
@Override public void afterPropertiesSet() throws Exception { if (getCredentials() != null) { getHttpClient().getState().setCredentials(getAuthScope(), getCredentials()); getHttpClient().getParams().setAuthenticationPreemptive(true); } }