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


Java AuthScope.ANY_HOST屬性代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.auth.AuthScope.ANY_HOST屬性的典型用法代碼示例。如果您正苦於以下問題:Java AuthScope.ANY_HOST屬性的具體用法?Java AuthScope.ANY_HOST怎麽用?Java AuthScope.ANY_HOST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.commons.httpclient.auth.AuthScope的用法示例。


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

示例1: setNTLMCredentials

public static void setNTLMCredentials(HttpClient httpClient, UsernamePasswordCredentials credentials,
                                      String domain) {
    initNTLMv2();

    String localHostName;
    try {
        localHostName = Inet4Address.getLocalHost().getHostName();
    } catch (Exception e) {
        localHostName = "";
    }

    AuthScope authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
    httpClient.getState().setCredentials(
            authscope,
            new NTCredentials(
                    credentials.getUserName(),
                    credentials.getPassword(),
                    localHostName, domain));
}
 
開發者ID:DovAmir,項目名稱:httpclientAuthHelper,代碼行數:19,代碼來源:CredentialsUtils.java

示例2: testCredentialsMatching

public void testCredentialsMatching() {
    Credentials creds1 = new UsernamePasswordCredentials("name1", "pass1");
    Credentials creds2 = new UsernamePasswordCredentials("name2", "pass2");
    Credentials creds3 = new UsernamePasswordCredentials("name3", "pass3");
    
    AuthScope scope1 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
    AuthScope scope2 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm");
    AuthScope scope3 = new AuthScope("somehost", AuthScope.ANY_PORT, AuthScope.ANY_REALM);
    
    HttpState state = new HttpState();
    state.setCredentials(scope1, creds1);
    state.setCredentials(scope2, creds2);
    state.setCredentials(scope3, creds3);

    Credentials got = state.getCredentials(
        new AuthScope("someotherhost", 80, "someotherrealm", "basic"));
    Credentials expected = creds1;
    assertEquals(expected, got);

    got = state.getCredentials(
        new AuthScope("someotherhost", 80, "somerealm", "basic"));
    expected = creds2;
    assertEquals(expected, got);

    got = state.getCredentials(
        new AuthScope("somehost", 80, "someotherrealm", "basic"));
    expected = creds3;
    assertEquals(expected, got);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:29,代碼來源:TestHttpState.java

示例3: addAuth

@Override
public void addAuth(AuthCredentials creds) {
    String host = (StringUtils.isBlank(creds.getHost()) || "*".equals(creds.getHost())) ? AuthScope.ANY_HOST : creds.getHost();
    String realm = (StringUtils.isBlank(creds.getRealm()) || "*".equals(creds.getRealm())) ? AuthScope.ANY_REALM : creds.getRealm();
    int port = NumberUtils.toInt(creds.getPortString(), AuthScope.ANY_PORT);
    String scheme = creds.getScheme() != null ? creds.getScheme().getRepresentation() : AuthScope.ANY_SCHEME;

    Credentials defaultcreds = new UsernamePasswordCredentials(creds.getUserName(), creds.getPassword());
    httpclient.getState().setCredentials(new AuthScope(host, port, realm, scheme), defaultcreds);
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:10,代碼來源:TankHttpClient3.java

示例4: initCredentials

protected void initCredentials() {
    if (username != null && password != null) {
        AuthScope authscope = new AuthScope(
                getAuthHost() == null ? AuthScope.ANY_HOST : getAuthHost(),
                AuthScope.ANY_PORT);
        Credentials credentials = new UsernamePasswordCredentials(getUsername(), getPassword());
        httpClient.getState().setCredentials(authscope, credentials);
    }
}
 
開發者ID:payneteasy,項目名稱:superfly,代碼行數:9,代碼來源:HttpClientFactoryBean.java

示例5: configureHttpClient

@Override
protected void configureHttpClient(HttpClient client) {
    super.configureHttpClient(client);
    if (isUseNTLM()) {
        client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, Arrays.asList(AuthPolicy.NTLM));
        AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
        Credentials credentials = new NTCredentials(getUsername(), getPassword(), getHost(), getDomain());
        client.getState().setCredentials(authScope, credentials);
    }
}
 
開發者ID:switchfly,項目名稱:targetprocess-intellij-plugin,代碼行數:10,代碼來源:TargetProcessRepository.java

示例6: setProxyCredentials

public void setProxyCredentials(String username, String password) {
	if (username == null || username.trim().length() == 0)
		return;

	Credentials cred = new UsernamePasswordCredentials(username, password);
	AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
			AuthScope.ANY_REALM);

	client.getState().setProxyCredentials(scope, cred);

	proxyAuthent = true;
}
 
