java.net.PasswordAuthentication源码实例Demo

java.net.HttpRetryException#java.net.PasswordAuthentication源码实例Demo

下面列出了java.net.HttpRetryException#java.net.PasswordAuthentication 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: HttpURLConnection.java
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;
            }
        });
}
 
源代码2 项目: netbeans   文件: SvnClientExceptionHandler.java
private boolean handleKenaiAuthorization(SvnKenaiAccessor support, String url) {
    PasswordAuthentication pa = support.getPasswordAuthentication(url, true);
    if(pa == null) {
        return false;
    }

    String user = pa.getUserName();
    char[] password = pa.getPassword();
    
    adapter.setUsername(user != null ? user : "");
    if (connectionType != ConnectionType.javahl) {
        adapter.setPassword(password != null ? new String(password) : "");
    }

    return true;
}
 
源代码3 项目: openjdk-jdk8u   文件: NegotiateCallbackHandler.java
private void getAnswer() {
    if (!answered) {
        answered = true;

        if (LoginConfigImpl.HTTP_USE_GLOBAL_CREDS) {
            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 项目: intellij-quarkus   文件: MavenWrapperDownloader.java
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
    if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
        String username = System.getenv("MVNW_USERNAME");
        char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });
    }
    URL website = new URL(urlString);
    ReadableByteChannel rbc;
    rbc = Channels.newChannel(website.openStream());
    FileOutputStream fos = new FileOutputStream(destination);
    fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    fos.close();
    rbc.close();
}
 
源代码5 项目: intellij-quarkus   文件: MavenWrapperDownloader.java
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
    if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
        String username = System.getenv("MVNW_USERNAME");
        char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });
    }
    URL website = new URL(urlString);
    ReadableByteChannel rbc;
    rbc = Channels.newChannel(website.openStream());
    FileOutputStream fos = new FileOutputStream(destination);
    fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    fos.close();
    rbc.close();
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: NTLMAuthentication.java
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();
}
 
源代码7 项目: TencentKona-8   文件: HttpURLConnection.java
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;
            }
        });
}
 
源代码8 项目: openjdk-jdk8u   文件: NTLMAuthentication.java
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();
}
 
源代码9 项目: ripme   文件: Proxy.java
/**
 * Set a Socks Proxy Server (globally).
 *
 * @param fullsocks the socks server, using format [user:password]@host[:port]
 */
public static void setSocks(String fullsocks) {

    Map<String, String> socksServer = parseServer(fullsocks);
    if (socksServer.get("user") != null && socksServer.get("password") != null) {
        Authenticator.setDefault(new Authenticator(){
            protected PasswordAuthentication  getPasswordAuthentication(){
                PasswordAuthentication p = new PasswordAuthentication(socksServer.get("user"), socksServer.get("password").toCharArray());
                return p;
            }
        });
        System.setProperty("java.net.socks.username", socksServer.get("user"));
        System.setProperty("java.net.socks.password", socksServer.get("password"));
    }
    if (socksServer.get("port") != null) {
        System.setProperty("socksProxyPort", socksServer.get("port"));
    }

    System.setProperty("socksProxyHost", socksServer.get("server"));
}
 
源代码10 项目: ripme   文件: Proxy.java
/**
 * Set a HTTP Proxy.
 * WARNING: Authenticated HTTP Proxy won't work from jdk1.8.111 unless
 * passing the flag -Djdk.http.auth.tunneling.disabledSchemes="" to java
 * see https://stackoverflow.com/q/41505219
 *
 * @param fullproxy the proxy, using format [user:password]@host[:port]
 */
public static void setHTTPProxy(String fullproxy) {
    Map<String, String> proxyServer = parseServer(fullproxy);

    if (proxyServer.get("user") != null && proxyServer.get("password") != null) {
        Authenticator.setDefault(new Authenticator(){
            protected PasswordAuthentication  getPasswordAuthentication(){
                PasswordAuthentication p = new PasswordAuthentication(proxyServer.get("user"), proxyServer.get("password").toCharArray());
                return p;
            }
        });
        System.setProperty("http.proxyUser", proxyServer.get("user"));
        System.setProperty("http.proxyPassword", proxyServer.get("password"));
        System.setProperty("https.proxyUser", proxyServer.get("user"));
        System.setProperty("https.proxyPassword", proxyServer.get("password"));
    }

    if (proxyServer.get("port") != null) {
        System.setProperty("http.proxyPort", proxyServer.get("port"));
        System.setProperty("https.proxyPort", proxyServer.get("port"));
    }

    System.setProperty("http.proxyHost", proxyServer.get("server"));
    System.setProperty("https.proxyHost", proxyServer.get("server"));
}
 
