diff --git a/src/main/java/com/bettercloud/vault/VaultConfig.java b/src/main/java/com/bettercloud/vault/VaultConfig.java index cdb771d7..f4f9e42e 100644 --- a/src/main/java/com/bettercloud/vault/VaultConfig.java +++ b/src/main/java/com/bettercloud/vault/VaultConfig.java @@ -209,17 +209,18 @@ public VaultConfig readTimeout(final Integer readTimeout) { } /** - * Sets the "path depth" of the prefix path. This defaults to 1, corresponding to one - * path element in the prefix path. To use a longer prefix path, set this value. + *
Set the "path depth" of the prefix path. Normally this is just + * 1, to correspond to one path element in the prefix path. To use + * a longer prefix path, set this value.
* * @param pathLength integer number of path elements in the prefix path */ - public VaultConfig prefixPathDepth(int pathLength) { - if (pathLength < 1) { + public VaultConfig prefixPathDepth(int prefixPathDepth) { + if (prefixPathDepth < 1) { throw new IllegalArgumentException("pathLength must be > 1"); } - this.prefixPathDepth = pathLength; + this.prefixPathDepth = prefixPathDepth; return this; } diff --git a/src/main/java/com/bettercloud/vault/api/Auth.java b/src/main/java/com/bettercloud/vault/api/Auth.java index 812d7682..4907e571 100644 --- a/src/main/java/com/bettercloud/vault/api/Auth.java +++ b/src/main/java/com/bettercloud/vault/api/Auth.java @@ -355,7 +355,9 @@ public AuthResponse createToken(final TokenRequest tokenRequest, final String to // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -421,7 +423,9 @@ public AuthResponse loginByAppID(final String path, final String appId, final St // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -515,7 +519,9 @@ public AuthResponse loginByAppRole(final String path, final String roleId, final // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -598,7 +604,9 @@ public AuthResponse loginByUserPass(final String username, final String password // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -720,7 +728,9 @@ public AuthResponse loginByAwsEc2(final String role, final String identity, fina // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -796,7 +806,9 @@ public AuthResponse loginByAwsEc2(final String role, final String pkcs7, final S // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -875,7 +887,9 @@ public AuthResponse loginByAwsIam(final String role, final String iamRequestUrl, // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -960,7 +974,9 @@ public AuthResponse loginByGithub(final String githubToken, final String githubA // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -1024,7 +1040,9 @@ public AuthResponse loginByJwt(final String provider, final String role, final S // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -1163,7 +1181,8 @@ public AuthResponse loginByCert(final String certAuthMount) throws VaultExceptio // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); @@ -1246,7 +1265,9 @@ public AuthResponse renewSelf(final long increment, final String tokenAuthMount) // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType(); if (!mimeType.equals("application/json")) { @@ -1308,7 +1329,9 @@ public LookupResponse lookupSelf(final String tokenAuthMount) throws VaultExcept // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } final String mimeType = restResponse.getMimeType(); if (!"application/json".equals(mimeType)) { @@ -1432,7 +1455,9 @@ public void revokeSelf(final String tokenAuthMount) throws VaultException { // Validate restResponse if (restResponse.getStatus() != 204) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus()); + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), + restResponse.getStatus()); } return; } catch (Exception e) { @@ -1534,7 +1559,8 @@ public AuthResponse unwrap(final String wrappedToken) throws VaultException { // Validate restResponse if (restResponse.getStatus() != 200) { - throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), + throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus() + + "\nResponse body: " + new String(restResponse.getBody(), StandardCharsets.UTF_8), restResponse.getStatus()); } final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();