本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
};
}
示例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();
}
}