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


Java PasswordAuthentication類代碼示例

本文整理匯總了Java中java.net.PasswordAuthentication的典型用法代碼示例。如果您正苦於以下問題:Java PasswordAuthentication類的具體用法?Java PasswordAuthentication怎麽用?Java PasswordAuthentication使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PasswordAuthentication類屬於java.net包,在下文中一共展示了PasswordAuthentication類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testIsAuthenticationDialogSuppressed

import java.net.PasswordAuthentication; //導入依賴的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: getAnswer

import java.net.PasswordAuthentication; //導入依賴的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:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:NegotiateCallbackHandler.java

示例3: init

import java.net.PasswordAuthentication; //導入依賴的package包/類
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:NTLMAuthentication.java

示例4: getPasswordAuthentication

import java.net.PasswordAuthentication; //導入依賴的package包/類
public PasswordAuthentication getPasswordAuthentication(String url, boolean forceRelogin) {
    if(kenaiAccessor != null) {
        if(forceRelogin && queriedUrls.contains(url)) {
            // we already queried the authentication for this url, but it didn't
            // seem to be accepted -> force a new login, the current user
            // might not be authorized for the given kenai project (url).
            if(!kenaiAccessor.showLogin()) {
                return null;
            }
        }
        queriedUrls.add(url);
        return kenaiAccessor.getPasswordAuthentication(url);
    } else {
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:HgKenaiAccessor.java

示例5: testUserPassword

import java.net.PasswordAuthentication; //導入依賴的package包/類
@Test
public void testUserPassword() throws Exception {
  startServer(buildUserPasswordConfig());

  Authenticator.setDefault(new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication("oryx", "pass".toCharArray());
    }
  });

  try {
    String response = Resources.toString(
        new URL("http://localhost:" + getHTTPPort() + "/helloWorld"),
        StandardCharsets.UTF_8);
    assertEquals("Hello, World", response);
  } finally {
    Authenticator.setDefault(null);
  }
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:21,代碼來源:SecureAPIConfigIT.java

示例6: main

import java.net.PasswordAuthentication; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    final String user = "probe";
    final String password = "probe";

    Proxy proxyTest = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 10779));

    java.net.Authenticator.setDefault(new java.net.Authenticator() {
        private PasswordAuthentication authentication = new PasswordAuthentication(user, password.toCharArray());

        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return authentication;
        }
    });

    OkHttpClient client = new OkHttpClient.Builder().proxy(proxyTest).build();
    Request request = new Request.Builder().url("https://www.baidu.com").build();
    Response response = client.newCall(request).execute();
    System.out.println("狀態碼: " + response.code());
    System.out.println("響應內容: \n" + response.body().string());

    client.dispatcher().executorService().shutdown();
    client.connectionPool().evictAll();
}
 
開發者ID:biezhi,項目名稱:probe,代碼行數:25,代碼來源:HttpProxyClient.java

示例7: privilegedRequestPasswordAuthentication

import java.net.PasswordAuthentication; //導入依賴的package包/類
private static PasswordAuthentication
privilegedRequestPasswordAuthentication(
                        final String host,
                        final InetAddress addr,
                        final int port,
                        final String protocol,
                        final String prompt,
                        final String scheme,
                        final URL url,
                        final RequestorType authType) {
    return java.security.AccessController.doPrivileged(
        new java.security.PrivilegedAction<PasswordAuthentication>() {
            public PasswordAuthentication run() {
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("Requesting Authentication: host =" + host + " url = " + url);
                }
                PasswordAuthentication pass = Authenticator.requestPasswordAuthentication(
                    host, addr, port, protocol,
                    prompt, scheme, url, authType);
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null"));
                }
                return pass;
            }
        });
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:HttpURLConnection.java

示例8: authenticateProxy

import java.net.PasswordAuthentication; //導入依賴的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

示例9: getPasswordAuthentication

