當前位置: 首頁>>代碼示例>>Java>>正文


Java UsernamePasswordCredentials類代碼示例

本文整理匯總了Java中org.apache.http.auth.UsernamePasswordCredentials的典型用法代碼示例。如果您正苦於以下問題:Java UsernamePasswordCredentials類的具體用法?Java UsernamePasswordCredentials怎麽用?Java UsernamePasswordCredentials使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UsernamePasswordCredentials類屬於org.apache.http.auth包,在下文中一共展示了UsernamePasswordCredentials類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setDefaultUser

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void setDefaultUser(String usr,String restServerName) throws ClientProtocolException, IOException {

		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));
		String  body = "{\"default-user\": \""+usr+"\"}";

		HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http&group-id=Default");
		put.addHeader("Content-type", "application/json");
		put.setEntity(new StringEntity(body));

		HttpResponse response2 = client.execute(put);
		HttpEntity respEntity = response2.getEntity();
		if(respEntity != null){
			String content =  EntityUtils.toString(respEntity);
			System.out.println(content);
		}
	}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:21,代碼來源:ConnectedRESTQA.java

示例2: constructHttpClient

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
protected CloseableHttpClient constructHttpClient() throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  URL                 mmsc          = new URL(apn.getMmsc());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  if (apn.hasAuthentication()) {
    credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
                                 new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
  }

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT))
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .setDefaultCredentialsProvider(credsProvider)
                    .build();
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:26,代碼來源:LegacyMmsConnection.java

示例3: MyPageProcessor

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public MyPageProcessor(SpiderInfo info, Task task) {
    this.site = Site.me().setDomain(info.getDomain()).setTimeOut(info.getTimeout())
            .setRetryTimes(info.getRetry()).setSleepTime(info.getSleep())
            .setCharset(StringUtils.isBlank(info.getCharset()) ? null : info.getCharset())
            .setUserAgent(info.getUserAgent());
    //設置抓取代理IP與接口
    if (StringUtils.isNotBlank(info.getProxyHost()) && info.getProxyPort() > 0) {
        this.site.setHttpProxy(new HttpHost(info.getProxyHost(), info.getProxyPort()));
        //設置代理的認證
        if (StringUtils.isNotBlank(info.getProxyUsername()) && StringUtils.isNotBlank(info.getProxyPassword())) {
            this.site.setUsernamePasswordCredentials(new UsernamePasswordCredentials(info.getProxyUsername(), info.getProxyPassword()));
        }
    }
    this.info = info;
    this.task = task;
}
 
開發者ID:bruceq,項目名稱:Gather-Platform,代碼行數:17,代碼來源:CommonSpider.java

示例4: setAuth

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
@Override
public void setAuth(SensorThingsService service) {
    try {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        URL url = service.getEndpoint().toURL();
        credsProvider.setCredentials(
                new AuthScope(url.getHost(), url.getPort()),
                new UsernamePasswordCredentials(editorUsername.getValue(), editorPassword.getValue()));
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider)
                .build();
        service.setClient(httpclient);
    } catch (MalformedURLException ex) {
        LOGGER.error("Failed to initialise basic auth.", ex);
    }
}
 
開發者ID:hylkevds,項目名稱:SensorThingsProcessor,代碼行數:17,代碼來源:AuthBasic.java

示例5: MyAnimeListQuery

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public MyAnimeListQuery(Charrizard charrizard) {
    status = MyAnimeListStatus.UNKNOWN_ERROR;
    errorDescription = "Unknown error.";
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("https://myanimelist.net/api/account/verify_credentials.xml");
        httpGet.addHeader(BasicScheme.authenticate(
                new UsernamePasswordCredentials(charrizard.getSettings().getMyAnimeList().getUsername(), charrizard.getSettings().getMyAnimeList().getUsername()),
                "UTF-8", false));

        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity responseEntity = httpResponse.getEntity();
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            status = MyAnimeListStatus.AUTH_ERROR;
            errorDescription = "Authorization Error: " + httpResponse.getStatusLine().getReasonPhrase();
            return;
        }
    } catch (IOException e) {
        status = MyAnimeListStatus.REQUEST_ERROR;
        errorDescription = "Can't connect to MyAnimeList: " + e.getMessage();
        e.printStackTrace();
    }
}
 
開發者ID:kacperduras,項目名稱:Charrizard,代碼行數:24,代碼來源:MyAnimeListQuery.java

示例6: generateClient

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
@Override
public CloseableHttpAsyncClient generateClient ()
{
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
   credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
           new UsernamePasswordCredentials(serviceUser, servicePass));
   RequestConfig rqconf = RequestConfig.custom()
         .setCookieSpec(CookieSpecs.DEFAULT)
         .setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
         .setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
         .setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
         .build();
   CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
         .setDefaultCredentialsProvider (credsProvider)
         .setDefaultRequestConfig(rqconf)
         .build ();
   res.start ();
   return res;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:20,代碼來源:ODataProductSynchronizer.java

