本文整理匯總了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;
}
}