開發者ID:OpenGeoportal,項目名稱:ogpHarvester,代碼行數:12,代碼來源:XmlRequest.java

示例7: setCredentials

public void setCredentials(String username, String password) {
	Credentials cred = new UsernamePasswordCredentials(username, password);
	AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
			AuthScope.ANY_REALM);

	client.getState().setCredentials(scope, cred);
	client.getParams().setAuthenticationPreemptive(true);
	serverAuthent = true;
}
 
開發者ID:OpenGeoportal,項目名稱:ogpHarvester,代碼行數:9,代碼來源:XmlRequest.java

示例8: getCommonsHttpSolrServer

public static CommonsHttpSolrServer getCommonsHttpSolrServer(JobConf job) throws MalformedURLException {
  HttpClient client=new HttpClient();

  // Check for username/password
  if (job.getBoolean(SolrConstants.USE_AUTH, false)) {
    String username = job.get(SolrConstants.USERNAME);

    LOG.info("Authenticating as: " + username);

    AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);

    client.getState().setCredentials(scope, new UsernamePasswordCredentials(username, job.get(SolrConstants.PASSWORD)));

    HttpClientParams params = client.getParams();
    params.setAuthenticationPreemptive(true);

    client.setParams(params);
  }

  return new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL), client);
}
 
開發者ID:yahoo,項目名稱:anthelion,代碼行數:21,代碼來源:SolrUtils.java

示例9: setHttpProxyCredentials

@Override
public void setHttpProxyCredentials(String username, String password) {
    Credentials cred = new UsernamePasswordCredentials(username, password);
    AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
    httpClient.getState().setProxyCredentials(scope, cred);
}
 
開發者ID:janotav,項目名稱:ali-idea-plugin,代碼行數:6,代碼來源:AliRestClient.java

示例10: login

@Override
public synchronized void login() {
    // exclude the NTLM authentication scheme (requires NTCredentials we don't supply)
    List<String> authPrefs = new ArrayList<String>(2);
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    // first try Apollo style login
    String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate");
    String authXml = createAuthXml();
    PostMethod post = initPostMethod(authPoint, authXml);
    ResultInfo resultInfo = ResultInfo.create(null);
    executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());

    if(resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) {
        // try Maya style login
        Credentials cred = new UsernamePasswordCredentials(userName, password);
        AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
        httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8");
        httpClient.getState().setCredentials(scope, cred);

        authPoint = pathJoin("/", location, "/authentication-point/authenticate");
        GetMethod get = new GetMethod(authPoint);
        resultInfo = ResultInfo.create(null);
        executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet());
    }
    HttpStatusBasedException.throwForError(resultInfo);
    if(resultInfo.getHttpStatus() != 200) {
        // during login we only accept 200 status (to avoid redirects and such as seemingly correct login)
        throw new AuthenticationFailureException(resultInfo);
    }

    Cookie[] cookies = httpClient.getState().getCookies();
    Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME);
    addTenantCookie(ssoCookie);

    //Since ALM 12.00 it is required explicitly ask for QCSession calling "/rest/site-session"
    //For all the rest of HP ALM / AGM versions it is optional
    String siteSessionPoint = pathJoin("/", location, "/rest/site-session");
    String sessionParamXml = createRestSessionXml();
    post = initPostMethod(siteSessionPoint, sessionParamXml);
    resultInfo = ResultInfo.create(null);
    executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());
    //AGM throws 403
    if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) {
        HttpStatusBasedException.throwForError(resultInfo);
    }

    cookies = httpClient.getState().getCookies();
    Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME);
    sessionContext = new SessionContext(location, ssoCookie, qcCookie);
}
 
開發者ID:janotav,項目名稱:ali-idea-plugin,代碼行數:53,代碼來源:AliRestClient.java


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