diff options
author | Simon Rettberg | 2017-07-31 16:42:51 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-07-31 16:42:51 +0200 |
commit | f60525b4783a4060781fa0deac2f47fb5b27d32f (patch) | |
tree | c23002de2c3da486147aa24815c3cbdc73ef5a06 /dozentenmodul/src/main/java/org/openslx/dozmod/util | |
parent | [client] Inform user about transfers that run independently of their client (diff) | |
download | tutor-module-f60525b4783a4060781fa0deac2f47fb5b27d32f.tar.gz tutor-module-f60525b4783a4060781fa0deac2f47fb5b27d32f.tar.xz tutor-module-f60525b4783a4060781fa0deac2f47fb5b27d32f.zip |
[client] Try thrift and https to master before deciding to skip proxy setup
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java index cadae6f8..1eb5def5 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java @@ -3,12 +3,16 @@ package org.openslx.dozmod.util; import java.net.ProxySelector; import java.text.MessageFormat; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.params.HttpParams; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.Priority; -import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.MasterServer; import org.openslx.dozmod.App; +import org.openslx.dozmod.authentication.ShibbolethEcp; import org.openslx.thrifthelper.ThriftManager; import com.btr.proxy.search.ProxySearch; @@ -22,6 +26,7 @@ import com.btr.proxy.util.Logger.LogLevel; * @author Jonathan Bauer */ +@SuppressWarnings("deprecation") public class ProxyConfigurator { /** @@ -43,13 +48,15 @@ public class ProxyConfigurator { masterClient.getOutputProtocol().getTransport().close(); } catch (Throwable e) { } - } catch (TException e) { + } catch (Exception e) { masterClient = null; } } // To be discussed: Let's bail out if the master server is reachable - if (masterClient != null) + if (masterClient != null && testHttpsMaster()) { + LOGGER.info("Not setting up proxy because master server seems reachable."); return; + } // first setup the logger of proxy_vole com.btr.proxy.util.Logger.setBackend(new LogBackEnd() { @@ -76,6 +83,7 @@ public class ProxyConfigurator { } }); + LOGGER.info("Master server not directly reachable; trying to determine proxy"); // try to find local proxy settings ProxySearch proxySearch = ProxySearch.getDefaultProxySearch(); ProxySelector myProxySelector = proxySearch.getProxySelector(); @@ -94,4 +102,24 @@ public class ProxyConfigurator { LOGGER.error("Could not find a suitable proxy!"); } } + + private static boolean testHttpsMaster() { + DefaultHttpClient client = new DefaultHttpClient(); + HttpParams params = client.getParams(); + params.setParameter("http.socket.timeout", 3000); + params.setParameter("http.connection.timeout", 3000); + params.setParameter("http.connection-manager.timeout", new Long(3000)); + params.setParameter("http.protocol.head-body-timeout", 3000); + HttpGet httpGet = new HttpGet(ShibbolethEcp.BWLP_SP.toString()); + httpGet.setHeader("Accept", "text/html, application/vnd.paos+xml"); + httpGet.setHeader("PAOS", "ver=\"urn:liberty:paos:2003-08\";\"urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp\""); + try { + HttpResponse response = client.execute(httpGet); + LOGGER.debug("Master server replies with " + response.getStatusLine().getStatusCode()); + return response.getStatusLine().getStatusCode() == 200; + } catch (Exception e) { + LOGGER.debug("Cannot reach master server via HTTPS", e); + return false; + } + } } |