import java.net.PasswordAuthentication; //導入依賴的package包/類
@Override protected PasswordAuthentication getPasswordAuthentication() {
  this.calls.add("host=" + getRequestingHost()
      + " port=" + getRequestingPort()
      + " site=" + getRequestingSite().getHostName()
      + " url=" + getRequestingURL()
      + " type=" + getRequestorType()
      + " prompt=" + getRequestingPrompt()
      + " protocol=" + getRequestingProtocol()
      + " scheme=" + getRequestingScheme());
  return authentication;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:RecordingAuthenticator.java

示例10: authenticate

import java.net.PasswordAuthentication; //導入依賴的package包/類
@Override public Request authenticate(Route route, Response response) throws IOException {
  List<Challenge> challenges = response.challenges();
  Request request = response.request();
  HttpUrl url = request.url();
  boolean proxyAuthorization = response.code() == 407;
  Proxy proxy = route.proxy();

  for (int i = 0, size = challenges.size(); i < size; i++) {
    Challenge challenge = challenges.get(i);
    if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue;

    PasswordAuthentication auth;
    if (proxyAuthorization) {
      InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
      auth = java.net.Authenticator.requestPasswordAuthentication(
          proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
          url.scheme(), challenge.realm(), challenge.scheme(), url.url(),
          RequestorType.PROXY);
    } else {
      auth = java.net.Authenticator.requestPasswordAuthentication(
          url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(),
          challenge.realm(), challenge.scheme(), url.url(), RequestorType.SERVER);
    }

    if (auth != null) {
      String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword()));
      return request.newBuilder()
          .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential)
          .build();
    }
  }

  return null; // No challenges were satisfied!
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:35,代碼來源:JavaNetAuthenticator.java

示例11: startServer

import java.net.PasswordAuthentication; //導入依賴的package包/類
static BadAuthProxyServer startServer() throws IOException {
    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("xyz", "xyz".toCharArray());
        }
        });

    BadAuthProxyServer server = new BadAuthProxyServer(new ServerSocket(0));
    Thread serverThread = new Thread(server);
    serverThread.start();
    return server;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:HttpsProxyStackOverflow.java

示例12: tryLoadNTLMAuthentication

import java.net.PasswordAuthentication; //導入依賴的package包/類
/**
 * Loads the NTLM authentiation implementation through reflection. If
 * the class is present, then it must have the required constructors and
 * method. Otherwise, it is considered an error.
 */
@SuppressWarnings("unchecked")
private static NTLMAuthenticationProxy tryLoadNTLMAuthentication() {
    Class<? extends AuthenticationInfo> cl;
    Constructor<? extends AuthenticationInfo> fourArg, sixArg;
    try {
        cl = (Class<? extends AuthenticationInfo>)Class.forName(clazzStr, true, null);
        if (cl != null) {
            fourArg = cl.getConstructor(boolean.class,
                                         URL.class,
                                         PasswordAuthentication.class,
                                         String.class);
            sixArg = cl.getConstructor(boolean.class,
                                        String.class,
                                        int.class,
                                        PasswordAuthentication.class,
                                        String.class);
            supportsTA = cl.getDeclaredMethod(supportsTAStr);
            isTrustedSite = cl.getDeclaredMethod(isTrustedSiteStr, java.net.URL.class);
            return new NTLMAuthenticationProxy(fourArg,
                                               sixArg);
        }
    } catch (ClassNotFoundException cnfe) {
        finest(cnfe);
    } catch (ReflectiveOperationException roe) {
        throw new AssertionError(roe);
    }

    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:NTLMAuthenticationProxy.java

示例13: authenticate

import java.net.PasswordAuthentication; //導入依賴的package包/類
@Override public Request authenticate(Route route, Response response) throws IOException {
  List<Challenge> challenges = response.challenges();
  Request request = response.request();
  HttpUrl url = request.url();
  boolean proxyAuthorization = response.code() == 407;
  Proxy proxy = route.proxy();

  for (int i = 0, size = challenges.size(); i < size; i++) {
    Challenge challenge = challenges.get(i);
    if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue;

    PasswordAuthentication auth;
    if (proxyAuthorization) {
      InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
      auth = java.net.Authenticator.requestPasswordAuthentication(
          proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
          url.scheme(), challenge.realm(), challenge.scheme(), url.url(),
          RequestorType.PROXY);
    } else {
      auth = java.net.Authenticator.requestPasswordAuthentication(
          url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(),
          challenge.realm(), challenge.scheme(), url.url(), RequestorType.SERVER);
    }

    if (auth != null) {
      String credential = Credentials.basic(
          auth.getUserName(), new String(auth.getPassword()), challenge.charset());
      return request.newBuilder()
          .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential)
          .build();
    }
  }

  return null; // No challenges were satisfied!
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:JavaNetAuthenticator.java

示例14: getPasswordAuthentication

import java.net.PasswordAuthentication; //導入依賴的package包/類
public static PasswordAuthentication
getPasswordAuthentication(
	String		realm,
	URL			tracker )
{
	return( SESecurityManagerImpl.getSingleton().getPasswordAuthentication(realm, tracker));
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:8,代碼來源:SESecurityManager.java

示例15: store

import java.net.PasswordAuthentication; //導入依賴的package包/類
synchronized void store(String authscheme,
                        URI domain,
                        boolean proxy,
                        PasswordAuthentication value) {
    remove(authscheme, domain, proxy);
    entries.add(new CacheEntry(authscheme, domain, proxy, value));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:AuthenticationFilter.java


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