Class OsxProxySearchStrategy

  • All Implemented Interfaces:
    ProxySearchStrategy

    public class OsxProxySearchStrategy
    extends java.lang.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 Detail

      • OVERRIDE_SETTINGS_FILE

        public static final java.lang.String OVERRIDE_SETTINGS_FILE
        See Also:
        Constant Field Values
      • OVERRIDE_ACCEPTED_DEVICES

        public static final java.lang.String OVERRIDE_ACCEPTED_DEVICES
        See Also:
        Constant Field Values
    • Constructor Detail

      • OsxProxySearchStrategy

        public OsxProxySearchStrategy()
        ProxySelector
        See Also:
        ProxySelector()
    • Method Detail

      • getProxySelector

        public java.net.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 java.lang.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 java.net.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 java.util.List<java.lang.String> getNetworkInterfaces()
                                                               throws java.net.SocketException
        Create a list of Ethernet interfaces that are connected
        Returns:
        a list of available interface names
        Throws:
        java.net.SocketException
      • isInterfaceAllowed

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

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

        private java.net.ProxySelector installSimpleHostFilter​(PListParser.Dict proxySettings,
                                                               java.net.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 java.net.ProxySelector installExceptionList​(PListParser.Dict proxySettings,
                                                            java.net.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 java.lang.String toCommaSeparatedString​(java.util.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 java.net.ProxySelector autodetectProxyIfAvailable​(PListParser.Dict proxySettings,
                                                                  java.net.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 java.net.ProxySelector installPacProxyIfAvailable​(PListParser.Dict proxySettings,
                                                                  java.net.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,
                                                java.lang.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​(java.lang.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.