Class HardwareBinder


  • public class HardwareBinder
    extends Object
    The hardware binder binds a license to a certain hardware. The use of this feature is optional. Calling methods from this class the license manager can check that the license is deployed on the machine it was destined to and may decide NOT to work on other machines than it was destined to.

    It is recommended that such a checking is used only with warning purposes and not treated as a strict license violation. It may happen that the ethernet card of a server is replaced due to some failure and there is no time to request a new license.

    Therefore it is a recommended practice to note the difference of UUID in the license and the calculated one and send it to the log, but do not deter the operation of the software.

    • Constructor Detail

      • HardwareBinder

        public HardwareBinder()
    • Method Detail

      • allowed

        public HardwareBinder allowed​(String regex)
        Add a regular expression to the set of the regular expressions that are checked against the display name of the network interface cards. If any of the regular expressions are matched against the display name then the interface is allowed taken into account during the calculation of the machine id.

        Note that there is also a denied set of regular expressions. A network interface card is used during the calculation of the machine uuid if any of the allowing regular expressions match and none of the denying regular expressions match.

        Note that if there is no any allowing regular expressions, then this is treated that all the interface cards are allowed unless explicitly denied by any of the denying regular expressions. This way the functionality of the hardware binder class is compatible with previous versions. If you do not define allowed set, nor denied set then the interface cards are treated the same as with the old version.

        This functionality is needed only when you have problem with some virtual network interface cards that are erroneously reported by the Java run time system as physical cards. This is a well known bug that is low priority in the Java realm and there is no general workaround. If you face that problem, then try programmatically exclude from the calculation the network cards that cause you problem.

        Parameters:
        regex - the regular expression string
        Returns:
        the HardwareBinder object so method calls can be chained
      • denied

        public HardwareBinder denied​(String regex)
        Add a regular expression to the set of the regular expressions that are checked against the display name of the network interface cards. If any of the regular expressions are matched against the display name then the interface is denied taken into account during the calculation of the machine id.

        See also the documentation of the method allowed(String).

        Parameters:
        regex - the regular expression string
        Returns:
        the HardwareBinder object so method calls can be chained
      • getMachineId

        public UUID getMachineId()
                          throws NoSuchAlgorithmException,
                                 SocketException,
                                 UnknownHostException
        Calculate the UUID for the machine this code is running on. To do this the method lists all network interfaces that are real 'server' interfaces (ignoring loop-back, virtual, and point-to-point interfaces). The method takes each interface name (as a string) and hardware address into a MD5 digest one after the other and finally converts the resulting 128bit digest into a UUID.

        The method also feeds the local machine name into the digest.

        This method relies on Java 6 methods, but also works with Java 5. However the result will not be the same on Java 5 as on Java 6.

        Returns:
        the UUID of the machine or null if the uuid can not be calculated.
        Throws:
        SocketException - in case some error
        NoSuchAlgorithmException - in case some error
        UnknownHostException - in case some error
      • assertUUID

        public boolean assertUUID​(String uuid)
        Asserts that the current machine has the UUID.
        Parameters:
        uuid - expected in String format
        Returns:
        true if the argument passed is the uuid of the current machine.