From d512a805133d83ca55eb8d72da6ff61c44509e3b Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Fri, 13 Apr 2018 10:11:49 +0200
Subject: Remove unused proxy-vole classes
---
pom.xml | 6 --
.../org/openslx/network/ProxyConfiguration.java | 72 -------------
.../java/org/openslx/network/ProxyProperties.java | 89 ----------------
.../openslx/network/StaticProxyAuthenticator.java | 23 -----
.../org/openslx/network/StaticProxySelector.java | 115 ---------------------
5 files changed, 305 deletions(-)
delete mode 100644 src/main/java/org/openslx/network/ProxyConfiguration.java
delete mode 100644 src/main/java/org/openslx/network/ProxyProperties.java
delete mode 100644 src/main/java/org/openslx/network/StaticProxyAuthenticator.java
delete mode 100644 src/main/java/org/openslx/network/StaticProxySelector.java
diff --git a/pom.xml b/pom.xml
index 42e5adf..6527be3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -104,12 +104,6 @@
1.7.25
compile
-
- org.openslx
- proxy_vole
- 0.0.3-SNAPSHOT
- compile
-
com.google.code.gson
gson
diff --git a/src/main/java/org/openslx/network/ProxyConfiguration.java b/src/main/java/org/openslx/network/ProxyConfiguration.java
deleted file mode 100644
index ecf800f..0000000
--- a/src/main/java/org/openslx/network/ProxyConfiguration.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.openslx.network;
-
-import java.net.Authenticator;
-import java.net.InetSocketAddress;
-import java.net.Proxy;
-import java.net.ProxySelector;
-
-import org.apache.log4j.Logger;
-
-import com.btr.proxy.search.wpad.WpadProxySearchStrategy;
-
-/**
- * Class for configuring proxy settings system wide, if necessary.
- *
- * @author bjoern
- *
- */
-public class ProxyConfiguration
-{
- private static final Logger log = Logger.getLogger( ProxyConfiguration.class );
-
- public static void configProxy()
- {
- // Reset proxy settings first
- ProxySelector.setDefault( null );
- Authenticator.setDefault( null );
-
- // Configuring proxy settings. First read options from config file.
- ProxyProperties.load();
- String proxyConfiguration = ProxyProperties.getProxyConf();
-
- if ( proxyConfiguration.equals( "AUTO" ) || proxyConfiguration.isEmpty() ) {
- log.info( "Configuring proxy settings automatically..." );
- // Configuring proxy settings automatically.
- WpadProxySearchStrategy wPSS = new WpadProxySearchStrategy();
- try {
- ProxySelector pS = wPSS.getProxySelector();
- ProxySelector.setDefault( pS );
- } catch ( Throwable e ) {
- log.error( "Setting proxy configuration automatically failed.", e );
- }
- return;
- }
-
- if ( proxyConfiguration.equals( "YES" ) ) {
- // Take the proxy settings from config file.
- // First check if one of the following necessary options might not be set.
- if ( ProxyProperties.hasProxyAddress() ) {
- String proxyAddress = ProxyProperties.getProxyAddress();
- int proxyPort = ProxyProperties.getProxyPort();
-
- // Configure proxy.
- Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) );
- StaticProxySelector sPS = new StaticProxySelector( proxy );
- ProxySelector.setDefault( sPS );
-
- if ( !ProxyProperties.hasProxyCredentials() ) {
- log.info( "Configuring proxy settings manually WITH authentication..." );
- // use Proxy with authentication.
- String proxyUname = ProxyProperties.getProxyUsername();
- String proxyPass = ProxyProperties.getProxyPassword();
-
- // Set authentication.
- StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass );
- Authenticator.setDefault( sPA );
- }
- }
- }
-
- }
-
-}
diff --git a/src/main/java/org/openslx/network/ProxyProperties.java b/src/main/java/org/openslx/network/ProxyProperties.java
deleted file mode 100644
index 5dacc57..0000000
--- a/src/main/java/org/openslx/network/ProxyProperties.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.openslx.network;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.Properties;
-
-import org.apache.log4j.Logger;
-import org.openslx.util.Util;
-
-public class ProxyProperties
-{
- private static Logger log = Logger.getLogger( ProxyProperties.class );
- private static final Properties properties = new Properties();
-
- // Getting the proxy settings from config file stored in
- // "/opt/openslx/proxy/conf".
- public static String getProxyConf()
- {
- return properties.getProperty( "PROXY_CONF", "" );
- }
-
- public static String getProxyAddress()
- {
- return properties.getProperty( "PROXY_ADDR", "" );
- }
-
- public static String getProxyUsername()
- {
- return properties.getProperty( "PROXY_USERNAME", "" );
- }
-
- public static String getProxyPassword()
- {
- return properties.getProperty( "PROXY_PASSWORD", "" );
- }
-
- // Integers //
- public static int getProxyPort()
- {
- return Util.parseInt( properties.getProperty( "PROXY_PORT", "0" ), 0 );
- }
-
- static
- {
- load();
- }
-
- /**
- * Load properties
- */
- public static void load()
- {
- InputStreamReader stream = null;
- try {
- properties.clear();
- // Load all entries of the config file into properties
- stream = new InputStreamReader(
- new FileInputStream( "/opt/openslx/proxy/config" ), StandardCharsets.UTF_8 );
- properties.load( stream );
- stream.close();
- } catch ( IOException e ) {
- log.warn( "Could not load proxy properties from '/opt/openslx/proxy/conf'." );
- } finally {
- Util.safeClose( stream );
- }
- }
-
- /**
- * Check proxy settings for being not empty.
- *
- * @return true if address and port are set
- */
- public static boolean hasProxyAddress()
- {
- return !getProxyAddress().isEmpty() && getProxyPort() != 0;
- }
-
- /**
- * Check if a username or password is configured.
- *
- * @return true if either username or password (or both) are set
- */
- public static boolean hasProxyCredentials()
- {
- return !getProxyUsername().isEmpty() || !getProxyPassword().isEmpty();
- }
-}
diff --git a/src/main/java/org/openslx/network/StaticProxyAuthenticator.java b/src/main/java/org/openslx/network/StaticProxyAuthenticator.java
deleted file mode 100644
index c1d8da7..0000000
--- a/src/main/java/org/openslx/network/StaticProxyAuthenticator.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.openslx.network;
-
-import java.net.Authenticator;
-import java.net.PasswordAuthentication;
-
-public class StaticProxyAuthenticator extends Authenticator
-{
- private final String username, password;
-
- public StaticProxyAuthenticator( String username, String password )
- {
- this.username = username;
- this.password = password;
- }
-
- protected PasswordAuthentication getPasswordAuthentication()
- {
- if ( getRequestorType() != RequestorType.PROXY )
- return super.getPasswordAuthentication();
- return new PasswordAuthentication(
- this.username, this.password.toCharArray() );
- }
-}
diff --git a/src/main/java/org/openslx/network/StaticProxySelector.java b/src/main/java/org/openslx/network/StaticProxySelector.java
deleted file mode 100644
index d7d76ac..0000000
--- a/src/main/java/org/openslx/network/StaticProxySelector.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package org.openslx.network;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.Proxy;
-import java.net.ProxySelector;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-
-public class StaticProxySelector extends ProxySelector
-{
- private static Logger log = Logger.getLogger( StaticProxySelector.class );
-
- private final Proxy proxy;
- private Set localAddresses = null;
- private long nextAddressGet = 0;
-
- public StaticProxySelector( Proxy proxy )
- {
- this.proxy = proxy;
- }
-
- @Override
- public void connectFailed( URI uri, SocketAddress sa, IOException ioe )
- {
- // Just one fix proxy. So no code is necessary here for deactivating proxy.
- }
-
- @Override
- public List select( URI uri )
- {
- List proxyList = new ArrayList();
-
- String host = uri.getHost();
- if ( host == null ) // Host not set? Well, we can only guess then, so try to use the proxy
- return proxyList;
-
- host = host.replaceFirst( "%\\d+$", "" );
- if ( host.equals( "localhost" ) || host.startsWith( "127." )
- || host.startsWith( "::1" ) || host.startsWith( "0:0:0:0:0:0:0:1" ) ) // Localhost = no proxy
- return proxyList;
-
- final Set addrs;
- synchronized ( this ) {
- addrs = getLocalAddresses();
- }
- if ( !addrs.contains( host ) ) {
- proxyList.add( this.proxy );
- }
-
- return proxyList;
- }
-
- /**
- * Get all local (IP) addresses
- *
- * @return
- */
- private Set getLocalAddresses()
- {
- long now = System.currentTimeMillis();
- if ( now < nextAddressGet )
- return localAddresses;
- nextAddressGet = now + 60000;
-
- List interfaces = getNetworkInterfaces();
- if ( interfaces == null )
- return localAddresses; // Fallback on last known data
- // iterate over network interfaces and get all addresses
- Set addrs = new HashSet<>();
- for ( NetworkInterface iface : interfaces ) {
- Enumeration e = iface.getInetAddresses();
- // iterate over InetAddresses of current interface
- while ( e.hasMoreElements() ) {
- addrs.add( e.nextElement().getHostAddress().replaceFirst( "%\\d+$", "" ) );
- }
- }
- synchronized ( this ) {
- localAddresses = addrs;
- }
- return localAddresses;
- }
-
- /**
- * Get a list of all local network interfaces
- *
- * @return
- */
- private List getNetworkInterfaces()
- {
- ArrayList retList = new ArrayList();
- Enumeration e = null;
- try {
- e = NetworkInterface.getNetworkInterfaces();
- } catch ( SocketException e1 ) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- return null;
- }
- while ( e.hasMoreElements() ) {
- retList.add( e.nextElement() );
- }
- return retList;
- }
-
-}
--
cgit v1.2.3-55-g7522