Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/main/java/com/bettercloud/vault/api/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.Getter;

import java.io.Serializable;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -225,7 +224,7 @@ 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 createFailedRestCallException(restResponse);
}
final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();
if (!mimeType.equals("application/json")) {
Expand Down Expand Up @@ -290,7 +289,7 @@ 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 createFailedRestCallException(restResponse);
}
final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();
if (!mimeType.equals("application/json")) {
Expand Down Expand Up @@ -383,7 +382,7 @@ 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 createFailedRestCallException(restResponse);
}
final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();
if (!mimeType.equals("application/json")) {
Expand Down Expand Up @@ -466,7 +465,7 @@ 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 createFailedRestCallException(restResponse);
}
final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();
if (!mimeType.equals("application/json")) {
Expand Down Expand Up @@ -589,7 +588,7 @@ 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 createFailedRestCallException(restResponse);
}
final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();
if (!mimeType.equals("application/json")) {
Expand Down Expand Up @@ -666,7 +665,7 @@ 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 createFailedRestCallException(restResponse);
}
final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();
if (!mimeType.equals("application/json")) {
Expand All @@ -693,6 +692,11 @@ public AuthResponse loginByAwsEc2(final String role, final String pkcs7, final S
}
}

private VaultException createFailedRestCallException(RestResponse restResponse) {
return new VaultException(String.format("Vault responded with HTTP status code: %s - Response Body: %s",
restResponse.getStatus(), new String(restResponse.getBody())), restResponse.getStatus());
}

/**
* <p>Basic login operation to authenticate to a AWS backend using IAM authentication. Example usage:</p>
*
Expand Down Expand Up @@ -746,7 +750,7 @@ 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 createFailedRestCallException(restResponse);
}
final String mimeType = restResponse.getMimeType() == null ? "null" : restResponse.getMimeType();
if (!mimeType.equals("application/json")) {
Expand Down