本文整理汇总了Java中java.net.Authenticator.requestPasswordAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Java Authenticator.requestPasswordAuthentication方法的具体用法?Java Authenticator.requestPasswordAuthentication怎么用?Java Authenticator.requestPasswordAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Authenticator
的用法示例。
在下文中一共展示了Authenticator.requestPasswordAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIsAuthenticationDialogSuppressed
import java.net.Authenticator; //导入方法依赖的package包/类
public void testIsAuthenticationDialogSuppressed() throws Exception {
final boolean[] suppressed = new boolean[1];
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
suppressed[0] = NetworkSettings.isAuthenticationDialogSuppressed();
return super.getPasswordAuthentication();
}
});
Callable<Void> callable = new Callable<Void>() {
@Override
public Void call() throws Exception {
Authenticator.requestPasswordAuthentication("wher.ev.er", Inet4Address.getByName("1.2.3.4"), 1234, "http", null, "http");
return null;
}
};
NetworkSettings.suppressAuthenticationDialog(callable);
assertTrue(suppressed[0]);
}
示例2: getSystemCreds
import java.net.Authenticator; //导入方法依赖的package包/类
private static PasswordAuthentication getSystemCreds(
final AuthScope authscope,
final Authenticator.RequestorType requestorType) {
final String hostname = authscope.getHost();
final int port = authscope.getPort();
final String protocol = port == 443 ? "https" : "http";
return Authenticator.requestPasswordAuthentication(
hostname,
null,
port,
protocol,
null,
translateScheme(authscope.getScheme()),
null,
requestorType);
}
示例3: getAnswer
import java.net.Authenticator; //导入方法依赖的package包/类
private void getAnswer() {
if (!answered) {
answered = true;
PasswordAuthentication passAuth =
Authenticator.requestPasswordAuthentication(
hci.host, hci.addr, hci.port, hci.protocol,
hci.prompt, hci.scheme, hci.url, hci.authType);
/**
* To be compatible with existing callback handler implementations,
* when the underlying Authenticator is canceled, username and
* password are assigned null. No exception is thrown.
*/
if (passAuth != null) {
username = passAuth.getUserName();
password = passAuth.getPassword();
}
}
}
示例4: authenticateProxy
import java.net.Authenticator; //导入方法依赖的package包/类
@Override public Credential authenticateProxy(
Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
for (Challenge challenge : challenges) {
if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
continue;
}
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
Authenticator.RequestorType.PROXY);
if (auth != null) {
return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
}
}
return null;
}
示例5: getAnswer
import java.net.Authenticator; //导入方法依赖的package包/类
private void getAnswer() {
if (!answered) {
answered = true;
PasswordAuthentication passAuth =
Authenticator.requestPasswordAuthentication(
hci.authenticator,
hci.host, hci.addr, hci.port, hci.protocol,
hci.prompt, hci.scheme, hci.url, hci.authType);
/**
* To be compatible with existing callback handler implementations,
* when the underlying Authenticator is canceled, username and
* password are assigned null. No exception is thrown.
*/
if (passAuth != null) {
username = passAuth.getUserName();
password = passAuth.getPassword();
}
}
}
示例6: authenticate
import java.net.Authenticator; //导入方法依赖的package包/类
@Override public Credential authenticate(
Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
for (Challenge challenge : challenges) {
if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
continue;
}
PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
if (auth != null) {
return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
}
}
return null;
}
示例7: getSystemCreds
import java.net.Authenticator; //导入方法依赖的package包/类
private static PasswordAuthentication getSystemCreds(
final AuthScope authscope,
final Authenticator.RequestorType requestorType) {
final String hostname = authscope.getHost();
final int port = authscope.getPort();
final HttpHost origin = authscope.getOrigin();
final String protocol = origin != null ? origin.getSchemeName() :
(port == 443 ? "https" : "http");
return Authenticator.requestPasswordAuthentication(
hostname,
null,
port,
protocol,
null,
translateScheme(authscope.getScheme()),
null,
requestorType);
}
示例8: testIsAuthenticationDialogNotSuppressed
import java.net.Authenticator; //导入方法依赖的package包/类
public void testIsAuthenticationDialogNotSuppressed() throws Exception {
final boolean[] suppressed = new boolean[1];
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
suppressed[0] = NetworkSettings.isAuthenticationDialogSuppressed();
return super.getPasswordAuthentication();
}
});
Authenticator.requestPasswordAuthentication("wher.ev.er", Inet4Address.getByName("1.2.3.4"), 1234, "http", null, "http");
assertFalse(suppressed[0]);
}
示例9: testUserInfoInUrl
import java.net.Authenticator; //导入方法依赖的package包/类
public void testUserInfoInUrl () throws Exception {
NbAuthenticator.install4test();
PasswordAuthentication auth = Authenticator.requestPasswordAuthentication("wher.ev.er", Inet4Address.getByName("1.2.3.4"), 1234, "http", null, "http",
new URL("http://user:[email protected]/resource"), Authenticator.RequestorType.SERVER);
assertNotNull(auth);
assertEquals("user", auth.getUserName());
assertEquals("password", new String(auth.getPassword()));
}
示例10: getSystemCreds
import java.net.Authenticator; //导入方法依赖的package包/类
private static PasswordAuthentication getSystemCreds(
final AuthScope authscope,
final Authenticator.RequestorType requestorType) {
return Authenticator.requestPasswordAuthentication(
authscope.getHost(),
null,
authscope.getPort(),
"http",
null,
translateScheme(authscope.getScheme()),
null,
requestorType);
}
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:14,代码来源:SystemDefaultCredentialsProvider.java
示例11: configureProxy
import java.net.Authenticator; //导入方法依赖的package包/类
private static void configureProxy(HttpClientBuilder builder, String url) {
List<Proxy> proxies = ProxySelector.getDefault().select(URI.create(url));
if (!proxies.isEmpty()) {
Optional<Proxy> proxy = proxies.stream().filter(p -> p.type().equals(Proxy.Type.HTTP))
.findFirst();
if (proxy.isPresent()) {
InetSocketAddress address = (InetSocketAddress) proxy.get().address();
builder.setProxy(new HttpHost(address.getHostName(), address.getPort()));
try {
PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
address.getHostName(), null, address.getPort(),
(url.startsWith("https://") ? "https" : "http"),
"Credentials for proxy " + proxy, null, new URL(url),
Authenticator.RequestorType.PROXY);
if (auth != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(address.getHostName(), address.getPort()),
new UsernamePasswordCredentials(auth.getUserName(),
String.valueOf(auth.getPassword())));
builder.setDefaultCredentialsProvider(credsProvider);
}
}
catch (MalformedURLException e) {
}
}
}
}
示例12: testPasswordAuthentication
import java.net.Authenticator; //导入方法依赖的package包/类
@Test
public void testPasswordAuthentication() throws UnknownHostException {
InetAddress addr = InetAddress.getLocalHost();
PasswordAuthentication pa =
Authenticator.requestPasswordAuthentication(addr, 8080, PROTOCOL, "prompt", "HTTP");
Assert.assertNull(pa);
MockAuthenticator mock = new MockAuthenticator();
Authenticator.setDefault(mock);
addr = InetAddress.getLocalHost();
pa = Authenticator.requestPasswordAuthentication(addr, 80, PROTOCOL, "prompt", "HTTP");
Assert.assertNotNull(pa);
Assert.assertEquals(USERNAME_TEST, pa.getUserName());
Assert.assertEquals(PASSWORD_TEST, String.valueOf(pa.getPassword()));
Authenticator.setDefault(null);
}
示例13: authenticateProxy
import java.net.Authenticator; //导入方法依赖的package包/类
@Override
public Credential authenticateProxy(Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
for (Challenge challenge : challenges) {
if (!"Basic".equals(challenge.getScheme())) {
continue;
}
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.PROXY);
if (auth != null) {
return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
}
}
return null;
}
示例14: testIsAuthenticationDialogSuppressedExclusive
import java.net.Authenticator; //导入方法依赖的package包/类
@SuppressWarnings("SleepWhileInLoop")
public void testIsAuthenticationDialogSuppressedExclusive() throws InterruptedException, UnknownHostException {
final boolean[] suppressed = new boolean[1];
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
suppressed[0] = NetworkSettings.isAuthenticationDialogSuppressed();
return super.getPasswordAuthentication();
}
});
final CountDownLatch doneSignal1 = new CountDownLatch(1);
final CountDownLatch doneSignal2 = new CountDownLatch(1);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Callable<Void> callable = new Callable<Void>() {
@Override
public Void call() throws Exception {
doneSignal1.countDown();
doneSignal2.await();
Authenticator.requestPasswordAuthentication("wher.ev.er", Inet4Address.getByName("1.2.3.4"), 1234, "http", null, "http");
return null;
}
};
try {
NetworkSettings.suppressAuthenticationDialog(callable);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
});
t.start();
doneSignal1.await();
Authenticator.requestPasswordAuthentication("wher.ev.er", Inet4Address.getByName("1.2.3.4"), 1234, "http", null, "http");
assertFalse(suppressed[0]);
doneSignal2.countDown();
t.join();
assertTrue(suppressed[0]);
}
示例15: connect
import java.net.Authenticator; //导入方法依赖的package包/类
public void connect() throws IOException {
if (connected) {
return;
}
if (auth == null) {
auth = System.getProperty("root.scheme");
}
if (auth != null && auth.equalsIgnoreCase(XROOT_AUTHORIZATION_SCHEME_ANONYMOUS)) {
username = XROOT_AUTHORIZATION_SCHEME_ANONYMOUS;
try {
password = System.getProperty("user.name") + "@" + InetAddress.getLocalHost().getCanonicalHostName();
} catch (SecurityException x) {
password = "[email protected]";
}
}
if (username == null) {
username = System.getProperty("root.user");
}
if (password == null) {
password = System.getProperty("root.password");
}
// Check for username password, if not present, and if allowed, prompt the user.
if ((password == null || username == null) && getAllowUserInteraction()) {
int port = url.getPort();
if (port == -1) {
port = XrootdProtocol.defaultPort;
}
PasswordAuthentication pa = Authenticator.requestPasswordAuthentication(url.getHost(), null, port, "root", "Username/Password required", auth);
if (pa != null) {
username = pa.getUserName();
password = new String(pa.getPassword());
}
}
if (password == null || username == null) {
throw new IOException("Authorization Required");
}
logger.fine("Opening rootd connection to: " + url);
Destination dest = new Destination(url.getHost(), url.getPort(), username);
session = new Session(dest);
try {
FileStatus status = session.stat(url.getFile());
fSize = status.getSize();
flags = status.getFlags();
date = status.getModTime().getTime();
// Prepare to do a checksum
// FIXME: The file location may contain the original redirector, which may result
// in the checksum being sent to the redirector
if (!dest.equals(status.getFileLocation())) {
session.close();
session = new Session(status.getFileLocation());
}
connected = true;
} catch (IOException t) {
disconnect();
throw t;
}
}