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


Java AuthScope類代碼示例

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


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

示例1: main

import org.apache.http.auth.AuthScope; //導入依賴的package包/類
public static void main(String... args) throws IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.NTLM);
    httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
    NTCredentials creds = new NTCredentials("abhisheks", "abhiProJul17", "", "");
    httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
    HttpHost target = new HttpHost("apps.prorigo.com", 80, "http");

    // Make sure the same context is used to execute logically related requests
    HttpContext localContext = new BasicHttpContext();
    // Execute a cheap method first. This will trigger NTLM authentication
    HttpGet httpget = new HttpGet("/conference/Booking");
    HttpResponse response = httpclient.execute(target, httpget, localContext);
    HttpEntity entity = response.getEntity();
    System.out.println(EntityUtils.toString(entity));
}
 
開發者ID:Vedang18,項目名稱:ProBOT,代碼行數:18,代碼來源:ClientAuthentication2.java

示例2: setDefaultUser

import org.apache.http.auth.AuthScope; //導入依賴的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

示例3: constructHttpClient

import org.apache.http.auth.AuthScope; //導入依賴的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

示例4: setAuth

import org.apache.http.auth.AuthScope; //導入依賴的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: createHTTPClient

import org.apache.http.auth.AuthScope; //導入依賴的package包/類
private static AbstractHttpClient createHTTPClient() {
    AbstractHttpClient client = new DefaultHttpClient();
    String proxyHost = System.getProperty("https.proxyHost", "");
    if (!proxyHost.isEmpty()) {
        int proxyPort = Integer.parseInt(System.getProperty("https.proxyPort", "-1"));
        log.info("Using proxy " + proxyHost + ":" + proxyPort);
        HttpParams params = client.getParams();
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        String proxyUser = System.getProperty(JMeter.HTTP_PROXY_USER, JMeterUtils.getProperty(JMeter.HTTP_PROXY_USER));
        if (proxyUser != null) {
            log.info("Using authenticated proxy with username: " + proxyUser);
            String proxyPass = System.getProperty(JMeter.HTTP_PROXY_PASS, JMeterUtils.getProperty(JMeter.HTTP_PROXY_PASS));

            String localHost;
            try {
                localHost = InetAddress.getLocalHost().getCanonicalHostName();
            } catch (Throwable e) {
                log.error("Failed to get local host name, defaulting to 'localhost'", e);
                localHost = "localhost";
            }

            AuthScope authscope = new AuthScope(proxyHost, proxyPort);
            String proxyDomain = JMeterUtils.getPropDefault("http.proxyDomain", "");
            NTCredentials credentials = new NTCredentials(proxyUser, proxyPass, localHost, proxyDomain);
            client.getCredentialsProvider().setCredentials(authscope, credentials);
        }
    }
    return client;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:32,代碼來源:HttpUtils.java

示例6: generateClient

import org.apache.http.auth.AuthScope; //導入依賴的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.AuthScope; //導入依賴的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: matchCredentials

import org.apache.http.auth.AuthScope; //導入依賴的package包/類
/**
 * Find matching {@link Credentials credentials} for the given authentication scope.
 *
 * @param map the credentials hash map
 * @param authscope the {@link AuthScope authentication scope}
 * @return the credentials
 *
 */
private static Credentials matchCredentials(
        final Map<AuthScope, Credentials> map,
        final AuthScope authscope) {
    // see if we get a direct hit
    Credentials creds = map.get(authscope);
    if (creds == null) {
        // Nope.
        // Do a full scan
        int bestMatchFactor  = -1;
        AuthScope bestMatch  = null;
        for (AuthScope current: map.keySet()) {
            int factor = authscope.match(current);
            if (factor > bestMatchFactor) {
                bestMatchFactor = factor;
                bestMatch = current;
            }
        }
        if (bestMatch != null) {
            creds = map.get(bestMatch);
        }
    }
    return creds;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:BasicCredentialsProvider.java

示例9: associateRESTServerWithDefaultUser

import org.apache.http.auth.AuthScope; //導入依賴的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.AuthScope; //導入依賴的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.AuthScope; //導入依賴的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.AuthScope; //導入依賴的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: loadBug18993

import org.apache.http.auth.AuthScope; //導入依賴的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

示例14: setAuthentication

import org.apache.http.auth.AuthScope; //導入依賴的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

示例15: setPathRangeIndexInDatabase

import org.apache.http.auth.AuthScope; //導入依賴的package包/類
public static void setPathRangeIndexInDatabase(String dbName, JsonNode jnode) throws IOException
{
	try {			
		DefaultHttpClient client = new DefaultHttpClient();
		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));
		
			HttpPut put = new HttpPut("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
			put.addHeader("Content-type", "application/json");
			put.setEntity(new StringEntity(jnode.toString()));

			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


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