I am deploying the application in a Tomcat 8.5 . This tomcat runs behind a proxy. If I use eclipse, the application runs properly, but not in Tomcat. I have seen that if I get authenticated using a web browser, the application runs ok while the authentication still remains. Once it is expired, I need to provide the credentials again.
I've tried to provide this information via code and have also added these lines to the catalina.bat:
http.proxyHost=proxy.myproxy.es
http.proxyPort=8080
http.proxyUser=USERNAME
http.proxyPassword=PWD
System.setProperty("http.proxyHost", PROXY_SERVER);
System.setProperty("http.proxyPort", PROXY_PORT.toString());
System.setProperty("https.proxyHost", PROXY_SERVER);
System.setProperty("https.proxyPort", PROXY_PORT.toString());
System.setProperty("http.proxyUser", PROXY_USER);
System.setProperty("http.proxyPassword", PROXY_PASSWORD);
System.setProperty("http.proxySet", "true");
// AUTENTICAMOS EL PROXY
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType() == RequestorType.PROXY) {
String prot = getRequestingProtocol().toLowerCase();
String host = System.getProperty(prot + ".proxyHost", PROXY_SERVER);
String port = System.getProperty(prot + ".proxyPort",PROXY_PORT.toString());
String user = System.getProperty(prot + ".proxyUser", PROXY_USER);
String password = System.getProperty(prot + ".proxyPassword", PROXY_PASSWORD);
if (getRequestingHost().equalsIgnoreCase(host)) {
if (Integer.parseInt(port) == getRequestingPort()) {
return new PasswordAuthentication(user, password.toCharArray());
}
}
}
return null;
}
});
I need this authentication to run automatically.
EDIT: This proxy should be used by a 3rd party class. If i create a new connection to a random URL like google.com, and then make a request with the 3rd party class, it works properly, so I assume that it is not using the Authenticator.setDefault. Any ideas of what is happening?
Finnaly there is a bug with the 3rd party class. Closed
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.