Interface IKeyMaster

  • All Known Implementing Classes:

    public interface IKeyMaster
    This interface defines the functionality of the KeyMaster class.

    This interface is provided in order to make unit testing your application easier. You should use a mock library to create a mock object which implements this interface, thus removing the dependency on the real KeyMaster implementation.

    • Method Detail

      • generateToken

        java.lang.String generateToken​(IAuthenticationParameters authParameters,
                                       IKeyMasterFormatter formatter)
        Generates a KeyMaster token for the given IAuthenticationParameters.

        KeyMaster offers no guarantees regarding thread safety, if there is a possibility that multiple calls to this method could be made at the same time, then the calling code should take steps to ensure that only once call can be in progress at a given point in time.

        This example generates a token and formats it using the StandardFormatter which is suitable for use by StreamLink.

        import com.caplin.keymaster.IKeyMaster;
        import com.caplin.keymaster.IKeyMasterConfiguration;
        import com.caplin.keymaster.KeyMaster;
        import com.caplin.keymaster.KeyMasterHashingAlgorithm;
        import com.caplin.keymaster.PEMPKCS8KeyMasterConfiguration;
        public class CreatingKeyMasterInstance
                private static final String PEM_FILE_LOCATION = "c:\\private.pem";
                public IKeyMaster createKeyMasterInstance() throws Exception
                        // Create a KeyMaster configuration using a private key stored as a PEM format file.
                        // This constructor may throw an exception; handling of it has been omitted for clarity.
                        IKeyMasterConfiguration configuration = new PEMPKCS8KeyMasterConfiguration(PEM_FILE_LOCATION, KeyMasterHashingAlgorithm.SHA256, null);
                        // Create a keymaster instance.
                        IKeyMaster keymaster = new KeyMaster(configuration);
                        return keymaster;

        authParameters - The authentication parameters.
        formatter - The formatter to apply to the token.
        The token as formatted by the given IKeyMasterFormatter