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();
}
}
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;
}
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());
}
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;
}
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);
}
}
Aggregations