Search in sources :

Example 96 with PasswordAuthentication

use of java.net.PasswordAuthentication in project goodies by sonatype.

the class JettyProxyProviderTest method testAuthAfterProxyAuthGet.

@Test
public void testAuthAfterProxyAuthGet() throws Exception {
    JettyProxyProvider proxy = new JettyProxyProvider("u", "p");
    proxy.addBehaviour("/*", new Debug(), new Content());
    proxy.addAuthentication("/*", "BASIC");
    proxy.addUser("user", "password");
    proxy.start();
    Authenticator.setDefault(new Authenticator() {

        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            if (getRequestingHost().equals("localhost")) {
                String password = "p";
                return new PasswordAuthentication("u", password.toCharArray());
            } else {
                String password = "password";
                return new PasswordAuthentication("user", password.toCharArray());
            }
        }
    });
    URL url = new URL("http://speutel.invalid/foo");
    SocketAddress sa = new InetSocketAddress("localhost", proxy.getPort());
    Proxy p = new Proxy(Type.HTTP, sa);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection(p);
    try {
        conn.setDoInput(true);
        conn.connect();
        assertEquals(200, conn.getResponseCode());
    } finally {
        conn.disconnect();
    }
}
Also used : Proxy(java.net.Proxy) HttpURLConnection(java.net.HttpURLConnection) Content(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Debug(org.sonatype.goodies.httpfixture.server.jetty.behaviour.Debug) Authenticator(java.net.Authenticator) URL(java.net.URL) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 97 with PasswordAuthentication

use of java.net.PasswordAuthentication in project stripe-java by stripe.

the class LiveStripeResponseGetter method createStripeConnection.

private static java.net.HttpURLConnection createStripeConnection(String url, RequestOptions options) throws IOException {
    URL stripeURL;
    String customURLStreamHandlerClassName = System.getProperty(CUSTOM_URL_STREAM_HANDLER_PROPERTY_NAME, null);
    if (customURLStreamHandlerClassName != null) {
        // instantiate the custom handler provided
        try {
            Class<URLStreamHandler> clazz = (Class<URLStreamHandler>) Class.forName(customURLStreamHandlerClassName);
            Constructor<URLStreamHandler> constructor = clazz.getConstructor();
            URLStreamHandler customHandler = constructor.newInstance();
            stripeURL = new URL(null, url, customHandler);
        } catch (ClassNotFoundException e) {
            throw new IOException(e);
        } catch (SecurityException e) {
            throw new IOException(e);
        } catch (NoSuchMethodException e) {
            throw new IOException(e);
        } catch (IllegalArgumentException e) {
            throw new IOException(e);
        } catch (InstantiationException e) {
            throw new IOException(e);
        } catch (IllegalAccessException e) {
            throw new IOException(e);
        } catch (InvocationTargetException e) {
            throw new IOException(e);
        }
    } else {
        stripeURL = new URL(url);
    }
    HttpURLConnection conn;
    if (Stripe.getConnectionProxy() != null) {
        conn = (HttpURLConnection) stripeURL.openConnection(Stripe.getConnectionProxy());
        Authenticator.setDefault(new Authenticator() {

            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return Stripe.getProxyCredential();
            }
        });
    } else {
        conn = (HttpURLConnection) stripeURL.openConnection();
    }
    conn.setConnectTimeout(options.getConnectTimeout());
    conn.setReadTimeout(options.getReadTimeout());
    conn.setUseCaches(false);
    for (Map.Entry<String, String> header : getHeaders(options).entrySet()) {
        conn.setRequestProperty(header.getKey(), header.getValue());
    }
    if (conn instanceof HttpsURLConnection) {
        ((HttpsURLConnection) conn).setSSLSocketFactory(socketFactory);
    }
    return conn;
}
Also used : IOException(java.io.IOException) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException) URLStreamHandler(java.net.URLStreamHandler) HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) Map(java.util.Map) Authenticator(java.net.Authenticator) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) PasswordAuthentication(java.net.PasswordAuthentication)

Example 98 with PasswordAuthentication

use of java.net.PasswordAuthentication in project sonar-go by SonarSource.

the class A method a.

