当前位置: 首页>>代码示例>>Java>>正文


Java AuthScope类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.auth.AuthScope的典型用法代码示例。如果您正苦于以下问题:Java AuthScope类的具体用法?Java AuthScope怎么用?Java AuthScope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthScope类属于org.apache.commons.httpclient.auth包,在下文中一共展示了AuthScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUrlContent

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
/**
 * Retrieves the content under the given URL with username and passwort
 * authentication.
 * 
 * @param url
 *            the URL to read
 * @param username
 * @param password
 * @return the read content.
 * @throws IOException
 *             if an I/O exception occurs.
 */
private static byte[] getUrlContent(URL url, String username,
        String password) throws IOException {
    final HttpClient client = new HttpClient();

    // Set credentials:
    client.getParams().setAuthenticationPreemptive(true);
    final Credentials credentials = new UsernamePasswordCredentials(
            username, password);
    client.getState()
            .setCredentials(
                    new AuthScope(url.getHost(), url.getPort(),
                            AuthScope.ANY_REALM), credentials);

    // Retrieve content:
    final GetMethod method = new GetMethod(url.toString());
    final int status = client.executeMethod(method);
    if (status != HttpStatus.SC_OK) {
        throw new IOException("Error " + status + " while retrieving "
                + url);
    }
    return method.getResponseBody();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:35,代码来源:BasicAuthLoader.java

示例2: matchCredentials

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
/**
 * Find matching {@link Credentials credentials} for the given authentication scope.
 *
 * @param map the credentials hash map
 * @param token the {@link AuthScope authentication scope}
 * @return the credentials 
 * 
 */
private static Credentials matchCredentials(final HashMap map, final AuthScope authscope) {
    // see if we get a direct hit
    Credentials creds = (Credentials)map.get(authscope);
    if (creds == null) {
        // Nope.
        // Do a full scan
        int bestMatchFactor  = -1;
        AuthScope bestMatch  = null;
        Iterator items = map.keySet().iterator();
        while (items.hasNext()) {
            AuthScope current = (AuthScope)items.next();
            int factor = authscope.match(current);
            if (factor > bestMatchFactor) {
                bestMatchFactor = factor;
                bestMatch = current;
            }
        }
        if (bestMatch != null) {
            creds = (Credentials)map.get(bestMatch);
        }
    }
    return creds;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:32,代码来源:HttpState.java

示例3: testPostProxyAuthHostAuthConnClose

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
/**
 * Tests POST via authenticating proxy + host auth + connection close 
 */
public void testPostProxyAuthHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
    
    this.server.setRequestHandler(handlerchain);
    
    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestProxy.java

示例4: create

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
@Create
public void create() {
	Protocol.registerProtocol("https", new Protocol("https",
			new EasySSLProtocolSocketFactory(), 8443));
	this.httpClient = new HttpClient();
	this.httpClient.getParams().setAuthenticationPreemptive(true);
	Credentials defaultcreds = new UsernamePasswordCredentials("admin",
			this.entityManager.find(CommandParameter.class,
					CommandParameter.HERITRIX_ADMINPW_KEY)
					.getCommandValue());
	this.httpClient.getState().setCredentials(
			new AuthScope(AuthScope.ANY_SCHEME, AuthScope.ANY_PORT,
					AuthScope.ANY_REALM), defaultcreds);
	this.engineUri = this.entityManager.find(Parameter.class,
			Parameter.ENGINE_URI.getKey()).getValue();
	Logger httpClientlogger = Logger.getLogger(this.httpClient.getClass());
	httpClientlogger.setLevel(Level.ERROR);
	Logger authChallengeProcessorLogger = Logger
			.getLogger(AuthChallengeProcessor.class);
	authChallengeProcessorLogger.setLevel(Level.ERROR);
	Logger httpMethodBaseLogger = Logger.getLogger(HttpMethodBase.class);
	httpMethodBaseLogger.setLevel(Level.ERROR);
	this.jobsDir = this.entityManager.find(Parameter.class,
			Parameter.JOBS_DIR.getKey()).getValue();
}
 
开发者ID:lablita,项目名称:ridire-cpi,代码行数:26,代码来源:CrawlerManager.java

示例5: create

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
private void create() {
	Protocol.registerProtocol("https", new Protocol("https",
			new EasySSLProtocolSocketFactory(), 8443));
	this.httpClient = new HttpClient();
	this.httpClient.getParams().setAuthenticationPreemptive(true);
	Credentials defaultcreds = new UsernamePasswordCredentials("admin",
			this.entityManager.find(CommandParameter.class,
					CommandParameter.HERITRIX_ADMINPW_KEY)
					.getCommandValue());
	this.httpClient.getState().setCredentials(
			new AuthScope(AuthScope.ANY_SCHEME, AuthScope.ANY_PORT,
					AuthScope.ANY_REALM), defaultcreds);
	this.engineUri = this.entityManager.find(Parameter.class,
			Parameter.ENGINE_URI.getKey()).getValue();
	Logger httpClientlogger = Logger.getLogger(this.httpClient.getClass());
	httpClientlogger.setLevel(Level.ERROR);
	Logger authChallengeProcessorLogger = Logger
			.getLogger(AuthChallengeProcessor.class);
	authChallengeProcessorLogger.setLevel(Level.ERROR);
	Logger httpMethodBaseLogger = Logger.getLogger(HttpMethodBase.class);
	httpMethodBaseLogger.setLevel(Level.ERROR);
	this.jobsDir = this.entityManager.find(Parameter.class,
			Parameter.JOBS_DIR.getKey()).getValue();
}
 
开发者ID:lablita,项目名称:ridire-cpi,代码行数:25,代码来源:JobDBDataUpdater.java

示例6: tryAuthentication

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
private static void tryAuthentication(RemoteFileReference wsReference) throws Exception {
	URL urlToConnect = wsReference.getUrl();
	String wsdlUrl = wsReference.getUrlpath();
	String username = wsReference.getAuthUser();
	String password = wsReference.getAuthPassword();
	
       HttpClient client = new HttpClient();

	client.getState().setCredentials(
			new AuthScope(urlToConnect.getHost(), urlToConnect.getPort()),
			new UsernamePasswordCredentials(username, password)
	);
       
       GetMethod get = new GetMethod(wsdlUrl);
       get.setDoAuthentication( true );
       
       int statuscode = client.executeMethod(get);
       
       if (statuscode == HttpStatus.SC_UNAUTHORIZED) {
       	throw new Exception(HttpStatus.SC_UNAUTHORIZED + " - Unauthorized connection!");
       }
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:23,代码来源:WsReference.java

示例7: HTTPMetadataProvider

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param metadataURL the URL to fetch the metadata
 * @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond
 * 
 * @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from
 *             the URL
 */
@Deprecated
public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException {
    super();
    try {
        metadataURI = new URI(metadataURL);
    } catch (URISyntaxException e) {
        throw new MetadataProviderException("Illegal URL syntax", e);
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setSoTimeout(requestTimeout);
    httpClient = new HttpClient(clientParams);
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(requestTimeout);
    authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort());

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:HTTPMetadataProvider.java

示例8: testAnonymousContent

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
public void testAnonymousContent() throws Exception {
    // disable credentials -> anonymous session
    final URL url = new URL(HTTP_BASE_URL);
    final AuthScope scope = new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM);
    httpClient.getParams().setAuthenticationPreemptive(false);
    httpClient.getState().setCredentials(scope, null);
    
    try {
        assertContent();
    } finally {
        // re-enable credentials -> admin session
        httpClient.getParams().setAuthenticationPreemptive(true);
        Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
        httpClient.getState().setCredentials(scope, defaultcreds);
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:17,代码来源:AnonymousAccessTest.java

示例9: testValidatingIncorrectHttpBasicCredentials

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
@Test
public void testValidatingIncorrectHttpBasicCredentials() throws Exception {

    // assume http and webdav are on the same host + port
    URL url = new URL(HttpTest.HTTP_BASE_URL);
    Credentials defaultcreds = new UsernamePasswordCredentials("garbage", "garbage");
    H.getHttpClient().getState()
            .setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_validate", "true"));
    HttpMethod post = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check",
            HttpServletResponse.SC_FORBIDDEN, params, null);
    assertXReason(post);

    HttpMethod get = H.assertHttpStatus(HttpTest.HTTP_BASE_URL + "/?j_validate=true",
            HttpServletResponse.SC_FORBIDDEN);
    assertXReason(get);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:20,代码来源:AuthenticationResponseCodeTest.java

示例10: testPreventLoopIncorrectHttpBasicCredentials

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
@Test
public void testPreventLoopIncorrectHttpBasicCredentials() throws Exception {

    // assume http and webdav are on the same host + port
    URL url = new URL(HttpTest.HTTP_BASE_URL);
    Credentials defaultcreds = new UsernamePasswordCredentials("garbage", "garbage");
    H.getHttpClient().getState()
            .setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);

    final String requestUrl = HttpTest.HTTP_BASE_URL + "/junk?param1=1";
    HttpMethod get = new GetMethod(requestUrl);
    get.setRequestHeader("Referer", requestUrl);
    get.setRequestHeader("User-Agent", "Mozilla/5.0 Sling Integration Test");
    int status = H.getHttpClient().executeMethod(get);
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, status);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:17,代码来源:AuthenticationResponseCodeTest.java

示例11: assertAuthenticatedHttpStatus

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
/** Verify that given URL returns expectedStatusCode
 * @throws IOException */
public void assertAuthenticatedHttpStatus(Credentials creds, String urlString, int expectedStatusCode, String assertMessage) throws IOException {
    URL baseUrl = new URL(HTTP_BASE_URL);
    AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
    GetMethod getMethod = new GetMethod(urlString);
    getMethod.setDoAuthentication(true);
    Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
    try {
        httpClient.getState().setCredentials(authScope, creds);

        final int status = httpClient.executeMethod(getMethod);
        if(assertMessage == null) {
            assertEquals(urlString,expectedStatusCode, status);
        } else {
            assertEquals(assertMessage, expectedStatusCode, status);
        }
    } finally {
        httpClient.getState().setCredentials(authScope, oldCredentials);
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:22,代码来源:AuthenticatedTestUtil.java

示例12: testAuthProxyWithRedirect

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
public void testAuthProxyWithRedirect() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    this.server.setHttpService(new BasicRedirectService("/"));
    this.proxy.requireAuthentication(creds, "test", true);
    
    GetMethod get = new GetMethod("/redirect/");
    try {
        this.client.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, get.getStatusCode());
    } finally {
        get.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:17,代码来源:TestProxyWithRedirect.java

示例13: testAuthProxyWithCrossSiteRedirect

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
public void testAuthProxyWithCrossSiteRedirect() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    this.server.setHttpService(new BasicRedirectService(
            "http://127.0.0.1:" + this.server.getLocalPort()));

    this.proxy.requireAuthentication(creds, "test", true);
    
    GetMethod get = new GetMethod("/redirect/");
    try {
        this.client.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, get.getStatusCode());
    } finally {
        get.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:TestProxyWithRedirect.java

示例14: testPreemptiveAuthProxyWithCrossSiteRedirect

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
public void testPreemptiveAuthProxyWithCrossSiteRedirect() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    this.client.getParams().setAuthenticationPreemptive(true);
    this.server.setHttpService(new BasicRedirectService(
            "http://127.0.0.1:" + this.server.getLocalPort()));

    this.proxy.requireAuthentication(creds, "test", true);
    
    GetMethod get = new GetMethod("/redirect/");
    try {
        this.client.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, get.getStatusCode());
    } finally {
        get.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:TestProxyWithRedirect.java

示例15: testHostNameValidation

import org.apache.commons.httpclient.auth.AuthScope; //导入依赖的package包/类
/**
 * Direct unit test for host versification in SSL.
 * The test has been proposed as a patch in <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1265">HTTPCLIENT-1265</a>
 */
@Issue("SECURITY-555")
public void testHostNameValidation() {
    HttpClient client = new HttpClient();
    if (PROXY_HOST != null) {
        if (PROXY_USER != null) {
            HttpState state = client.getState();
            state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(
                    PROXY_USER, PROXY_PASS));
        }
        client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
    }
    GetMethod method = new GetMethod(_urlWithIp);

    try {
        client.executeMethod(method);
        fail("Invalid hostname not detected");
    } catch (SSLException e) {
        assertTrue("Connection with a invalid server certificate rejected", true);
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception" + t.getMessage());
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:28,代码来源:TestHttps.java


注:本文中的org.apache.commons.httpclient.auth.AuthScope类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。