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


Java DefaultCredentialsProvider.addCredentials方法代码示例

本文整理汇总了Java中com.gargoylesoftware.htmlunit.DefaultCredentialsProvider.addCredentials方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultCredentialsProvider.addCredentials方法的具体用法?Java DefaultCredentialsProvider.addCredentials怎么用?Java DefaultCredentialsProvider.addCredentials使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.gargoylesoftware.htmlunit.DefaultCredentialsProvider的用法示例。


在下文中一共展示了DefaultCredentialsProvider.addCredentials方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupClient

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入方法依赖的package包/类
private WebClient setupClient(final String username, final String password) {
  final WebClient client = new WebClient(BrowserVersion.FIREFOX_24);
  final WebClientOptions options = client.getOptions();
  DefaultCredentialsProvider credentials = new DefaultCredentialsProvider();
  credentials.addCredentials(username, password);
  client.setCredentialsProvider(credentials);
  options.setRedirectEnabled(true);
  options.setThrowExceptionOnFailingStatusCode(true);
  client.addWebWindowListener(new ValidateOnContentChange());
  client.getCookieManager().setCookiesEnabled(false);

  // Try to log only "interesting" things:
  // Don't log errors we can't fix due to browser bugs etc.
  client.setIncorrectnessListener(new SuppressingIncorrectnessListener());

  return client;
}
 
开发者ID:CoreFiling,项目名称:reviki,代码行数:18,代码来源:WebTestSupport.java

示例2: provideHtmlUnitCredentialsProviderMap

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入方法依赖的package包/类
@Provides
protected Map<String, CredentialsProvider> provideHtmlUnitCredentialsProviderMap(final Configuration config) {
	Map<String, CredentialsProvider> result = newHashMapWithExpectedSize(1);

	// extract sorted credential keys
	Set<String> credentialKeys = newTreeSet(Maps.filterKeys(config, (Predicate<String>) input -> input.startsWith(WebConstants.HTMLUNIT_CREDENTIALS_PREFIX)).keySet());

	for (Iterator<String> it = credentialKeys.iterator(); it.hasNext();) {
		String key = it.next();

		Matcher matcher = HOST_EXTRACTION_PATTERN.matcher(key);
		checkState(matcher.find(), "Could not extract host from property: " + key);

		String host = matcher.group();
		String password = config.get(key);

		// as set is sorted, the next key is that for the username for the current host
		String username = config.get(it.next());

		DefaultCredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
		credentialsProvider.addCredentials(username, password);
		result.put(host, credentialsProvider);
	}

	return result;
}
 
开发者ID:mgm-tp,项目名称:jfunk,代码行数:27,代码来源:ScopingWebDriverModule.java

示例3: setup

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入方法依赖的package包/类
@Before
public void setup() throws IOException {
	webClient = new WebClient();

	DefaultCredentialsProvider creds = new DefaultCredentialsProvider();
	creds.addCredentials("root", "p1");
	webClient.setCredentialsProvider(creds);
	resourceBundle = getBundle("ResourceJSF");
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:10,代码来源:ApplicationTestCase.java

示例4: newWebClient

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入方法依赖的package包/类
@Override
protected WebClient newWebClient(BrowserVersion browserVersion) {
	WebClient client = super.newWebClient(browserVersion);
	DefaultCredentialsProvider provider = new DefaultCredentialsProvider();
	provider.addCredentials(USERNAME, PASSWORD);
	client.setCredentialsProvider(provider);
	return client;
}
 
开发者ID:ViliamS,项目名称:XPathBuilder,代码行数:9,代码来源:AuthenticatedHtmlUnitDriver.java

示例5: newWebClient

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入方法依赖的package包/类
@Override
protected WebClient newWebClient(final BrowserVersion browserVersion) {
	WebClient client = super.newWebClient(browserVersion);
	DefaultCredentialsProvider provider = new DefaultCredentialsProvider();
	provider.addCredentials(USERNAME, PASSWORD);
	client.setCredentialsProvider(provider);
	return client;
}
 
开发者ID:Nocket,项目名称:nocket,代码行数:9,代码来源:AuthenticatedHtmlUnitDriver.java

示例6: webDriver

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入方法依赖的package包/类
@Bean
public WebDriver webDriver() {
    return new HtmlUnitDriver() {
        @Override
        protected WebClient getWebClient() {
            final WebClient webClient = super.getWebClient();
            final DefaultCredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
            credentialsProvider.addCredentials(login, password);
            webClient.setCredentialsProvider(credentialsProvider);

            return webClient;
        }

    };
}
 
开发者ID:KyleRogers,项目名称:cylus,代码行数:16,代码来源:WebAppExecutingTestContext.java

示例7: test

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入方法依赖的package包/类
private void test(final HttpUrl baseUrl) throws Exception {
  final DefaultCredentialsProvider credentials = new DefaultCredentialsProvider();
  final WebClient web = new WebClient(BrowserVersion.BEST_SUPPORTED);
  web.setCredentialsProvider(credentials);
  try {
    final WebClientOptions options = web.getOptions();
    options.setThrowExceptionOnFailingStatusCode(false);
    options.setThrowExceptionOnScriptError(false);
    options.setJavaScriptEnabled(true);
    options.setCssEnabled(true);
    options.setDownloadImages(true);
    options.setRedirectEnabled(true);
    options.setUseInsecureSSL(true);

    final Page page1 = web.getPage(baseUrl.url());
    assertEquals(401, page1.getWebResponse().getStatusCode());
    assertWWWAuthHeaderIsCorrect(
      page1.getWebResponse().getResponseHeaderValue("WWW-AUTHENTICATE"),
      baseUrl.host()
    );

    credentials.addCredentials("anonymous", "anonymous",
                               baseUrl.host(), baseUrl.port(), "[email protected]" + baseUrl.host());

    final Page page2 = web.getPage(baseUrl.url());
    assertEquals(401, page2.getWebResponse().getStatusCode());
    assertWWWAuthHeaderIsCorrect(
      page2.getWebResponse().getResponseHeaderValue("WWW-AUTHENTICATE"),
      baseUrl.host()
    );

    credentials.removeCredentials(new AuthScope(baseUrl.host(), baseUrl.port()));
    credentials.addCredentials("user1", "password1",
                               baseUrl.host(), baseUrl.port(), "[email protected]" + baseUrl.host());

    final Page page3 = web.getPage(baseUrl.url());
    assertEquals(200, page3.getWebResponse().getStatusCode());

    credentials.removeCredentials(new AuthScope(baseUrl.host(), baseUrl.port()));
    credentials.addCredentials("user 2", "password 2",
                               baseUrl.host(), baseUrl.port(), "[email protected]" + baseUrl.host());

    final Page page4 = web.getPage(baseUrl.url());
    assertEquals(200, page4.getWebResponse().getStatusCode());
  }
  finally {
    web.close();
  }
}
 
开发者ID:programingjd,项目名称:okserver,代码行数:50,代码来源:DigestAuthHandlerTest.java


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