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


Java DefaultCredentialsProvider类代码示例

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


DefaultCredentialsProvider类属于com.gargoylesoftware.htmlunit包,在下文中一共展示了DefaultCredentialsProvider类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: bookRoom

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入依赖的package包/类
@Test
public void bookRoom() throws Exception {
    try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52)) {

        //set proxy username and password
        final DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider();
        credentialsProvider.addNTLMCredentials("abhisheks", "abhiProJul17", "apps.prorigo.com", 80, "", "");

        final HtmlPage page = webClient.getPage("http://apps.prorigo.com/conference/Booking");

        final HtmlForm form = page.getForms().get(0);
        final HtmlButton button = form.getFirstByXPath("//*[@id=\"Submit\"]");

        HtmlSelect select = (HtmlSelect) page.getElementById("ConferenceRooms");
        HtmlOption option = select.getOptionByValue("dedfcc1d-d413-e311-9c19-0025648b200e");
        select.setSelectedAttribute(option, true);

        HtmlInput inputStartTime = form.getInputByName("StartTime");
        inputStartTime.setValueAttribute("11:00 PM");

        HtmlInput inputEndTime = form.getInputByName("EndTime");
        inputEndTime.setValueAttribute("11:30 PM");

        HtmlInput inputReason = form.getInputByName("Title");
        inputReason.type("Test Booking By HtmlUnit");

        final HtmlPage page2 = button.click();
    }
}
 
开发者ID:Vedang18,项目名称:ProBOT,代码行数:30,代码来源:HtmlUnitTests.java

示例5: 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

示例6: 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

示例7: 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

示例8: addCredentials

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入依赖的package包/类
/**
 * Adds credentials to access intranet
 * @param user
 * @param webClient
 * @throws Exception
 */
private void addCredentials( User user, final WebClient webClient ) throws Exception
{
    DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider)webClient
        .getCredentialsProvider();
    credentialsProvider.addNTLMCredentials( user.getUsername(), passwordCoder.decrypt( user.getPassword() ), WEBSITE,
                                            80, "", "" );
    webClient.getOptions().setPrintContentOnFailingStatusCode( false );
}
 
开发者ID:Vedang18,项目名称:ProBOT,代码行数:15,代码来源:Bookie.java

示例9: 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

示例10: getFedoraAdminCredentials

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; //导入依赖的package包/类
private CredentialsProvider getFedoraAdminCredentials() {
    final CredentialsProvider credentials  = new DefaultCredentialsProvider();
    credentials.setCredentials(AuthScope.ANY, FEDORA_ADMIN_CREDENTIALS);
    return credentials;
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:6,代码来源:FedoraHtmlResponsesIT.java


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