Java/Kotlin SDK
Keeperシークレットマネージャー用JavaとKotlin SDKの詳細
ダウンロードとインストール
MavenまたはGradleを使用したインストール
repositories {
mavenCentral()
}
dependencies {
implementation 'com.keepersecurity.secrets-manager:core:17.1.1+'
implementation("org.bouncycastle:bc-fips:1.0.2.4")
}<dependency>
<groupId>com.keepersecurity.secrets-manager</groupId>
<artifactId>core</artifactId>
<version>[17.1.1,)</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bc-fips</artifactId>
<version>1.0.2.4</version>
</dependency>暗号化プロバイダ
KeeperシークレットマネージャーSDK では、開発者が必要とされる暗号化プロバイダを使用することが想定されています。特定のプロバイダが追加されない限り、Javaランタイムのデフォルトの暗号化モジュールを使用します。本ページの例では、BouncyCastle FIPSプロバイダを使用しています。
ソースコードで、プロバイダがセキュリティコンテキストにロードされていることを確認します。
fun main() {
Security.addProvider(BouncyCastleFipsProvider())
...カスタムセキュリティプロバイダーの使用方法については、こちらのページの CryptoUtilsTest.kt ファイルをご参照ください。
ソースコード
Java/Kotlinのソースコードは、GitHubリポジトリで入手できます。
ストレージの初期化
シークレットを取得するには、まずマシンのローカルストレージを初期化する必要があります。
initializeStorage(storage:KeyValueStorage, clientKey:String? = null, hostName:String? = null)storage
KeyValueStorage
はい
clientKey
String
オプション
null
hostName
String
オプション
null
使用例
import static com.keepersecurity.secretsManager.core.SecretsManager.initializeStorage;
import com.keepersecurity.secretsManager.core.LocalConfigStorage;
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
// oneTimeTokenはストレージの初期化に一度だけ使用
// 初回実行以降の呼び出しでは「ksm-config.txt」ファイルを使用
String oneTimeToken = "[One Time Access Token]";
LocalConfigStorage storage = new LocalConfigStorage("ksm-config.txt");
try {
initializeStorage(storage, oneTimeToken);
SecretsManagerOptions options = new SecretsManagerOptions(storage);
// トークンのみを使用して(後で使用するために)設定を生成するには
// トークンをバインドするアクセス操作が少なくとも1回必要です
//getSecrets(options)
} catch (Exception e) {
System.out.println(e.getMessage());
}シークレットの取得
getSecrets(options:SecretsManagerOptions, recordsFilter:List<String> = emptyList()):KeeperSecretsパラメータ
型
必須
デフォルト
説明
options
SecretsManagerOptions
はい
ストレージとクエリの設定
recordsFilter
List<String>
オプション
空のリスト
レコードの検索フィルタ
レスポンス
型: KeeperSecrets
すべてのKeeperレコード、または指定したフィルタ条件に一致するレコードを含むオブジェクト
使用例
すべてのシークレットを取得
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperSecrets;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// シークレットを取得
SecretsManagerOptions options = new SecretsManagerOptions(storage);
KeeperSecrets secrets = SecretsManager.getSecrets(options);
// シークレットからレコードを取得
List<KeeperRecord> records = secrets.getRecords();UIDで1つのシークレットを取得
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperSecrets;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// シークレットを取得
SecretsManagerOptions options = new SecretsManagerOptions(storage);
KeeperSecrets secrets = SecretsManager.getSecrets(options);
// シークレットを取得するための1つまたは複数のUIDレコードを指定
List<String> uidFilter = List.of("[XXX]");
// フィルタを使用してシークレットを取得
KeeperSecrets secrets = SecretsManager.getSecrets(options, uidFilter);
// シークレットからレコードを取得
List<KeeperRecord> records = secrets.getRecords();タイトルでシークレットを取得
// 一致するレコードをすべて取得
getSecretsByTitle(recordTitle:String):List<KeeperRecord>
// 最初に一致したレコードだけを取得
getSecretByTitle(recordTitle:String):KeeperRecordrecordTitle
String
はい
検索するレコードタイトル
使用例
import com.keepersecurity.secretsManager.core.*;
import java.util.List;
public class KSMSample {
public static void main(String[] args){
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// 事前に初期化されたストレージを取得
KeyValueStorage storage = new LocalConfigStorage("ksm-config.json");
try {
SecretsManagerOptions options = new SecretsManagerOptions(storage);
// 取得するレコードのタイトル
String recordTitle = "My Credentials";
// タイトルでレコードを検索
KeeperRecord myCredentials = secrets.getRecords().getSecretByTitle(recordTitle);
// レコードの詳細を出力
System.out.println("Record UID: " + myCredentials.getRecordUid());
System.out.println("Title: " + myCredentials.getData().getTitle());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}シークレットから値を取得
パスワードを取得
シークレットをKeeperシークレットマネージャーから取得すると、このショートカットでそのシークレットのパスワードを取得します。
secret.getPassword()import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperSecrets;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// シークレットを取得
SecretsManagerOptions options = new SecretsManagerOptions(storage);
KeeperSecrets secrets = SecretsManager.getSecrets(options);
// 最初のレコードを取得
List<KeeperRecord> records = secrets.getRecords().get(0);
// 最初のレコードからパスワードを取得
firstRecord.getPassword()フィールドを取得
secret.getData().getField(<FIELD_TYPE>)import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperSecrets;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// シークレットを取得
SecretsManagerOptions options = new SecretsManagerOptions(storage);
KeeperSecrets secrets = SecretsManager.getSecrets(options);
// 最初のレコードを取得
List<KeeperRecord> records = secrets.getRecords();
KeeperRecord firstRecord = secrets.getRecords().get(0);
// 最初のレコードからパスワードを取得
KeeperRecordField pwd = firstRecord.getData().getField(Password.class)フィールド値を取得するには、戻り値を対応するフィールドタイプのクラスにキャストする必要があります。フィールドタイプの一覧については、レコードタイプページをご参照ください。
Keeper表記法
Notation.getValue(secret, "<query>");
// クエリの例: <RECORD UID>/field/loginimport static com.keepersecurity.secretsManager.core.SecretsManager.*
import static com.keepersecurity.secretsManager.core.Notation.*;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// シークレットを取得
KeeperSecrets secrets = getSecrets(options);
// ドット記法でログインを取得
String login = getValue(secrets, "BediNKCMG21ztm5xGYgNww/field/login");secret
KeeperRecord
はい
フィールド値を取得するレコード
query
String
はい
目的のフィールドのドット記法によるクエリ
TOTPコードを取得
TotpCode.uriToTotpCode(url)import static com.keepersecurity.secretsManager.core.Notation.*;
import static com.keepersecurity.secretsManager.core.TotpCode.*;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
...
// シークレットを取得
KeeperSecrets secrets = getSecrets(options);
// レコードからTOTP urlを取得
String url= getValue(secrets, "BediNKCMG21ztm5xGYgNww/field/oneTimeCode");
// TOTPコードを取得
TotpCode totp = uriToTotpCode(url);url
String
はい
TOTP Url
シークレットの値を更新
レコード更新コマンドが成功しても、ローカルのデータ (特にレコードのリビジョン情報) は更新されません。そのため、同じレコードを続けて更新しようとすると、リビジョンが一致しないため失敗します。これを防ぐには、レコードを更新した後に、必ずそのレコードを再読み込みしてください。
シークレットを更新
updateSecret(options:SecretsManagerOptions, recordToUpdate:KeeperRecord);import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperSecrets;
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import static com.keepersecurity.secretsManager.core.SecretsManager.*;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// シークレットを取得
SecretsManagerOptions options = SecretsManagerOptions(storage);
KeeperSecrets secrets = getSecrets(options);
// 最初のレコードを更新
KeeperRecord recordToUpdate = secrets.getRecords().get(0);
// パスワードを更新
recordToUpdate.updatePassword("aP1$t367QOCvL$eM$bG#");
// 変更を保存
updateSecret(options, recordToUpdate); import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperSecrets;
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import static com.keepersecurity.secretsManager.core.SecretsManager.*;
...
// シークレットを取得
SecretsManagerOptions options = SecretsManagerOptions(storage);
KeeperSecrets secrets = getSecrets(options);
// 最初のレコードを更新
KeeperRecord record = secrets.getRecords().get(0);
// レコードのパスワードをローテーション
record.updatePassword("aP1$t367QOCvL$eM$bG#");
// トランザクションを開始
updateSecret(options, record, transactionType = UpdateTransactionType.GENERAL);
// リモートホストでパスワードをローテーション
boolean success = rotateRemoteSshPassword("aP1$t367QOCvL$eM$bG#");
// トランザクション完了 (コミットかロールバック)
completeTransaction(options, record.recordUid, rollback = !success);UpdateSecretを使用して、シークレットに加えた変更を保存します。 UpdateSecretが正常に実行されると、変更がKeeperボルトに反映されます。
パラメータ
型
必須
デフォルト
説明
options
SecretsManagerOptions
はい
ストレージとクエリの設定
recordToUpdate
KeeperRecord
はい
更新するレコード
パスワードを更新
recordToUpdate.updatePassword(password:String);
SecretsManager.updateSecret(options, recordToUpdate);import static com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperSecrets;
// シークレットを取得
SecretsManagerOptions options = SecretsManagerOptions(storage);
KeeperSecrets secrets = getSecrets(options);
// 最初のレコードを更新
KeeperRecord recordToUpdate = secrets.getRecords().get(0);
// パスワードを更新
recordToUpdate.updatePassword("aP1$t367QOCvL$eM$bG#");
// 変更を保存
SecretsManager.updateSecret(options, recordToUpdate);password
String
はい
設定する新しいパスワード
他のフィールドを更新
// 形式
RecordField.getValue().set(index, value)
// 例 - ログインフィールド
recordLogin.getValue().set(0, "New Login");// 編集するフィールドを取得
Login recordLogin = (Login) recordToUpdate.getData().getField(Login.class);
// フィールド値を更新
recordLogin.getValue().set(0, "New Login");
// 変更を保存
SecretsManager.updateSecret(options, recordToUpdate);レコードの各フィールドタイプは、クラスに相当します。 フィールドの値に正しくアクセスするために、フィールドを対応するクラスにキャストします。 フィールドタイプについては、レコードタイプのページご確認ください。
フィールドには複数の値を設定でき、リストでアクセスします。 この例では、1つの値のみを指定するログインフィールドを更新するため、値リスト内の1つの値を更新します。
ランダムなパスワードを生成
generatePassword(length: int, lowercase: int, uppercase: int, digits: int, specialCharacters: int)import com.keepersecurity.secretsManager.core.CryptoUtils;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// 編集するフィールドを取得
Password recordPassword = (Password) recordToUpdate.getData().getField(Password.class);
// ランダムなパスワードを生成
String password = CryptoUtils.generatePassword();
// フィールド値を更新
recordPassword.getValue().set(0, password);
// 変更を保存
SecretsManager.updateSecret(options, recordToUpdate);length
int
オプション
64
lowercase
int
オプション
0
uppercase
int
オプション
0
digits
int
オプション
0
specialCharacters
int
オプション
0
各パラメータは、使用する文字の種類の最小数を示します。たとえば、「uppercase」は、使用する大文字の最小数を示します。
ファイルのダウンロード
SecretsManager.downloadFile(file):ByteArrayimport static com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperFile;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// 最初のレコードから最初のファイルをダウンロード
KeeperRecord firstRecord = secrets.getRecords().get(0);
KeeperFile file = firstRecord.getFileByName("acme.cer");
byte[] fileBytes = SecretsManager.downloadFile(file);
// ファイルをディスクに書き込む
try (FileOutputStream fos = new FileOutputStream(file.getData().getName())) {
fos.write(fileBytes);
} catch (IOException ioException){
ioException.printStackTrace();
}file
KeeperFile
はい
ダウンロードするファイル
レスポンス
型: ByteArray
ダウンロード用のファイルのバイト配列
サムネイルのダウンロード
SecretsManager.downloadThumbnail(file):ByteArrayimport static com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.KeeperRecord;
import com.keepersecurity.secretsManager.core.KeeperFile;
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// 最初のレコードから最初のファイルをダウンロード
KeeperRecord firstRecord = secrets.getRecords().get(0);
KeeperFile file = firstRecord.getFileByName("acme.cer");
byte[] fileBytes = SecretsManager.downloadThumbnail(file);
// ファイルをディスクに書き込む
try (FileOutputStream fos = new FileOutputStream(file.getData().getName())) {
fos.write(fileBytes);
} catch (IOException ioException){
ioException.printStackTrace();
}file
KeeperFile
はい
ダウンロードするサムネイル付きファイル
レスポンス
型: ByteArray
ダウンロード用サムネイルのバイト配列
ファイルのアップロード
ファイルのアップロード
uploadFile(options:SecretsManagerOptions, ownerRecord:KeeperRecord, file:KeeperFileUpload):Stringoptions
SecretsManagerOptions
はい
ストレージとクエリの設定
ownerRecord
KeeperRecord
はい
アップロードされたファイルを添付するレコード
file
KeeperFileUpload
はい
アップロードするファイル
Keeperファイルアップロードオブジェクトを作成
KeeperFileUpload(
val name:String,
val title:String,
val type:String?,
val data:ByteArray
)name
string
はい
アップロード後にKeeperに格納されるファイルの名前
title
string
はい
アップロード後にKeeperに格納されるファイルのタイトル
type
string
オプション
ファイルのデータのMIMEタイプ。何も指定しない場合は、「application/octet-stream」が使用されます
data
ByteArray
はい
バイト型のファイルデータ
使用例
import com.keepersecurity.secretsManager.core.*;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
public class KSMSample {
public static void main(String[] args){
// セキュリティプロバイダがロードされていることを確認
Security.addProvider(new BouncyCastleFipsProvider());
// 事前に初期化されたストレージを取得
KeyValueStorage storage = new LocalConfigStorage("ksm-config.json");
try {
SecretsManagerOptions options = new SecretsManagerOptions(storage);
// 必要なレコードのUIDを含むフィルタを作成
List<String> uidFilter = List.of("XXX");
// フィルタを使用してシークレットを取得
KeeperSecrets secrets = SecretsManager.getSecrets(options, uidFilter);
// ファイルのアップロード先のシークレットを取得
KeeperRecord ownerRecord = secrets.getRecords().get(0);
// アップロードするファイルからバイトを取得
File file = new File("./myFile.json");
FileInputStream fl = new FileInputStream(file);
byte[] fileBytes = new byte[(int)file.length()];
fl.read(fileBytes);
fl.close();
// アップロードするKeeperファイルを作成
KeeperFileUpload myFile = new KeeperFileUpload(
"myFile.json",
"My File",
"application/json",
fileBytes
)
// 選択したレコードにファイルをアップロード
SecretsManager.uploadFile(options, ownerRecord, myFile);
} catch (Exception e) {
System.out.println("KSM ran into an problem: " + e.getMessage());
}
}
}レコードからファイルを削除する
必要なSDKバージョン: 17.1.1以上
UpdateOptions クラスの linksToRemove パラメータを使用して、レコードからファイル添付を削除できます。
要件
ファイルを含むレコードのUID、または
KeeperRecordオブジェクト削除するファイルのファイルUID
削除対象のファイルがレコード上に存在していること
options
SecretsManagerOptions
はい
事前設定されたオプション
record
KeeperRecord
はい
更新対象のレコード
updateOptions
UpdateOptions
はい
削除するファイルを含むオプション
transactionType
UpdateTransactionType
いいえ
null
バッチ処理のトランザクションタイプ
linksToRemove
List<String>
はい
削除するファイルUIDのリスト
// // "temp_"で始まるファイルを削除
List<String> filesToRemove = new ArrayList<>();
for (KeeperFile file : record.getFiles()) {
if (file.getData().getTitle().startsWith("temp_")) {
filesToRemove.add(file.getFileUid());
}
}
if (!filesToRemove.isEmpty()) {
UpdateOptions updateOptions = new UpdateOptions(null, filesToRemove);
SecretsManager.updateSecretWithOptions(options, record, updateOptions);
}// "temp_"で始まるファイルを削除
val filesToRemove = record.files
?.filter { it.data?.title?.startsWith("temp_") == true }
?.map { it.fileUid }
?: emptyList()
if (filesToRemove.isNotEmpty()) {
updateSecretWithOptions(
options,
record,
UpdateOptions(linksToRemove = filesToRemove)
)
}完全な使用例
import com.keepersecurity.secretsManager.core.*;
import java.util.*;
// ファイル付きのレコードを取得
QueryOptions queryOptions = new QueryOptions(
Arrays.asList(recordUid),
Collections.emptyList(),
true // ファイルをリクエスト
);
KeeperSecrets secrets = SecretsManager.getSecrets2(options, queryOptions);
KeeperRecord record = secrets.getRecords().get(0);
// 特定のファイルを削除
List<String> fileUidsToRemove = Arrays.asList("fileUid1", "fileUid2");
UpdateOptions updateOptions = new UpdateOptions(
null, // transactionType
fileUidsToRemove // linksToRemove
);
SecretsManager.updateSecretWithOptions(options, record, updateOptions);シークレットの作成
要件
共有フォルダのUID
共有フォルダには、シークレットマネージャーアプリケーションからアクセスできる必要があります。
ユーザーとシークレットマネージャーアプリケーションには編集権限が必要です。
共有フォルダには、少なくとも1つのレコードが存在する必要があります。
作成されたレコードとレコードのフィールドは正しく形式である必要があります。
レコードタイプごとの適切なフィールド形式については、こちらのページをご参照ください。
TOTPフィールドには、KSM SDK以外で生成されたURLのみを指定できます。
レコード作成後、uploadFileファイルをで添付ファイルをアップロードできます。
SecretsManager.createSecret(options, folderUid, newRecordData, secrets);options
SecretsManagerOptions
はい
folderUid
String
はい
newRecordData
KeeperRecordData
はい
secrets
KeeperSecrets
オプション
Keeperサーバーから新たに取得したすべてのシークレットのリスト
SecretsManager.createSecret2(options, createOptions, newRecordData, folders);options
SecretsManagerOptions
はい
createOptions
CreateOptions
はい
newRecordData
KeeperRecordData
はい
folderss
KeeperFolder[]s
オプション
Keeperサーバーから新たに取得したすべてのフォルダのリスト
この例では、ログイン値と生成されたパスワードを含むログインタイプのレコードを作成します。
import com.keepersecurity.secretsManager.core.*;
KeeperRecordData newRecordData = new KeeperRecordData(
"Sample KSM Record:Java",
"login",
Arrays.asList(
new Login("My Username"),
new Password(CryptoUtils.generatePassword())
),
null,
"This is a \nmultiline\n\n\tnote"
);
String recordUid = SecretsManager.createSecret(options, folderUid, newRecordData);この例では、カスタムレコードタイプのレコードを作成します。
import com.keepersecurity.secretsManager.core.*;
KeeperRecordData newRecordData = new KeeperRecordData(
"Sample Custom Type KSM Record:Java",
"Custom Login", // レコードタイプの名前
Arrays.asList(
new Hosts(
"My Custom Host lbl", // ラベル
true, // 必須
false, // プライベートスクリーン
List.of(new Host("127.0.0.1", "8000"))),
// または new Hosts(new Host("127.0.0.1", "8000"))
new Login("My Custom Login lbl",
true,
false,
List.of("[email protected]")),
// または new Login("[email protected]")
new Password( "My Custom Password lbl",
true,
false,
List.of(CryptoUtils.generatePassword())),
// または new Password(CryptoUtils.generatePassword())
new Url("My Login Page",
true,
false,
List.of("http://localhost:8080/login")),
// または new Url("http://localhost:8080/login")
new SecurityQuestions(
"My Question 1",
true,
false,
List.of(new SecurityQuestion("What is one plus one (write just a number)", "2"))),
// または new SecurityQuestions(new SecurityQuestion("What is one plus one (write just a number)", "2"))
new Phones("My Phone Number",
true,
false,
List.of(new Phone("US", "510-444-3333", "2345", "Mobile"))),
// または new Phones(new Phone("US", "510-444-3333", "2345", "Mobile"))
new Date("My Date Lbl",
true,
false,
List.of(1641934793000L)
),
// または new Date(1641934793000L),
new Names("My Custom Name lbl",
true,
false,
List.of(new Name("John", "Patrick", "Smith"))),
// または new Names(new Name("John", "Patrick", "Smith"))
new OneTimeCode("My TOTP",
true,
false,
List.of("otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example"))
// または new OneTimeCode("otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example")
),
Arrays.asList(
new Phones(new Phone("US", "(510) 123-3456")),
new Phones(new Phone("US", "510-111-3333", "45674", "Mobile"))
),
"\tThis custom type record was created\n\tvia KSM Java Document Example"
);
String recordUid = SecretsManager.createSecret(options, "[FOLDER UID]", newRecordData);シークレットの削除
Java/Kotlin KSM SDKでKeeperボルトのレコードを削除できます。
deleteSecret(smOptions, recordUids);smOptions
SecretsManagerOptions
はい
recordUids
List<Sting>
はい
// シークレットマネージャーを設定
val storage = LocalConfigStorage("ksm-config.json")
//initializeStorage(storage, "<One Time Access Token>")
val smOptions = SecretsManagerOptions(storage)
// UIDレコードで特定のシークレットを削除
deleteSecret(smOptions, List.of("EG6KdJaaLG7esRZbMnfbFA"));キャッシュ
ネットワークアクセスが失われたときにシークレットにアクセスできない状況を避けるため、Java SDKを使用してシークレットを暗号化されたファイルを使用してローカルマシンにキャッシュできます。
キャッシュの設定と構成
Java SDKでキャッシュを設定するには、SecretsManagerOptions オブジェクトをインスタンス化するときに、2番目の引数としてキャッシュポスト関数を指定します。
Java SDKには、クエリをキャッシュしてファイルに保存するデフォルトのキャッシュ関数cachingPostFunction が含まれています。
// キャッシュオプションを作成
SecretsManagerOptions options = new SecretsManagerOptions(storage, SecretsManager::cachingPostFunction);
// 例すべてのシークレットを取得
SecretsManager.getSecrets(options)フォルダ
フォルダは完全なCRUD (作成、読み取り、更新、削除操作) をサポートしています。
フォルダの読み取り
フォルダの完全な階層構造をダウンロードします。
getFolders(options:SecretsManagerOptions):List<KeeperFolder>レスポンス
型: List<KeeperFolder>
使用例
import com.keepersecurity.secretsManager.core.*;
SecretsManagerOptions options = new SecretsManagerOptions(new LocalConfigStorage("ksm-config.json"));
List<KeeperFolder> folders = SecretsManager.getFolders(options);フォルダの作成
CreateOptions とフォルダ名の指定が必要です。CreateOptions はフォルダのUIDパラメータ (共有フォルダのUID) が必須ですが、サブフォルダのUIDはオプションであり、指定されていない場合は、通常の新しいフォルダが親 (共有フォルダ) の直下に作成されます。サブフォルダは、親の共有フォルダの直接の下位オブジェクトである必要はありません。親フォルダから何階層も深い位置にサブフォルダを作成することができます。
createFolder(options:SecretsManagerOptions, createOptions:CreateOptions, folderName:String, folders:List<KeeperFolder> = getFolders(options)):Stringoptions
SecretsManagerOptions
はい
事前に設定されたオプション
createOptions
CreateOptions
はい
親およびサブフォルダのUID
folderName
String
はい
フォルダ名
folders
List<KeeperFolder>
いいえ
List<KeeperFolder>
CreateOptionsで作成した親とサブフォルダの検索に使用するフォルダのリスト
data class CreateOptions constructor(
val folderUid:String,
val subFolderUid:String? = null,
)data class KeeperFolder(
val folderKey:ByteArray,
val folderUid:String,
val parentUid:String? = null,
val name:String
)使用例
import com.keepersecurity.secretsManager.core.*;
SecretsManagerOptions options = new SecretsManagerOptions(new LocalConfigStorage("ksm-config.json"));
CreateOptions co := new CreateOptions("[SHARED_FOLDER_UID]");
String folderUid = SecretsManager.createFolder(options, co, "new_folder");フォルダの更新
フォルダのメタデータ (現在はフォルダ名のみ) を更新します。
updateFolder(options:SecretsManagerOptions, folderUid:String, folderName:String, folders:List<KeeperFolder> = getFolders(options))options
SecretsManagerOptions
はい
事前に設定されたオプション
folderUid
String
はい
フォルダのUID
folderName
String
はい
新しいフォルダ名
folders
List<KeeperFolder>
いいえ
List<KeeperFolder>
親フォルダの検索に使用するフォルダのリスト
使用例
import com.keepersecurity.secretsManager.core.*;
SecretsManagerOptions options = new SecretsManagerOptions(new LocalConfigStorage("ksm-config.json"));
SecretsManager.updateFolder(options, "[FOLDER_UID]", "new_folder_name");フォルダの削除
フォルダのリストを削除します。空でないフォルダを削除するには、forceDeletionフラグを使用します。
deleteFolder(options:SecretsManagerOptions, folderUids:List<String>, forceDeletion:Boolean = false):SecretsManagerDeleteResponseoptions
SecretsManagerOptions
はい
事前に設定されたオプション
folderUids
List<String>
はい
フォルダUIDリスト
forceDeletion
Boolean
いいえ
false
空でないフォルダを強制的に削除
使用例
import com.keepersecurity.secretsManager.core.*;
SecretsManagerOptions options = new SecretsManagerOptions(new LocalConfigStorage("ksm-config.json"));
SecretsManager.deleteFolder(options, Arrays.asList("[FOLDER_UID1]", "[FOLDER_UID2]"), true);PAMレコードタイプ - リンク済み認証情報へのアクセス
必要なSDKバージョン: 17.1.1 以上
PAMリソースレコードタイプ (PAMマシン、PAMディレクトリ、PAMデータベース) では、以下の認証情報をリンクできます。
管理者認証情報 リソース上で管理操作を実行するために使用される認証情報
接続用認証情報 リソースへのセッションを起動する際の認証に使用される認証情報
要件
getSecrets()ではなく、getSecrets2()メソッドを使用することQueryOptionsでrequestLinks = trueを設定し、GraphSync™を有効化することrequestLinks = falseの場合、linksはnullになりますrequestLinks = trueでもリンクが存在しない場合、linksは空のリストになります
options
SecretsManagerOptions
はい
なし
事前に構成されたオプション
queryOptions
QueryOptions
はい
なし
requestLinks=true を設定する必要があります
QueryOptionsのパラメータ
recordsFilter
List
はい
空
レコードUIDでフィルタリング
foldersFilter
List
いいえ
空
フォルダUIDでフィルタリング
requestLinks
boolean
はい
false
GraphSync™を有効にするにはtrueに設定する必要があります
リンク方式
getRecordUid()
String
対象レコードのUID
isAdminUser()
boolean
管理者権限を持つ場合にtrue
allowsRotation()
boolean
ローテーションが許可されている場合にtrue
allowsConnections()
boolean
接続が許可されている場合にtrue
基本的な使い方 - リンク付きレコードの取得
import com.keepersecurity.secretsManager.core.*;
import java.util.*;
// GraphSync™ を有効化
QueryOptions queryOptions = new QueryOptions(
Collections.emptyList(), // recordsFilter
Collections.emptyList(), // foldersFilter
true // requestLinks - 必須
);
SecretsManagerOptions options = new SecretsManagerOptions(storage);
KeeperSecrets secrets = SecretsManager.getSecrets2(options, queryOptions);
// リンクへアクセス
for (KeeperRecord record : secrets.getRecords()) {
List<KeeperRecordLink> links = record.getLinks();
if (links != null && !links.isEmpty()) {
for (KeeperRecordLink link : links) {
System.out.println("リンク先: " + link.getRecordUid());
}
}
}リンクプロパティの確認
for (KeeperRecordLink link : record.getLinks()) {
// ユーザー権限を確認
if (link.isAdminUser()) {
System.out.println("管理者ユーザー");
}
// パーミッションを確認
if (link.allowsRotation()) {
System.out.println("パスワードのローテーションが許可されています");
}
}一般的な例 - PAMユーザーの検索
// PAMマシンに関連付けられているユーザーを検索
for (KeeperRecord machine : secrets.getRecords()) {
if ("pamMachine".equals(machine.getType())) {
System.out.println("PAMマシン: " + machine.getTitle());
List<KeeperRecordLink> links = machine.getLinks();
if (links != null) {
for (KeeperRecordLink link : links) {
// ユーザーが管理者かどうか確認
if (link.isAdminUser()) {
System.out.println(" 管理者ユーザー: " + link.getRecordUid());
}
}
}
}
}追加情報
PAMレコードタイプで取得可能なフィールドの詳細については、レコードフィールドクラスのページをご参照ください。
高度なPAM活用事例におけるリンク済み認証情報の扱いについては、PAMレコードのリンク済み認証情報のページをご覧ください。
最終更新

