List of usage examples for org.apache.http.client.protocol ClientContext AUTH_CACHE
String AUTH_CACHE
To view the source code for org.apache.http.client.protocol ClientContext AUTH_CACHE.
Click Source Link
From source file:org.hyperic.hq.plugin.rabbitmq.core.HypericRabbitAdmin.java
public HypericRabbitAdmin(Properties props) throws PluginException { int port = Integer.parseInt(props.getProperty(DetectorConstants.PORT)); String addr = props.getProperty(DetectorConstants.ADDR); boolean https = "true".equals(props.getProperty(DetectorConstants.HTTPS)); this.user = props.getProperty(DetectorConstants.USERNAME); this.pass = props.getProperty(DetectorConstants.PASSWORD); targetHost = new HttpHost(addr, port, https ? "https" : "http"); AgentKeystoreConfig config = new AgentKeystoreConfig(); client = new HQHttpClient(config, new HttpConfig(5000, 5000, null, 0), config.isAcceptUnverifiedCert()); client.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort(), "Management: Web UI"), new UsernamePasswordCredentials(user, pass)); List authPrefs = new ArrayList(1); authPrefs.add("Management: Web UI"); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); }
From source file:org.jenkinsmvn.jenkins.api.JenkinsClient.java
public void authenticate(String username, String password) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); client.getCredentialsProvider()/* w w w .jav a 2s . com*/ .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); }