public class KeyMaster extends java.lang.Object implements IKeyMaster
Constructor and Description |
---|
KeyMaster(IKeyMasterConfiguration configuration)
Initializes a new instance of the
KeyMaster class. |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
generateToken(IAuthenticationParameters authParameters,
IKeyMasterFormatter formatter)
Generates a KeyMaster token for the given
IAuthenticationParameters |
public KeyMaster(IKeyMasterConfiguration configuration)
KeyMaster
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;
}
}
configuration
- The configuration for this instance of KeyMaster.public java.lang.String generateToken(IAuthenticationParameters authParameters, IKeyMasterFormatter formatter)
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;
}
}
generateToken
in interface IKeyMaster
authParameters
- The authentication parameters.formatter
- The formatter to apply to the token.IKeyMasterFormatter
Please send bug reports and comments to Caplin support