源代码11 项目: xdm   文件: XDMApp.java
private PasswordAuthentication getCredential(String msg, boolean proxy) {
	JTextField user = new JTextField(30);
	JPasswordField pass = new JPasswordField(30);

	String prompt = proxy ? StringResource.get("PROMPT_PROXY")
			: String.format(StringResource.get("PROMPT_SERVER"), msg);

	Object[] obj = new Object[5];
	obj[0] = prompt;
	obj[1] = StringResource.get("DESC_USER");
	obj[2] = user;
	obj[3] = StringResource.get("DESC_PASS");
	obj[4] = pass;

	if (JOptionPane.showOptionDialog(null, obj, StringResource.get("PROMPT_CRED"), JOptionPane.OK_CANCEL_OPTION,
			JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) {
		PasswordAuthentication pauth = new PasswordAuthentication(user.getText(), pass.getPassword());
		return pauth;
	}
	return null;
}
 
源代码12 项目: webi   文件: Webi.java
public Webi setProxy(String host, int port, final String username, final String password) {
    webService.is_proxy_seted = true;
    webService.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", String.valueOf(port));
    System.setProperty("http.proxyUser", username);
    System.setProperty("http.proxyPassword", password);

    Authenticator.setDefault(
            new Authenticator() {
                public PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password.toCharArray());
                }
            }
    );
    return this;
}
 
源代码13 项目: jdk8u-jdk   文件: AuthenticationInfo.java
private void readObject(ObjectInputStream s)
    throws IOException, ClassNotFoundException
{
    s.defaultReadObject ();
    pw = new PasswordAuthentication (s1, s2.toCharArray());
    s1 = null; s2= null;
}
 
源代码14 项目: openjdk-jdk9   文件: BasicAuthentication.java
/**
 * Create a BasicAuthentication
 */
public BasicAuthentication(boolean isProxy, URL url, String realm,
                           PasswordAuthentication pw,
                           String authenticatorKey) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
          AuthScheme.BASIC, url, realm,
          Objects.requireNonNull(authenticatorKey));
    String plain = pw.getUserName() + ":";
    byte[] nameBytes = null;
    try {
        nameBytes = plain.getBytes("ISO-8859-1");
    } catch (java.io.UnsupportedEncodingException uee) {
        assert false;
    }

    // get password bytes
    char[] passwd = pw.getPassword();
    byte[] passwdBytes = new byte[passwd.length];
    for (int i=0; i<passwd.length; i++)
        passwdBytes[i] = (byte)passwd[i];

    // concatenate user name and password bytes and encode them
    byte[] concat = new byte[nameBytes.length + passwdBytes.length];
    System.arraycopy(nameBytes, 0, concat, 0, nameBytes.length);
    System.arraycopy(passwdBytes, 0, concat, nameBytes.length,
                     passwdBytes.length);
    this.auth = "Basic " + Base64.getEncoder().encodeToString(concat);
    this.pw = pw;
}
 
源代码15 项目: openjdk-jdk9   文件: NTLMAuthentication.java
/**
* Constructor used for proxy entries
*/
public NTLMAuthentication(boolean isProxy, String host, int port,
                          PasswordAuthentication pw,
                          String authenticatorKey) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
            AuthScheme.NTLM,
            host,
            port,
            "",
            Objects.requireNonNull(authenticatorKey));
    init (pw);
}
 
源代码16 项目: BiglyBT   文件: SESecurityManager.java
public static PasswordAuthentication
getPasswordAuthentication(
	String		realm,
	URL			tracker )
{
	return( SESecurityManagerImpl.getSingleton().getPasswordAuthentication(realm, tracker));
}
 
