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