Class HardwareBinder


  • public class HardwareBinder
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      HardwareBinder()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HardwareBinder allowed​(java.lang.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.
      boolean assertUUID​(java.lang.String uuid)
      Asserts that the current machine has the UUID.
      boolean assertUUID​(java.util.UUID uuid)
      Asserts that the current machine has the UUID.
      HardwareBinder denied​(java.lang.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.
      java.util.UUID getMachineId()
      Calculate the UUID for the machine this code is running on.
      java.lang.String getMachineIdString()
      Get the machine id as an UUID string.
      static void main​(java.lang.String[] args)
      A very simple main that prints out the machine UUID to the standard output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HardwareBinder

        public HardwareBinder()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.security.NoSuchAlgorithmException,
                                java.net.SocketException,
                                java.net.UnknownHostException
        A very simple main that prints out the machine UUID to the standard output.

        This code takes into account the hardware address (Ethernet MAC) when calculating the hardware UUID.

        Parameters:
        args - not used in this version
        Throws:
        java.net.UnknownHostException - in case some error happens
        java.net.SocketException - in case some error happens
        java.security.NoSuchAlgorithmException - in case some error happens
      • allowed

        public HardwareBinder allowed​(java.lang.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​(java.lang.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 java.util.UUID getMachineId()
                                    throws java.security.NoSuchAlgorithmException,
                                           java.net.SocketException,
                                           java.net.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:
        java.net.SocketException - in case some error
        java.security.NoSuchAlgorithmException - in case some error
        java.net.UnknownHostException - in case some error
      • getMachineIdString

        public java.lang.String getMachineIdString()
                                            throws java.security.NoSuchAlgorithmException,
                                                   java.net.SocketException,
                                                   java.net.UnknownHostException
        Get the machine id as an UUID string.
        Returns:
        the UUID as a string
        Throws:
        java.net.UnknownHostException - in case some error
        java.net.SocketException - in case some error
        java.security.NoSuchAlgorithmException - in case some error
      • assertUUID

        public boolean assertUUID​(java.util.UUID uuid)
                           throws java.security.NoSuchAlgorithmException,
                                  java.net.SocketException,
                                  java.net.UnknownHostException
        Asserts that the current machine has the UUID.
        Parameters:
        uuid - expected
        Returns:
        true if the argument passed is the uuid of the current machine.
        Throws:
        java.net.UnknownHostException - in case some error
        java.net.SocketException - in case some error
        java.security.NoSuchAlgorithmException - in case some error
      • assertUUID

        public boolean assertUUID​(java.lang.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.