源代码17 项目: jdk8u60   文件: DigestAuthentication.java
public DigestAuthentication(boolean isProxy, String host, int port, String realm,
                            String authMethod, PasswordAuthentication pw,
                            Parameters params) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
          AuthScheme.DIGEST,
          host,
          port,
          realm);
    this.authMethod = authMethod;
    this.pw = pw;
    this.params = params;
}
 
源代码18 项目: dragonwell8_jdk   文件: NTLMAuthenticationProxy.java
AuthenticationInfo create(boolean isProxy,
                          String host,
                          int port,
                          PasswordAuthentication pw) {
    try {
        return fiveArgCtr.newInstance(isProxy, host, port, pw);
    } catch (ReflectiveOperationException roe) {
        finest(roe);
    }

    return null;
}
 
源代码19 项目: jdk8u-jdk   文件: NTLMAuthenticationProxy.java
AuthenticationInfo create(boolean isProxy,
                          URL url,
                          PasswordAuthentication pw) {
    try {
        return threeArgCtr.newInstance(isProxy, url, pw);
    } catch (ReflectiveOperationException roe) {
        finest(roe);
    }

    return null;
}
 
源代码20 项目: dragonwell8_jdk   文件: BasicAuthentication.java
/**
 * Create a BasicAuthentication
 */
public BasicAuthentication(boolean isProxy, String host, int port,
                           String realm, PasswordAuthentication pw) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
          AuthScheme.BASIC, host, port, realm);
    String plain = pw.getUserName() + ":";
    byte[] nameBytes = null;
    try {
        nameBytes = plain.getBytes("ISO-8859-1");
    } catch (java.io.UnsupportedEncodingException uee) {
        assert false;
    }

    // get password bytes
    char[] passwd = pw.getPassword();
    byte[] passwdBytes = new byte[passwd.length];
    for (int i=0; i<passwd.length; i++)
        passwdBytes[i] = (byte)passwd[i];

    // concatenate user name and password bytes and encode them
    byte[] concat = new byte[nameBytes.length + passwdBytes.length];
    System.arraycopy(nameBytes, 0, concat, 0, nameBytes.length);
    System.arraycopy(passwdBytes, 0, concat, nameBytes.length,
                     passwdBytes.length);
    this.auth = "Basic " + Base64.getEncoder().encodeToString(concat);
    this.pw = pw;
}
 
源代码21 项目: dragonwell8_jdk   文件: BasicAuthentication.java
/**
 * Create a BasicAuthentication
 */
public BasicAuthentication(boolean isProxy, URL url, String realm,
                               PasswordAuthentication pw) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
          AuthScheme.BASIC, url, realm);
    String plain = pw.getUserName() + ":";
    byte[] nameBytes = null;
    try {
        nameBytes = plain.getBytes("ISO-8859-1");
    } catch (java.io.UnsupportedEncodingException uee) {
        assert false;
    }

    // get password bytes
    char[] passwd = pw.getPassword();
    byte[] passwdBytes = new byte[passwd.length];
    for (int i=0; i<passwd.length; i++)
        passwdBytes[i] = (byte)passwd[i];

    // concatenate user name and password bytes and encode them
    byte[] concat = new byte[nameBytes.length + passwdBytes.length];
    System.arraycopy(nameBytes, 0, concat, 0, nameBytes.length);
    System.arraycopy(passwdBytes, 0, concat, nameBytes.length,
                     passwdBytes.length);
    this.auth = "Basic " + Base64.getEncoder().encodeToString(concat);
    this.pw = pw;
}
 
源代码22 项目: dragonwell8_jdk   文件: NTLMAuthentication.java
/**
 * Create a NTLMAuthentication:
 * Username may be specified as domain<BACKSLASH>username in the application Authenticator.
 * If this notation is not used, then the domain will be taken
 * from a system property: "http.auth.ntlm.domain".
 */
public NTLMAuthentication(boolean isProxy, URL url, PasswordAuthentication pw) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
          AuthScheme.NTLM,
          url,
          "");
    init (pw);
}
 
