当前位置: 首页>>代码示例>>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;未经允许,请勿转载。