private void a(char[] pwd, String var) {
    String variable1 = "blabla";
    // Noncompliant
    String variable2 = "login=a&password=xxx";
    // Noncompliant
    String variable3 = "login=a&passwd=xxx";
    // Noncompliant
    String variable4 = "login=a&pwd=xxx";
    String variable5 = "login=a&password=";
    String variable6 = "login=a&password= ";
    // Noncompliant
    String variableNameWithPasswordInIt = "xxx";
    // Noncompliant
    String variableNameWithPasswdInIt = "xxx";
    // Noncompliant
    String variableNameWithPwdInIt = "xxx";
    String otherVariableNameWithPasswordInIt;
    // Noncompliant
    fieldNameWithPasswordInIt = "xx";
    fieldNameWithPasswordInIt = retrievePassword();
    // Noncompliant
    this.fieldNameWithPasswordInIt = "xx";
    this.fieldNameWithPasswordInIt = retrievePassword();
    variable1 = "xx";
    String[] array = {};
    array[0] = "xx";
    A myA = new A();
    // XXXoncompliant - not supported in UAST rule
    myA.setProperty("password", "xxxxx");
    // XXXoncompliant - not supported in UAST rule
    myA.setProperty("passwd", "xxxxx");
    // XXXoncompliant - not supported in UAST rule
    myA.setProperty("pwd", "xxxxx");
    myA.setProperty("password", new Object());
    myA.setProperty("xxxxx", "password");
    myA.setProperty(12, "xxxxx");
    myA.setProperty(new Object(), new Object());
    // XXXoncompliant - not supported in UAST rule
    MyUnknownClass.myUnknownMethod("password", "xxxxx");
    PasswordAuthentication pa;
    // XXXoncompliant {{Remove this hard-coded password.}} - not supported in UAST rule
    pa = new PasswordAuthentication("userName", "1234".toCharArray());
    // Compliant
    pa = new PasswordAuthentication("userName", pwd);
    // Compliant
    pa = new PasswordAuthentication("userName", getPwd(var));
    // Compliant
    pa = new PasswordAuthentication("userName", var.toCharArray());
    OtherPasswordAuthentication opa;
    // Compliant
    opa = new OtherPasswordAuthentication("userName", "1234".toCharArray());
}
Also used : PasswordAuthentication(java.net.PasswordAuthentication)

Example 99 with PasswordAuthentication

use of java.net.PasswordAuthentication in project fess by codelibs.

the class FessProp method getHttpProxy.

default Proxy getHttpProxy() {
    Proxy proxy = (Proxy) propMap.get(HTML_PROXY);
    if (proxy == null) {
        if (StringUtil.isNotBlank(getHttpProxyHost()) && getHttpProxyPortAsInteger() != null) {
            final SocketAddress addr = new InetSocketAddress(getHttpProxyHost(), getHttpProxyPortAsInteger());
            proxy = new Proxy(Type.HTTP, addr);
            if (StringUtil.isNotBlank(getHttpProxyUsername())) {
                Authenticator.setDefault(new Authenticator() {

                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(getHttpProxyUsername(), getHttpProxyPassword().toCharArray());
                    }
                });
            }
        } else {
            proxy = Proxy.NO_PROXY;
        }
        propMap.put(HTML_PROXY, proxy);
    }
    return proxy;
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication)

Example 100 with PasswordAuthentication

use of java.net.PasswordAuthentication in project apjp by jvansteirteghem.

the class Main method onCreate.