源代码23 项目: openjdk-jdk8u-backup   文件: NTLMAuthentication.java
/**
 * Create a NTLMAuthentication:
 * Username may be specified as domain<BACKSLASH>username in the application Authenticator.
 * If this notation is not used, then the domain will be taken
 * from a system property: "http.auth.ntlm.domain".
 */
public NTLMAuthentication(boolean isProxy, URL url, PasswordAuthentication pw) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
          AuthScheme.NTLM,
          url,
          "");
    init (pw);
}
 
源代码24 项目: openjdk-jdk9   文件: NTLMAuthWithSM.java
@Override
public PasswordAuthentication getPasswordAuthentication() {
    System.out.println("getPasswordAuthentication() called, scheme: "
            + getRequestingScheme());
    if (getRequestingScheme().equalsIgnoreCase("ntlm")) {
        return new PasswordAuthentication("test", "test".toCharArray());
    }
    return null;
}
 
源代码25 项目: openjdk-jdk9   文件: NTLMAuthentication.java
/**
* Constructor used for proxy entries
*/
public NTLMAuthentication(boolean isProxy, String host, int port,
                          PasswordAuthentication pw,
                          String authenticatorKey) {
    super(isProxy?PROXY_AUTHENTICATION:SERVER_AUTHENTICATION,
          AuthScheme.NTLM,
          host,
          port,
          "",
          Objects.requireNonNull(authenticatorKey));
    init (pw);
}
 
源代码26 项目: dragonwell8_jdk   文件: NTLMAuthentication.java
/**
* Constructor used for proxy entries
*/
public NTLMAuthentication(boolean isProxy, String host, int port,
                            PasswordAuthentication pw) {
    super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
            AuthScheme.NTLM,
            host,
            port,
            "");
    init (pw);
}
 
源代码27 项目: dragonwell8_jdk   文件: HttpsProxyStackOverflow.java
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;
}
 
源代码28 项目: netbeans   文件: NetworkSettingsTest.java
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]);
}
 
源代码29 项目: openjdk-jdk9   文件: HttpsProxyStackOverflow.java
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;
}
 
源代码30 项目: netbeans   文件: NbAuthenticator.java
@Override
protected PasswordAuthentication getPasswordAuthentication() {
    Logger.getLogger(NbAuthenticator.class.getName()).log(Level.FINER, "Authenticator.getPasswordAuthentication() with prompt " + this.getRequestingPrompt()); //NOI18N

    if (RequestorType.PROXY == getRequestorType() && ProxySettings.useAuthentication()) {
        Logger.getLogger(NbAuthenticator.class.getName()).log(Level.FINER, "Username set to " + ProxySettings.getAuthenticationUsername() + " while request " + this.getRequestingURL()); //NOI18N
        return new java.net.PasswordAuthentication(ProxySettings.getAuthenticationUsername(), ProxySettings.getAuthenticationPassword());
    } else {
        if (System.currentTimeMillis() - lastTry > TIMEOUT) {
            if (getRequestingProtocol().startsWith("SOCKS")&&(ProxySettings.getAuthenticationUsername().length()>0)) { //NOI18N
                return new java.net.PasswordAuthentication(ProxySettings.getAuthenticationUsername(), ProxySettings.getAuthenticationPassword());
            }
            if (NetworkSettings.isAuthenticationDialogSuppressed()) {
                return null;
            }
            PasswordAuthentication auth = getAuthenticationFromURL();
            if (auth != null) {
                return auth;
            }
            NbAuthenticatorPanel ui = new NbAuthenticatorPanel(getRequestingPrompt());
            Object result = DialogDisplayer.getDefault().notify(
                    new DialogDescriptor(ui, NbBundle.getMessage(NbAuthenticator.class, "CTL_Authentication"))); //NOI18N
            if (DialogDescriptor.OK_OPTION == result) {
                lastTry = 0;
                return new PasswordAuthentication(ui.getUserName(), ui.getPassword());
            } else {
                lastTry = System.currentTimeMillis();
            }
        }
    }

    Logger.getLogger(NbAuthenticator.class.getName()).log(Level.WARNING, "No authentication set while requesting " + this.getRequestingURL()); //NOI18N
    return null;
}