Java/Kotlin SDK
Detailed Java and Kotlin SDK docs for Keeper Secrets Manager
Download and Installation
Install With Maven or Gradle
For more information, see https://central.sonatype.com/artifact/com.keepersecurity.secrets-manager/core
Cryptographic Provider
The Keeper Secrets Manager SDK expects the developer to use their required cryptographic provider. As documented above, Keeper will use the default cryptographic module of the Java runtime unless a specific provider is added. In the examples here in this documentation, we are using the BouncyCastle FIPS provider.
In the source code, ensure that the provider is loaded in the security context:
See the file CryptoUtilsTest.kt as shown in this example on how to use a custom security provider.
Source Code
Find the Java/Kotlin source code in the GitHub repository
Using the SDK
Initialize Storage
In order to retrieve secrets, you must first initialize the local storage on your machine.
storage
KeyValueStorage
Yes
Storage Implementation
oneTimeToken
String
Yes
One-time access token
hostName
String
Optional
null
Custom hostname
Example Usage
Binding Lifecycle
The one-time token is redeemed on the first getSecrets() call, not at construction. If you persist config to an external store (AWS Secrets Manager, Azure Key Vault, etc.), read it back only after that call. For the full explanation, see Binding Lifecycle.
Retrieve Secrets
Parameter
Type
Required
Default
Description
options
SecretsManagerOptions
Yes
Storage and query configuration
recordsFilter
List<String>
Optional
Empty List
Record search filters
Response
Type: KeeperSecrets
Object containing all Keeper records, or records that match the given filter criteria
Example Usage
Retrieve all Secrets
Retrieve one secret by UID
Retrieve Secrets by Title
recordTitle
String
Yes
Record title to search for
Example Usage
Retrieve Values From a Secret
Retrieve a Password
This shortcut gets the password of a secret once that secret has been retrieved from Keeper Secrets Manager.
Retrieve Fields
To get a field value, you will need to cast the return to the class of the corresponding field type. For a list of field types see the Record Types page.
Keeper Notation
secrets
KeeperSecrets
Yes
Secrets collection to resolve the notation against
query
String
Yes
Dot notation query of desired field
Get TOTP Code
url
String
Yes
TOTP Url
PAM Record Types
Use record.getType() to identify PAM records.
For field schemas of all 11 PAM record types, see PAM Record Types.
Linked Credentials
Pass requestLinks = true in QueryOptions to retrieve PAM resource records with their linked credentials included. Each link is a KeeperRecordLink exposing typed accessors for the target record UID and the link's privileges and permitted operations (isAdminUser(), isLaunchCredential(), allowsRotation(), allowsConnections(), …). See Linked Credentials on PAM Records for the full reference.
QueryOptions Parameters
recordsFilter
List<String>
No
Empty
Filter by record UIDs
foldersFilter
List<String>
No
Empty
Filter by folder UIDs
requestLinks
Boolean?
No
null
Set to true to retrieve links; null/false returns no links
For the cross-SDK overview of the linked credentials workflow, see Linked Credentials.
Update Values in a Secret
Record update commands don't update local record data on success (esp. updated record revision) so any consecutive updates to an already updated record will fail due to revision mismatch. Make sure to reload all updated records after each update batch.
Update Secret
Update Secret is used to save changes made to a secret. Once updateSecret is performed successfully, the changes are reflected in the Keeper Vault.
Parameter
Type
Required
Description
options
SecretsManagerOptions
Yes
Storage and query configuration
recordToUpdate
KeeperRecord
Yes
Record to update
transactionType
UpdateTransactionType
No
Set to start a two-phase update; complete it with completeTransaction
Update Password
password
String
Yes
New password to set
Update other fields
Each record field type is represented by a class. Cast the field to the corresponding class in order to correctly access the field's value. Check the Record Types documentation for a list of field types.
Fields can have multiple values, which is accessed in a List. In this example we are updating the login field, which only accepts one value, so we update the one value in the values list.
Generate a Random Password
minLength
Int
Optional
32
Minimum total length of the generated password
lowercase
Int
Optional
null
Minimum lowercase letters (treated as an exact count if 0 or negative)
uppercase
Int
Optional
null
Minimum uppercase letters (treated as an exact count if 0 or negative)
digits
Int
Optional
null
Minimum digits (treated as an exact count if 0 or negative)
specialCharacters
Int
Optional
null
Minimum special characters (treated as an exact count if 0 or negative)
specialCharacterSet
String
Optional
"!@#$%()+;<>=?[]{}^.,
Custom set of special characters to draw from
Each parameter indicates the min number of a type of character to include. For example, 'uppercase' indicates the minimum number of uppercase letters to include.
Download a File
file
KeeperFile
Yes
File to download
Response
Type: ByteArray
ByteArray of file for download
Download a Thumbnail
file
KeeperFile
Yes
File with thumbnail to download
Response
Type: ByteArray
ByteArray of thumbnail for download
Upload a File
Upload File:
options
SecretsManagerOptions
Yes
Storage and query configuration
ownerRecord
KeeperRecord
Yes
The record to attach the uploaded file to
file
KeeperFileUpload
Yes
The File to upload
Creating the Keeper File Upload Object:
name
string
Yes
What the name of the file will be in Keeper once uploaded
title
string
Yes
What the title of the file will be in Keeper once uploaded
type
string
Optional
The mime type of data in the file. 'application/octet-stream' will be used if nothing is given
data
ByteArray
Yes
File data as bytes
Example Usage
Remove Files from a Record
SDK Version Required: 17.1.1 or higher
This feature add the ability to remove file attachments from records using the UpdateOptions class with the linksToRemove parameter.
Prerequisites:
Record UID or KeeperRecord object containing files
File UIDs of the files to be removed
Files must exist on the record to be removed
options
SecretsManagerOptions
Yes
Preconfigured options
record
KeeperRecord
Yes
The record to update
updateOptions
UpdateOptions
Yes
Options containing files to remove
transactionType
UpdateTransactionType
No
null
Transaction type for batch operations
linksToRemove
List<String>
Yes
List of file UIDs to remove
Full Example Usage:
Create a Secret
Prerequisites:
Shared folder UID
Shared folder must be accessible by the Secrets Manager Application
You and the Secrets Manager application must have edit permission
There must be at least one record in the shared folder
Created records and record fields must be formatted correctly
See the documentation for expected field formats for each record type
TOTP fields accept only URL generated outside of the KSM SDK
After record creation, you can upload file attachments using uploadFile
options
SecretsManagerOptions
Yes
folderUid
String
Yes
newRecordData
KeeperRecordData
Yes
secrets
KeeperSecrets
Optional
Freshly fetched list of all secrets from the Keeper servers
options
SecretsManagerOptions
Yes
createOptions
CreateOptions
Yes
newRecordData
KeeperRecordData
Yes
folders
KeeperFolder[]
Optional
Freshly fetched list of all folders from the Keeper servers
This example creates a login type record with a login value and a generated password.
This example creates a serverCredentials record — a server login with host, username, and password.
databaseCredentials Example
This example creates a databaseCredentials record — a database login with connection details.
sshKeys Example
This example creates an sshKeys record — an SSH key pair with host and login.
Delete a Secret
The Java/Kotlin KSM SDK can delete records in the Keeper Vault.
smOptions
SecretsManagerOptions
Yes
recordUids
List<String>
Yes
Caching
To protect against losing access to your secrets when network access is lost, the Java SDK allows caching of secrets to the local machine in an encrypted file.
Setup and Configure Cache
In order to setup caching in the Java SDK, include a caching post function as the second argument when instantiating aSecretsManagerOptions object.
The Java SDK includes a default caching function cachingPostFunction which stores cached queries to a file.
Folders
Folders have full CRUD support - create, read, update and delete operations.
Read Folders
Downloads full folder hierarchy.
Response
Type: List<KeeperFolder>
Example Usage
Create a Folder
Requires CreateOptions and folder name to be provided. The folder UID parameter in CreateOptions is required - UID of a shared folder, while sub-folder UID is optional and if missing new regular folder is created directly under the parent (shared folder). There's no requirement for the sub-folder to be a direct descendant of the parent shared folder - it could be many levels deep.
options
SecretsManagerOptions
Yes
Preconfigured options
createOptions
CreateOptions
Yes
The parent and sub-folder UIDs
folderName
String
Yes
The Folder name
folders
List<KeeperFolder>
No
List<KeeperFolder>
List of folders to use in the search for parent and sub-folder from CreateOptions
Example Usage
Update a Folder
Updates the folder metadata - currently folder name only.
options
SecretsManagerOptions
Yes
Preconfigured options
folderUid
String
Yes
The folder UID
folderName
String
Yes
The new folder name
folders
List<KeeperFolder>
No
List<KeeperFolder>
List of folders to use in the search for parent folder
Example Usage
Delete Folders
Removes a list of folders. Use forceDeletion flag to remove non-empty folders.
Response
Type: SecretsManagerDeleteFolderResponse
options
SecretsManagerOptions
Yes
Preconfigured options
folderUids
List<String>
Yes
The folder UID list
forceDeletion
Boolean
No
false
Force deletion of non-empty folders
Example Usage
Record Field Classes
Each record field type is represented by a class. Cast the field to the corresponding class to access the field's value. See the Record Types documentation for a list of field types.
Proxy Support
To route SDK traffic through an HTTP or HTTPS proxy, set proxyUrl on SecretsManagerOptions.
Java — static factory (recommended):
Kotlin — named parameter:
Authenticated proxies use the http://user:password@host:port URL form. Percent-encode reserved characters in the password (for example, p%40ss for p@ss).
Authenticated Proxies and the JVM Flag
Java disables Basic authentication over HTTPS CONNECT tunnels by default. The SDK clears this restriction automatically when proxy credentials are detected, but only if no other HTTP or HTTPS connection has loaded HttpURLConnection before the SDK's first call — which application servers and frameworks nearly always do first.
If you use an authenticated proxy, set this JVM flag before your application makes any other HTTP or HTTPS call:
Pass it on the command line or via JDK_JAVA_OPTIONS (Java 9+). If the flag is not set in time, the SDK throws a SecretsManagerException naming this remedy rather than a bare 407 error.
Ambient Proxy Settings
When proxyUrl is not set, the SDK reads JVM system properties (https.proxyHost/https.proxyPort) and then the HTTPS_PROXY/https_proxy environment variables. NO_PROXY/no_proxy and http.nonProxyHosts exclusions are honored.
Starting in 17.4.0, the SDK honors ambient proxy settings that it previously ignored. If your environment sets HTTPS_PROXY or https.proxyHost for other tools, verify those values before upgrading.
Connection and Read Timeouts
SecretsManagerOptions exposes connectTimeoutMillis (default 5,000 ms) and readTimeoutMillis (default 30,000 ms). A stalled server raises SocketTimeoutException rather than hanging indefinitely. Use Kotlin named parameters to set only the values you need:
Last updated

