當前位置: 首頁>>代碼示例>>Java>>正文


Java Authenticator.requestPasswordAuthentication方法代碼示例

本文整理匯總了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]);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:NetworkSettingsTest.java

示例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);
}
 
開發者ID:mozilla-mobile,項目名稱:FirefoxData-android,代碼行數:17,代碼來源:SystemDefaultCredentialsProvider.java

示例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();
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:NegotiateCallbackHandler.java

示例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;
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:19,代碼來源:HttpAuthenticator.java

示例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();
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:NegotiateCallbackHandler.java

示例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;
}
 
開發者ID:chrisuehlinger,項目名稱:smart-mirror-app,代碼行數:17,代碼來源:HttpAuthenticator.java

示例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);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:19,代碼來源:SystemDefaultCredentialsProvider.java

示例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]);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:NetworkSettingsTest.java

示例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()));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:NbAuthenticatorTest.java

示例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) {
            }
        }
    }
}
 
開發者ID:atomist-attic,項目名稱:rug-cli,代碼行數:30,代碼來源:HttpClientFactory.java

示例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);
}
 
開發者ID:AlbanAndrieu,項目名稱:nabla-projects-interview-visma,代碼行數:16,代碼來源:InputTest.java

示例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;
}
 
開發者ID:goodev,項目名稱:android-discourse,代碼行數:16,代碼來源:HttpAuthenticator.java

示例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]);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:43,代碼來源:NetworkSettingsTest.java

示例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;
    }
}
 
開發者ID:diana-hep,項目名稱:root4j,代碼行數:60,代碼來源:XrootdURLConnection.java


注:本文中的java.net.Authenticator.requestPasswordAuthentication方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。