Java/Kotlin SDK
Detailed Java and Kotlin SDK docs for Keeper Secrets Manager
Download and Installation
Install With Maven or Gradle
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
Initialize Storage
In order to retrieve secrets, you must first initialize the local storage on your machine.
Parameter
Type
Required
Default
Description
storage
KeyValueStorage
Yes
clientKey
String
Optional
null
hostName
String
Optional
null
Example Usage
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
Parameter
Type
Required
Default
Description
secret
KeeperRecord
Yes
Record to get field value from
query
String
Yes
Dot notation query of desired field
Get TOTP Code
Parameter
Type
Required
Default
Description
url
String
Yes
TOTP Url
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
Default
Description
options
SecretsManagerOptions
Yes
Storage and query configuration
recordToUpdate
KeeperRecord
Yes
Record to update
Update Password
Parameter
Type
Required
Default
Description
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
length
int
Optional
64
lowercase
int
Optional
0
uppercase
int
Optional
0
digits
int
Optional
0
specialCharacters
int
Optional
0
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
Parameter
Type
Required
Default
Description
file
KeeperFile
Yes
File to download
Response
Type: ByteArray
ByteArray of file for download
Download a Thumbnail
Parameter
Type
Required
Default
Description
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 record with a custom record type.
Delete a Secret
The Java/Kotlin KSM SDK can delete records in the Keeper Vault.
smOptions
SecretsManagerOptions
Yes
recordUids
List<Sting>
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.
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
PAM Records Types - Accessing Linked Credentials
SDK Version Required: 17.1.1 or higher
On PAM Resource Records Types (PAM Machine, PAM Directory, PAM Database), the following credentials can be linked:
Administrative Credentials - the credentials used to perform administrative operations on the resource
Launch Credentials - the credentials used to authenticate a launched session to the resource
Prerequisites:
Use
getSecrets2()method instead ofgetSecrets()Set
requestLinks = truein QueryOptions to enable GraphSyncâ„¢Links will be
nullifrequestLinksis false, empty list iftruebut no links exist
options
SecretsManagerOptions
Yes
Preconfigured options
queryOptions
QueryOptions
Yes
Must set requestLinks=true
QueryOptions Parameters
recordsFilter
List<String>
No
Empty
Filter by record UIDs
foldersFilter
List<String>
No
Empty
Filter by folder UIDs
requestLinks
boolean
Yes
false
Must be true for GraphSync
Link Methods
getRecordUid()
String
Target record UID
isAdminUser()
boolean
Admin privileges
allowsRotation()
boolean
Rotation allowed
allowsConnections()
boolean
Connections allowed
Basic Usage - Retrieve Records with Links
Check Link Properties
Common Example - Find PAM Users
Additional Details
For detailed information on the retrievable fields on the PAM record types, see the Record Field Classes page.
For examples on handling Linked Credentials for advanced PAM use cases, see the Linked Credentials on PAM records page.
Last updated
Was this helpful?

