当前位置: 首页>>代码示例>>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;未经允许,请勿转载。