Credential builder for secure credential management in non-Hadoop Java applications using encrypted keystores
npx @tessl/cli install tessl/maven-org-apache-ranger--credentialbuilder@2.7.0Secure credential management library for Java applications outside the Hadoop ecosystem. Provides encrypted credential storage using Java KeyStore formats (JCEKS and BCFKS) with command-line and programmatic APIs for creating, retrieving, listing, and deleting encrypted credentials.
<dependency>
<groupId>org.apache.ranger</groupId>
<artifactId>credentialbuilder</artifactId>
<version>2.7.0</version>
</dependency>import org.apache.ranger.credentialapi.buildks;
import org.apache.ranger.credentialapi.CredentialReader;import org.apache.ranger.credentialapi.buildks;
import org.apache.ranger.credentialapi.CredentialReader;
// Create a credential builder instance
buildks credBuilder = new buildks();
// Create a new credential programmatically
String[] createArgs = {
"create",
"myAlias",
"-value",
"mySecretPassword",
"-provider",
"jceks://file/path/to/keystore.jceks"
};
int result = credBuilder.createCredential(createArgs);
// Read a credential back
String decryptedPassword = CredentialReader.getDecryptedString(
"/path/to/keystore.jceks",
"myAlias",
"jceks"
);
// List all credentials in keystore
String[] listArgs = {"list", "-provider", "jceks://file/path/to/keystore.jceks"};
credBuilder.listCredential(listArgs);Create encrypted credentials in keystore files with support for different store types.
public class buildks {
public buildks();
public int createCredential(String[] args);
public int createKeyStore(String[] args);
public int createCredentialFromUserInput();
}createCredential creates or updates encrypted credentials with automatic duplicate handling.
args[0]: "create"args[1]: alias nameargs[2]: "-value"args[3]: credential valueargs[4]: "-provider"args[5]: provider path (e.g., "jceks://file/path/to/keystore.jceks")args[6] (optional): "storeType"args[7] (optional): store type value ("jceks", "bcfks")createKeyStore performs lower-level keystore creation using Hadoop CredentialShell.
createCredentialFromUserInput provides interactive credential creation with user prompts.
Usage example:
buildks builder = new buildks();
// Create credential with JCEKS keystore
String[] args = {
"create", "dbPassword", "-value", "secretPass123",
"-provider", "jceks://file/app/config/credentials.jceks"
};
int result = builder.createCredential(args);
// Create credential with BCFKS keystore
String[] bcfksArgs = {
"create", "apiKey", "-value", "key123",
"-provider", "bcfks://file/app/config/credentials.bcfks",
"storeType", "bcfks"
};
int bcfksResult = builder.createCredential(bcfksArgs);Retrieve and decrypt stored credentials from keystore files.
public class CredentialReader {
public static String getDecryptedString(String credentialProviderPath, String alias, String storeType);
}
public class buildks {
public String getCredential(String[] args);
}getDecryptedString is the main API method for retrieving and decrypting stored credentials.
credentialProviderPath: Path to keystore file or provider URLalias: Credential alias namestoreType: Keystore type ("jceks", "bcfks", etc.)getCredential provides command-line style credential retrieval.
args[0]: "get"args[1]: alias nameargs[2]: "-provider"args[3]: provider pathUsage example:
// Direct decryption
String password = CredentialReader.getDecryptedString(
"/app/config/credentials.jceks",
"dbPassword",
"jceks"
);
// Command-style retrieval
buildks builder = new buildks();
String[] getArgs = {"get", "dbPassword", "-provider", "jceks://file/app/config/credentials.jceks"};
String password2 = builder.getCredential(getArgs);List and delete existing credentials in keystore files.
public class buildks {
public int listCredential(String[] args);
public int deleteCredential(String[] args, boolean isSilentMode);
}listCredential displays all available credential aliases in a keystore.
args[0]: "list"args[1]: "-provider"args[2]: provider pathdeleteCredential removes a credential from the keystore.
args[0]: "delete"args[1]: alias nameargs[2]: "-provider"args[3]: provider pathisSilentMode: boolean flag for non-interactive deletionUsage example:
buildks builder = new buildks();
// List all credentials
String[] listArgs = {"list", "-provider", "jceks://file/app/config/credentials.jceks"};
builder.listCredential(listArgs);
// Delete a credential
String[] deleteArgs = {"delete", "oldPassword", "-provider", "jceks://file/app/config/credentials.jceks"};
builder.deleteCredential(deleteArgs, true); // Silent modeMain entry point for command-line usage with validation utilities.
public class buildks {
public static void main(String[] args);
public static boolean isValidCreateCommand(String command, String alias, String valueOption,
String credential, String providerOption, String providerPath,
String storeTypeOption, String storeType);
public static boolean isValidListCommand(String command, String providerOption, String providerPath, String storeType);
public static boolean isValidGetCommand(String command, String alias, String providerOption, String providerPath, String storeType);
public static void displayCommand(String[] args);
public static void displaySyntax(String command, String storeType);
}main provides command-line entry point supporting "create" and "list" commands.
Validation methods verify command syntax and parameters:
Utility methods:
Usage example:
# Command line usage
java -cp credentialbuilder-2.7.0.jar org.apache.ranger.credentialapi.buildks create myAlias -value myPassword -provider jceks://file/keystore.jceks
# Alternative format (as used in tests)
java -cp credentialbuilder-2.7.0.jar org.apache.ranger.credentialapi.buildks create myAlias -value myPassword -provider jceks://file@/keystore.jceks
java -cp credentialbuilder-2.7.0.jar org.apache.ranger.credentialapi.buildks list -provider jceks://file/keystore.jceksHelper methods for keystore management and validation.
public class buildks {
public void deleteInvalidKeystore(String providerPath);
}deleteInvalidKeystore removes corrupted or empty keystore files.
providerPath - Path to keystore file or provider URLThe library supports multiple Java KeyStore formats:
jceks://file/path/to/keystore.jceksjceks://file@/path/to/keystore.jceks (alternative format)localjceks://file/path/to/keystore.jceks.jceksbcfks://file/path/to/keystore.bcfksbcfks://file@/path/to/keystore.bcfks (alternative format)localbcfks://file/path/to/keystore.bcfks.bcfksThe library uses consistent error handling patterns:
getDecryptedString() returns null for missing/invalid credentialsCommon error scenarios:
Key external dependencies used by the public API:
org.apache.hadoop.security.alias.CredentialShell - Core credential operationsorg.apache.hadoop.security.alias.CredentialProvider - Provider interfaceorg.apache.hadoop.security.alias.CredentialProviderFactory - Provider factoryorg.apache.hadoop.security.alias.JavaKeyStoreProvider - JCEKS providerorg.apache.hadoop.conf.Configuration - Hadoop configuration frameworkjava.security.KeyStore - Java KeyStore APIThese dependencies are automatically resolved through Maven when including the credentialbuilder artifact.