示例7: generateClient

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
@Override
public CloseableHttpAsyncClient generateClient ()
{
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
   credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
            new UsernamePasswordCredentials(username, password));
   RequestConfig rqconf = RequestConfig.custom()
         .setCookieSpec(CookieSpecs.DEFAULT)
         .setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
         .setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
         .setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
         .build();
   CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
         .setDefaultCredentialsProvider (credsProvider)
         .setDefaultRequestConfig(rqconf)
         .build ();
   res.start ();
   return res;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:20,代碼來源:ODataClient.java

示例8: ElasticBulkSender

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public ElasticBulkSender(String user, String password, HttpHost... hosts) {
	this.user = user;
	this.password = password;
	this.hosts = hosts;
	this.restClient = RestClient.builder(hosts)
			.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
				@Override
				public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
					if (!Strings.isBlank(user)) {
						CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
						credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
		                return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
					} else {
						return httpClientBuilder;
					}
				}
	        })
			.build();
}
 
開發者ID:magrossi,項目名稱:es-log4j2-appender,代碼行數:20,代碼來源:ElasticBulkSender.java

示例9: associateRESTServerWithDefaultUser

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void associateRESTServerWithDefaultUser(String restServerName,String userName,String authType)throws Exception{
	DefaultHttpClient client = new DefaultHttpClient();

	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));
	String  body = "{ \"default-user\":\""+userName+"\",\"authentication\": \""+authType+"\",\"group-name\": \"Default\"}";

	HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http");
	put.addHeader("Content-type", "application/json");
	put.setEntity(new StringEntity(body));

	HttpResponse response2 = client.execute(put);
	HttpEntity respEntity = response2.getEntity();
	if(respEntity != null){
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:20,代碼來源:ConnectedRESTQA.java

示例10: deleteRESTUser

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void deleteRESTUser(String usrName){
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/users/"+usrName);

		HttpResponse response = client.execute(delete);
		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(3500);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}

}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:21,代碼來源:ConnectedRESTQA.java

示例11: deleteUserRole

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void deleteUserRole(String roleName){
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/roles/"+roleName);

		HttpResponse response = client.execute(delete);
		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(3500);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}

}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:21,代碼來源:ConnectedRESTQA.java

示例12: deleteRESTServerWithDB

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void deleteRESTServerWithDB(String restServerName)	{
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/v1/rest-apis/"+restServerName+"?include=content&include=modules");

		HttpResponse response = client.execute(delete);
		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(9500);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}
}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:20,代碼來源:ConnectedRESTQA.java

示例13: deleteRESTServer

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void deleteRESTServer(String restServerName)	{
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/v1/rest-apis/"+restServerName+"&include=modules");
		HttpResponse response = client.execute(delete);

		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(3500);
			waitForServerRestart();
		}
		else System.out.println("Server response "+response.getStatusLine().getStatusCode());
	}catch (Exception e) {
		// writing error to Log
		System.out.println("Inside Deleting Rest server is throwing an error");
		e.printStackTrace();
	}
}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:23,代碼來源:ConnectedRESTQA.java

示例14: loadBug18993

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void loadBug18993(){
	try{
		DefaultHttpClient client = new DefaultHttpClient();
		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8011),
				new UsernamePasswordCredentials("admin", "admin"));
		String document ="<foo>a space b</foo>";
		String  perm = "perm:rest-writer=read&perm:rest-writer=insert&perm:rest-writer=update&perm:rest-writer=execute";
		HttpPut put = new HttpPut("http://"+host+":8011/v1/documents?uri=/a%20b&"+perm);
		put.addHeader("Content-type", "application/xml");
		put.setEntity(new StringEntity(document)); 	
		HttpResponse response = client.execute(put);
		HttpEntity respEntity = response.getEntity();
		if(respEntity != null){
			String content =  EntityUtils.toString(respEntity);
			System.out.println(content);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}

}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:24,代碼來源:ConnectedRESTQA.java

示例15: setAuthentication

import org.apache.http.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public static void setAuthentication(String level,String restServerName) throws ClientProtocolException, IOException
{
	DefaultHttpClient client = new DefaultHttpClient();

	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));
	String  body = "{\"authentication\": \""+level+"\"}";

	HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http&group-id=Default");
	put.addHeader("Content-type", "application/json");
	put.setEntity(new StringEntity(body));

	HttpResponse response2 = client.execute(put);
	HttpEntity respEntity = response2.getEntity();
	if(respEntity != null){
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:21,代碼來源:ConnectedRESTQA.java


注:本文中的org.apache.http.auth.UsernamePasswordCredentials類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。