public void onCreate() {
    try {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        APJP.APJP_KEY = sharedPreferences.getString("APJP_KEY", "");
        APJP.APJP_LOGGER_ID = "APJP";
        APJP.APJP_LOGGER_LEVEL = 1;
        APJP.APJP_LOCAL_PROXY_SERVER_ADDRESS = sharedPreferences.getString("APJP_LOCAL_PROXY_SERVER_ADDRESS", "");
        try {
            APJP.APJP_LOCAL_PROXY_SERVER_PORT = new Integer(sharedPreferences.getString("APJP_LOCAL_PROXY_SERVER_PORT", ""));
        } catch (Exception e) {
            APJP.APJP_LOCAL_PROXY_SERVER_PORT = 0;
        }
        APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_PROXY_SERVER";
        APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_LEVEL = 1;
        APJP.APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS = sharedPreferences.getString("APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS", "");
        try {
            APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = new Integer(sharedPreferences.getString("APJP_LOCAL_HTTP_PROXY_SERVER_PORT", ""));
        } catch (Exception e) {
            APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = 0;
        }
        APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_PROXY_SERVER";
        APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_LEVEL = 1;
        APJP.APJP_LOCAL_HTTP_SERVER_ADDRESS = sharedPreferences.getString("APJP_LOCAL_HTTP_SERVER_ADDRESS", "");
        try {
            APJP.APJP_LOCAL_HTTP_SERVER_PORT = new Integer(sharedPreferences.getString("APJP_LOCAL_HTTP_SERVER_PORT", ""));
        } catch (Exception e) {
            APJP.APJP_LOCAL_HTTP_SERVER_PORT = 0;
        }
        APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_SERVER";
        APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_LEVEL = 1;
        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL = new String[10];
        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
        for (int i = 0; i < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
            APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL[i] = sharedPreferences.getString("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_URL", "");
            for (int j = 0; j < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i][j] = sharedPreferences.getString("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE[i][j] = sharedPreferences.getString("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
            }
        }
        APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS = sharedPreferences.getString("APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS", "");
        try {
            APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = new Integer(sharedPreferences.getString("APJP_LOCAL_HTTPS_PROXY_SERVER_PORT", ""));
        } catch (Exception e) {
            APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = 0;
        }
        APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_PROXY_SERVER";
        APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_LEVEL = 1;
        APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS = sharedPreferences.getString("APJP_LOCAL_HTTPS_SERVER_ADDRESS", "");
        try {
            APJP.APJP_LOCAL_HTTPS_SERVER_PORT = new Integer(sharedPreferences.getString("APJP_LOCAL_HTTPS_SERVER_PORT", ""));
        } catch (Exception e) {
            APJP.APJP_LOCAL_HTTPS_SERVER_PORT = 0;
        }
        APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_SERVER";
        APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_LEVEL = 1;
        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL = new String[10];
        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
        for (int i = 0; i < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
            APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL[i] = sharedPreferences.getString("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_URL", "");
            for (int j = 0; j < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i][j] = sharedPreferences.getString("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE[i][j] = sharedPreferences.getString("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
            }
        }
        APJP.APJP_HTTP_PROXY_SERVER_ADDRESS = sharedPreferences.getString("APJP_HTTP_PROXY_SERVER_ADDRESS", "");
        try {
            APJP.APJP_HTTP_PROXY_SERVER_PORT = new Integer(sharedPreferences.getString("APJP_HTTP_PROXY_SERVER_PORT", ""));
        } catch (Exception e) {
            APJP.APJP_HTTP_PROXY_SERVER_PORT = 0;
        }
        APJP.APJP_HTTP_PROXY_SERVER_USERNAME = sharedPreferences.getString("APJP_HTTP_PROXY_SERVER_USERNAME", "");
        APJP.APJP_HTTP_PROXY_SERVER_PASSWORD = sharedPreferences.getString("APJP_HTTP_PROXY_SERVER_PASSWORD", "");
        APJP.APJP_HTTPS_PROXY_SERVER_ADDRESS = sharedPreferences.getString("APJP_HTTPS_PROXY_SERVER_ADDRESS", "");
        try {
            APJP.APJP_HTTPS_PROXY_SERVER_PORT = new Integer(sharedPreferences.getString("APJP_HTTPS_PROXY_SERVER_PORT", ""));
        } catch (Exception e) {
            APJP.APJP_HTTPS_PROXY_SERVER_PORT = 0;
        }
        APJP.APJP_HTTPS_PROXY_SERVER_USERNAME = sharedPreferences.getString("APJP_HTTPS_PROXY_SERVER_USERNAME", "");
        APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD = sharedPreferences.getString("APJP_HTTPS_PROXY_SERVER_PASSWORD", "");
        APJP.APJP_APPLICATION = getApplication();
        Authenticator.setDefault(new Authenticator() {

            protected PasswordAuthentication getPasswordAuthentication() {
                PasswordAuthentication passwordAuthentication = null;
                if (this.getRequestorType() == Authenticator.RequestorType.PROXY) {
                    if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTP") == true) {
                        passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTP_PROXY_SERVER_USERNAME, APJP.APJP_HTTP_PROXY_SERVER_PASSWORD.toCharArray());
                    } else {
                        if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTPS") == true) {
                            passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTPS_PROXY_SERVER_USERNAME, APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD.toCharArray());
                        }
                    }
                }
                return passwordAuthentication;
            }
        });
        logger = Logger.getLogger(APJP.APJP_LOGGER_ID);
        proxyServer = new ProxyServer();
    } catch (Exception e) {
        logger.log(1, "EXCEPTION", e);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication)

Aggregations

PasswordAuthentication (java.net.PasswordAuthentication)108 Authenticator (java.net.Authenticator)52 URL (java.net.URL)27 InetSocketAddress (java.net.InetSocketAddress)22 Proxy (java.net.Proxy)19 Test (org.junit.Test)16 HttpURLConnection (java.net.HttpURLConnection)11 InetAddress (java.net.InetAddress)11 URI (java.net.URI)10 MalformedURLException (java.net.MalformedURLException)9 File (java.io.File)8 IOException (java.io.IOException)8 SocketAddress (java.net.SocketAddress)8 UnknownHostException (java.net.UnknownHostException)6 PrivilegedActionException (java.security.PrivilegedActionException)6 InputStream (java.io.InputStream)5 SocketTimeoutException (java.net.SocketTimeoutException)5 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)5 HttpRetryException (java.net.HttpRetryException)4 ProtocolException (java.net.ProtocolException)4