Package org.opends.server.util
Class Platform
- java.lang.Object
-
- org.opends.server.util.Platform
-
public final class Platform extends Object
Provides a wrapper class that collects all of the JVM vendor and JDK version specific code in a single place.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPlatform.KeyTypeKey size, key algorithm and signature algorithms used.
-
Field Summary
Fields Modifier and Type Field Description static StringJAVA_MINIMUM_VERSION_NUMBERThe minimum java supported version.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddCertificate(KeyStore ks, String ksType, String ksPath, String alias, char[] pwd, String certPath)Add the certificate in the specified path to the provided keystore; creating the keystore with the provided type and path if it doesn't exist.static voidaddTrustedCertificate(KeyStore ks, String ksType, String ksPath, String alias, char[] pwd, Certificate certificate)Add the provided certificate to the provided keystore as a trusted certificate entry; creating the keystore with the provided type and path if it doesn't exist.static intcomputeNumberOfThreads(int minimumValue, float cpuMultiplier)Computes the number of replay/worker/cleaner threads based on the number of cpus in the system.static voiddeleteAlias(KeyStore ks, String ksPath, String alias, char[] pwd)Delete the specified alias from the provided keystore.static voidgenerateSelfSignedCertificate(KeyStore ks, String ksType, String ksPath, Platform.KeyType keyType, String alias, char[] pwd, String dn, int validity)Generate a self-signed certificate using the specified alias, dn string and validity period.static voidimportKeyEntry(KeyStore ks, String ksType, String ksPath, String alias, char[] pwd, Key privateKey, Certificate[] chain)Copy a key entry, that is a private key and its certificate chain, into the provided keystore; creating the keystore with the provided type and path if it doesn't exist.static booleanisVendor(String vendor)Test if a platform java vendor property starts with the specified vendor string.
-
-
-
Field Detail
-
JAVA_MINIMUM_VERSION_NUMBER
public static final String JAVA_MINIMUM_VERSION_NUMBER
The minimum java supported version.- See Also:
- Constant Field Values
-
-
Method Detail
-
addCertificate
public static void addCertificate(KeyStore ks, String ksType, String ksPath, String alias, char[] pwd, String certPath) throws KeyStoreException
Add the certificate in the specified path to the provided keystore; creating the keystore with the provided type and path if it doesn't exist.- Parameters:
ks- The keystore to add the certificate to, may be null if it doesn't exist.ksType- The type to use if the keystore is created.ksPath- The path to the keystore if it is created.alias- The alias to store the certificate under.pwd- The password to use in saving the certificate.certPath- The path to the file containing the certificate.- Throws:
KeyStoreException- If an error occurred adding the certificate to the keystore.
-
importKeyEntry
public static void importKeyEntry(KeyStore ks, String ksType, String ksPath, String alias, char[] pwd, Key privateKey, Certificate[] chain) throws KeyStoreException
Copy a key entry, that is a private key and its certificate chain, into the provided keystore; creating the keystore with the provided type and path if it doesn't exist. The private key is re-encrypted with the password of the destination keystore.- Parameters:
ks- The keystore to add the key entry to, may be null if it doesn't exist.ksType- The type to use if the keystore is created.ksPath- The path to the keystore.alias- The alias to store the key entry under.pwd- The keystore password, used for the private key as well.privateKey- The private key to store.chain- The certificate chain of the private key, the certificate it belongs to first.- Throws:
KeyStoreException- If the alias is already in use, or an error occurred adding the key entry to the keystore.
-
addTrustedCertificate
public static void addTrustedCertificate(KeyStore ks, String ksType, String ksPath, String alias, char[] pwd, Certificate certificate) throws KeyStoreException
Add the provided certificate to the provided keystore as a trusted certificate entry; creating the keystore with the provided type and path if it doesn't exist. Only such an entry is a trust anchor: the certificate chain of a key entry is not, the trust managers take the certificate the key belongs to and none of its issuers.- Parameters:
ks- The keystore to add the certificate to, may be null if it doesn't exist.ksType- The type to use if the keystore is created.ksPath- The path to the keystore.alias- The alias to store the certificate under.pwd- The keystore password.certificate- The certificate to trust.- Throws:
KeyStoreException- If the alias is already in use, or an error occurred adding the certificate to the keystore.
-
deleteAlias
public static void deleteAlias(KeyStore ks, String ksPath, String alias, char[] pwd) throws KeyStoreException
Delete the specified alias from the provided keystore.- Parameters:
ks- The keystore to delete the alias from.ksPath- The path to the keystore.alias- The alias to use in the request generation.pwd- The keystore password to use.- Throws:
KeyStoreException- If an error occurred deleting the alias.
-
generateSelfSignedCertificate
public static void generateSelfSignedCertificate(KeyStore ks, String ksType, String ksPath, Platform.KeyType keyType, String alias, char[] pwd, String dn, int validity) throws KeyStoreException
Generate a self-signed certificate using the specified alias, dn string and validity period. If the keystore does not exist, it will be created using the specified keystore type and path.- Parameters:
ks- The keystore to save the certificate in. May be null if it does not exist.keyType- The keystore type to use if the keystore is created.ksPath- The path to the keystore if the keystore is created.ksType- Specify the key size, key algorithm and signature algorithms used.alias- The alias to store the certificate under.pwd- The password to us in saving the certificate.dn- The dn string used as the certificate subject.validity- The validity of the certificate in days.- Throws:
KeyStoreException- If the self-signed certificate cannot be generated.
-
isVendor
public static boolean isVendor(String vendor)
Test if a platform java vendor property starts with the specified vendor string.- Parameters:
vendor- The vendor to check for.- Returns:
trueif the java vendor starts with the specified vendor string.
-
computeNumberOfThreads
public static int computeNumberOfThreads(int minimumValue, float cpuMultiplier)Computes the number of replay/worker/cleaner threads based on the number of cpus in the system. Allows for a multiplier to be specified and a minimum value to be returned if not enough processors are present in the system.- Parameters:
minimumValue- at least this value should be returned.cpuMultiplier- the scaling multiplier of the number of threads to return- Returns:
- the number of threads based on the number of cpus in the system.
- Throws:
IllegalArgumentException- ifcpuMultiplieris a non positive number
-
-