You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Builder-style class for use with {@link #createToken(TokenRequest)}
25
+
*
26
+
* <p>All properties are optional and can be <code>null</code>.</p>
27
+
*/
28
+
publicstaticclassTokenRequest {
29
+
/**
30
+
* (optional) The ID of the client token. Can only be specified by a root token. Otherwise, the token ID is a randomly generated UUID.
31
+
*/
32
+
privateUUIDid;
33
+
34
+
/**
35
+
* (optional) A list of policies for the token. This must be a subset of the policies belonging to the token making the request, unless root. If not specified, defaults to all the policies of the calling token.
36
+
*/
37
+
privateList<String> polices;
38
+
39
+
/**
40
+
* (optional) A map of string to string valued metadata. This is passed through to the audit backends.
41
+
*/
42
+
privateMap<String, String> meta;
43
+
44
+
/**
45
+
* (optional) If true and set by a root caller, the token will not have the parent token of the caller. This creates a token with no parent.
46
+
*/
47
+
privateBooleannoParent;
48
+
49
+
/**
50
+
* (optional) If <code>true</code> the default policy will not be a part of this token's policy set.
51
+
*/
52
+
privateBooleannoDefaultPolicy;
53
+
54
+
/**
55
+
* (optional) The TTL period of the token, provided as "1h", where hour is the largest suffix. If not provided, the token is valid for the default lease TTL, or indefinitely if the root policy is used.
56
+
*/
57
+
privateStringttl;
58
+
59
+
/**
60
+
* (optional) The display name of the token. Defaults to "token".
61
+
*/
62
+
privateStringdisplayName;
63
+
64
+
/**
65
+
* (optional) The maximum uses for the given token. This can be used to create a one-time-token or limited use token. Defaults to 0, which has no limit to the number of uses.
66
+
*/
67
+
privateLongnumUses;
68
+
69
+
/**
70
+
* (optional) The role the token will be created with. Default is no role.
@@ -56,7 +240,9 @@ public Auth(final VaultConfig config) {
56
240
* @param numUses (optional) The maximum uses for the given token. This can be used to create a one-time-token or limited use token. Defaults to 0, which has no limit to the number of uses.
57
241
* @return The auth token
58
242
* @throws VaultException If any error occurs, or unexpected response received from Vault
243
+
* @deprecated Use {@link #createToken(TokenRequest)}
59
244
*/
245
+
@Deprecated
60
246
publicAuthResponsecreateToken(
61
247
finalUUIDid,
62
248
finalList<String> policies,
@@ -67,32 +253,63 @@ public AuthResponse createToken(
67
253
finalStringdisplayName,
68
254
finalLongnumUses
69
255
) throwsVaultException {
256
+
returncreateToken(
257
+
newTokenRequest()
258
+
.withId(id)
259
+
.withPolices(policies)
260
+
.withMeta(meta)
261
+
.withNoParent(noParent)
262
+
.withNoDefaultPolicy(noDefaultPolicy)
263
+
.withTtl(ttl)
264
+
.withDisplayName(displayName)
265
+
.withNumUses(numUses));
266
+
}
267
+
268
+
269
+
/**
270
+
* <p>Operation to create an authentication token. Relies on another token already being present in
271
+
* the <code>VaultConfig</code> instance. Example usage:</p>
272
+
*
273
+
* <blockquote>
274
+
* <pre>{@code
275
+
* final VaultConfig config = new VaultConfig(address, rootToken);
276
+
* final Vault vault = new Vault(config);
277
+
* final AuthResponse response = vault.auth().createToken(new TokenRequest().withTtl("1h"));
278
+
*
279
+
* final String token = response.getAuthClientToken();
* final Map<String, String> nameValuePairs = new HashMap<String, String>();
96
+
* final Map<String, String> nameValuePairs = new HashMap<String, Object>();
97
97
* nameValuePairs.put("value", "foo");
98
98
* nameValuePairs.put("other_value", "bar");
99
99
*
100
100
* final LogicalResponse response = vault.logical().write("secret/hello", nameValuePairs);
101
101
* }</pre>
102
102
* </blockquote>
103
103
*
104
+
* <p>The values in these name-value pairs may be booleans, numerics, strings, or nested JSON objects. However,
105
+
* be aware that this method does not recursively parse any nested structures. If you wish to write arbitrary
106
+
* JSON objects to Vault... then you should parse them to JSON outside of this method, and pass them here as JSON
107
+
* strings.</p>
108
+
*
104
109
* @param path The Vault key value to which to write (e.g. <code>secret/hello</code>)
105
110
* @param nameValuePairs Secret name and value pairs to store under this Vault key (can be <code>null</code> for writing to keys that do not need or expect any fields to be specified)
106
111
* @return The response information received from Vault
107
112
* @throws VaultException If any errors occurs with the REST request, and the maximum number of retries is exceeded.
0 commit comments