Class OsxProxySearchStrategy

java.lang.Object
com.github.markusbernhardt.proxy.search.desktop.osx.OsxProxySearchStrategy
All Implemented Interfaces:
ProxySearchStrategy

public class OsxProxySearchStrategy extends Object implements ProxySearchStrategy
Loads the OSX system proxy settings from the settings file.

All settings are stored in OSX in a special XML file format. These settings file are named plist files and contain nested dictionaries, arrays and values.

To parse this file we use a parser that is derived from a plist parser that comes with the xmlwise XML parser package:

http://code.google.com/p/xmlwise/

I modified that parser to work with the default Java XML parsing library.

The plist file is located on OSX at:

/Library/Preferences/SystemConfiguration/preferences.plist

  • Field Details

  • Constructor Details

    • OsxProxySearchStrategy

      public OsxProxySearchStrategy()
      ProxySelector
      See Also:
  • Method Details

    • getProxySelector

      public ProxySelector getProxySelector() throws ProxyException
      Loads the proxy settings and initializes a proxy selector for the OSX proxy settings.
      Specified by:
      getProxySelector in interface ProxySearchStrategy
      Returns:
      a configured ProxySelector, null if none is found.
      Throws:
      ProxyException - on file reading error.
    • getName

      public String getName()
      Gets the printable name of the search strategy.
      Specified by:
      getName in interface ProxySearchStrategy
      Returns:
      the printable name of the search strategy
    • buildSelector

      private ProxySelector buildSelector(PListParser.Dict proxySettings) throws ProxyException
      Build a selector from the given settings.
      Parameters:
      proxySettings - to parse
      Returns:
      the configured selector
      Throws:
      ProxyException - on error
    • getNetworkInterfaces

      private List<String> getNetworkInterfaces() throws SocketException
      Create a list of Ethernet interfaces that are connected
      Returns:
      a list of available interface names
      Throws:
      SocketException
    • isInterfaceAllowed

      private boolean isInterfaceAllowed(NetworkInterface ni) throws SocketException
      Check if a given network interface is interesting for us.
      Parameters:
      ni - the interface to check
      Returns:
      true if accepted else false.
      Throws:
      SocketException - on error.
    • getSettingsFile

      private File getSettingsFile()
      Gets the settings file to parse the settings from.
      Returns:
      the settings file.
    • installSimpleHostFilter

      private ProxySelector installSimpleHostFilter(PListParser.Dict proxySettings, ProxySelector result)
      Install a filter to ignore simple host names without domain name.
      Parameters:
      proxySettings - the dictionary containing all settings
      result - the proxy selector that needs to be adapted.
      Returns:
      a wrapped proxy selector that will ignore simple names.
    • installExceptionList

      private ProxySelector installExceptionList(PListParser.Dict proxySettings, ProxySelector result)
      Install a host name base filter to handle the proxy exclude list.
      Parameters:
      proxySettings - the dictionary containing all settings
      result - the proxy selector that needs to be adapted.
      Returns:
      a wrapped proxy selector that will handle the exclude list.
    • toCommaSeparatedString

      private String toCommaSeparatedString(List<?> proxyExceptions)
      Convert a list to a comma separated list.
      Parameters:
      proxyExceptions - list of elements.
      Returns:
      a comma separated string of the list's content.
    • autodetectProxyIfAvailable

      private ProxySelector autodetectProxyIfAvailable(PListParser.Dict proxySettings, ProxySelector result) throws ProxyException
      Invoke WPAD proxy detection if configured.
      Parameters:
      proxySettings - the settings to analyse.
      result - the current proxy selector.
      Returns:
      a WPAD proxy selector or the passed in proxy selector.
      Throws:
      ProxyException - on automatic detection errors.
    • installPacProxyIfAvailable

      private ProxySelector installPacProxyIfAvailable(PListParser.Dict proxySettings, ProxySelector result)
      Use a PAC based proxy selector if configured.
      Parameters:
      proxySettings - the settings to analyse.
      result - the current proxy selector.
      Returns:
      a PAC proxy selector or the passed in proxy selector.
    • installSocksProxy

      private void installSocksProxy(PListParser.Dict proxySettings, ProtocolDispatchSelector ps)
      Build a socks proxy and set it for the socks protocol.
      Parameters:
      proxySettings - to read the config values from.
      ps - the ProtocolDispatchSelector to install the new proxy on.
    • installSelectorForProtocol

      private void installSelectorForProtocol(PListParser.Dict proxySettings, ProtocolDispatchSelector ps, String protocol)
      Installs a proxy selector for the given protocoll on the ProtocolDispatchSelector
      Parameters:
      proxySettings - to read the config for the procotol from.
      ps - the ProtocolDispatchSelector to install the new selector on.
      protocol - to use.
    • isActive

      private boolean isActive(Object value)
      Checks if the given value is set to "on".
      Parameters:
      value - the value to test.
      Returns:
      true if it is set else false.