Class KeyMaster
- java.lang.Object
-
- com.caplin.keymaster.KeyMaster
-
- All Implemented Interfaces:
IKeyMaster
public class KeyMaster extends java.lang.Object implements IKeyMaster
The main KeyMaster class. Use this class to generate KeyMaster tokens.
-
-
Constructor Summary
Constructors Constructor Description KeyMaster(IKeyMasterConfiguration configuration)
Initializes a new instance of theKeyMaster
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
generateToken(IAuthenticationParameters authParameters, IKeyMasterFormatter formatter)
Generates a KeyMaster token for the givenIAuthenticationParameters
-
-
-
Constructor Detail
-
KeyMaster
public KeyMaster(IKeyMasterConfiguration configuration)
Initializes a new instance of theKeyMaster
class.This example constructs a KeyMaster instance using a private key contained within a PEM file.
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; } }
- Parameters:
configuration
- The configuration for this instance of KeyMaster.
-
-
Method Detail
-
generateToken
public java.lang.String generateToken(IAuthenticationParameters authParameters, IKeyMasterFormatter formatter)
Generates a KeyMaster token for the givenIAuthenticationParameters
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; } }
- Specified by:
generateToken
in interfaceIKeyMaster
- Parameters:
authParameters
- The authentication parameters.formatter
- The formatter to apply to the token.- Returns:
- The token as formatted by the given
IKeyMasterFormatter
-
-