Code style
A number of style corrections in main source files. Trimmed lines to 120 characters, added some spaces and line breaks. Removed unused imports
This commit is contained in:
parent
259747afae
commit
42094101a3
@ -29,7 +29,6 @@ import org.apache.http.client.utils.URIBuilder;
|
|||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.params.HttpConnectionParams;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
@ -39,7 +38,6 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vault Connector implementatin using Vault's HTTP API.
|
* Vault Connector implementatin using Vault's HTTP API.
|
||||||
*
|
*
|
||||||
@ -103,10 +101,10 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
* @param prefix HTTP API prefix (default: /v1/)
|
* @param prefix HTTP API prefix (default: /v1/)
|
||||||
*/
|
*/
|
||||||
public HTTPVaultConnector(final String hostname, final boolean useTLS, final Integer port, final String prefix) {
|
public HTTPVaultConnector(final String hostname, final boolean useTLS, final Integer port, final String prefix) {
|
||||||
this(((useTLS) ? "https" : "http") +
|
this(((useTLS) ? "https" : "http")
|
||||||
"://" + hostname +
|
+ "://" + hostname
|
||||||
((port != null) ? ":" + port : "") +
|
+ ((port != null) ? ":" + port : "")
|
||||||
prefix);
|
+ prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,7 +116,11 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
* @param prefix HTTP API prefix (default: /v1/)
|
* @param prefix HTTP API prefix (default: /v1/)
|
||||||
* @param sslContext Custom SSL Context
|
* @param sslContext Custom SSL Context
|
||||||
*/
|
*/
|
||||||
public HTTPVaultConnector(final String hostname, final boolean useTLS, final Integer port, final String prefix, final SSLContext sslContext) {
|
public HTTPVaultConnector(final String hostname,
|
||||||
|
final boolean useTLS,
|
||||||
|
final Integer port,
|
||||||
|
final String prefix,
|
||||||
|
final SSLContext sslContext) {
|
||||||
this(hostname, useTLS, port, prefix, sslContext, 0, null);
|
this(hostname, useTLS, port, prefix, sslContext, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,11 +135,17 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
* @param numberOfRetries Number of retries on 5xx errors
|
* @param numberOfRetries Number of retries on 5xx errors
|
||||||
* @param timeout Timeout for HTTP requests (milliseconds)
|
* @param timeout Timeout for HTTP requests (milliseconds)
|
||||||
*/
|
*/
|
||||||
public HTTPVaultConnector(final String hostname, final boolean useTLS, final Integer port, final String prefix, final SSLContext sslContext, final int numberOfRetries, final Integer timeout) {
|
public HTTPVaultConnector(final String hostname,
|
||||||
this(((useTLS) ? "https" : "http") +
|
final boolean useTLS,
|
||||||
"://" + hostname +
|
final Integer port,
|
||||||
((port != null) ? ":" + port : "") +
|
final String prefix,
|
||||||
prefix,
|
final SSLContext sslContext,
|
||||||
|
final int numberOfRetries,
|
||||||
|
final Integer timeout) {
|
||||||
|
this(((useTLS) ? "https" : "http")
|
||||||
|
+ "://" + hostname
|
||||||
|
+ ((port != null) ? ":" + port : "")
|
||||||
|
+ prefix,
|
||||||
sslContext,
|
sslContext,
|
||||||
numberOfRetries,
|
numberOfRetries,
|
||||||
timeout);
|
timeout);
|
||||||
@ -181,7 +189,10 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
* @param numberOfRetries Number of retries on 5xx errors
|
* @param numberOfRetries Number of retries on 5xx errors
|
||||||
* @param timeout Timeout for HTTP requests (milliseconds)
|
* @param timeout Timeout for HTTP requests (milliseconds)
|
||||||
*/
|
*/
|
||||||
public HTTPVaultConnector(final String baseURL, final SSLContext sslContext, final int numberOfRetries, final Integer timeout) {
|
public HTTPVaultConnector(final String baseURL,
|
||||||
|
final SSLContext sslContext,
|
||||||
|
final int numberOfRetries,
|
||||||
|
final Integer timeout) {
|
||||||
this.baseURL = baseURL;
|
this.baseURL = baseURL;
|
||||||
this.sslContext = sslContext;
|
this.sslContext = sslContext;
|
||||||
this.retries = numberOfRetries;
|
this.retries = numberOfRetries;
|
||||||
@ -272,7 +283,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final AuthResponse authUserPass(final String username, final String password) throws VaultConnectorException {
|
public final AuthResponse authUserPass(final String username, final String password)
|
||||||
|
throws VaultConnectorException {
|
||||||
final Map<String, String> payload = new HashMap<>();
|
final Map<String, String> payload = new HashMap<>();
|
||||||
payload.put("password", password);
|
payload.put("password", password);
|
||||||
return queryAuth(PATH_AUTH_USERPASS + username, payload);
|
return queryAuth(PATH_AUTH_USERPASS + username, payload);
|
||||||
@ -304,7 +316,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
* @return The AuthResponse
|
* @return The AuthResponse
|
||||||
* @throws VaultConnectorException on errors
|
* @throws VaultConnectorException on errors
|
||||||
*/
|
*/
|
||||||
private AuthResponse queryAuth(final String path, final Map<String, String> payload) throws VaultConnectorException {
|
private AuthResponse queryAuth(final String path, final Map<String, String> payload)
|
||||||
|
throws VaultConnectorException {
|
||||||
try {
|
try {
|
||||||
/* Get response */
|
/* Get response */
|
||||||
String response = requestPost(path, payload);
|
String response = requestPost(path, payload);
|
||||||
@ -322,7 +335,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final boolean registerAppId(final String appID, final String policy, final String displayName) throws VaultConnectorException {
|
public final boolean registerAppId(final String appID, final String policy, final String displayName)
|
||||||
|
throws VaultConnectorException {
|
||||||
if (!isAuthorized())
|
if (!isAuthorized())
|
||||||
throw new AuthorizationRequiredException();
|
throw new AuthorizationRequiredException();
|
||||||
Map<String, String> payload = new HashMap<>();
|
Map<String, String> payload = new HashMap<>();
|
||||||
@ -427,7 +441,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final AppRoleSecretResponse createAppRoleSecret(final String roleName, final AppRoleSecret secret) throws VaultConnectorException {
|
public final AppRoleSecretResponse createAppRoleSecret(final String roleName, final AppRoleSecret secret)
|
||||||
|
throws VaultConnectorException {
|
||||||
if (!isAuthorized())
|
if (!isAuthorized())
|
||||||
throw new AuthorizationRequiredException();
|
throw new AuthorizationRequiredException();
|
||||||
/* Get response */
|
/* Get response */
|
||||||
@ -446,12 +461,15 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final AppRoleSecretResponse lookupAppRoleSecret(final String roleName, final String secretID) throws VaultConnectorException {
|
public final AppRoleSecretResponse lookupAppRoleSecret(final String roleName, final String secretID)
|
||||||
|
throws VaultConnectorException {
|
||||||
if (!isAuthorized())
|
if (!isAuthorized())
|
||||||
throw new AuthorizationRequiredException();
|
throw new AuthorizationRequiredException();
|
||||||
/* Request HTTP response and parse Secret */
|
/* Request HTTP response and parse Secret */
|
||||||
try {
|
try {
|
||||||
String response = requestPost(PATH_AUTH_APPROLE + "role/" + roleName + "/secret-id/lookup", new AppRoleSecret(secretID));
|
String response = requestPost(
|
||||||
|
PATH_AUTH_APPROLE + "role/" + roleName + "/secret-id/lookup",
|
||||||
|
new AppRoleSecret(secretID));
|
||||||
return jsonMapper.readValue(response, AppRoleSecretResponse.class);
|
return jsonMapper.readValue(response, AppRoleSecretResponse.class);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new InvalidResponseException("Unable to parse response", e);
|
throw new InvalidResponseException("Unable to parse response", e);
|
||||||
@ -459,12 +477,15 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean destroyAppRoleSecret(final String roleName, final String secretID) throws VaultConnectorException {
|
public final boolean destroyAppRoleSecret(final String roleName, final String secretID)
|
||||||
|
throws VaultConnectorException {
|
||||||
if (!isAuthorized())
|
if (!isAuthorized())
|
||||||
throw new AuthorizationRequiredException();
|
throw new AuthorizationRequiredException();
|
||||||
|
|
||||||
/* Request HTTP response and expect empty result */
|
/* Request HTTP response and expect empty result */
|
||||||
String response = requestPost(PATH_AUTH_APPROLE + "role/" + roleName + "/secret-id/destroy", new AppRoleSecret(secretID));
|
String response = requestPost(
|
||||||
|
PATH_AUTH_APPROLE + "role/" + roleName + "/secret-id/destroy",
|
||||||
|
new AppRoleSecret(secretID));
|
||||||
|
|
||||||
/* Response should be code 204 without content */
|
/* Response should be code 204 without content */
|
||||||
if (!response.equals(""))
|
if (!response.equals(""))
|
||||||
@ -496,7 +517,9 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
throw new AuthorizationRequiredException();
|
throw new AuthorizationRequiredException();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String response = requestGet(PATH_AUTH_APPROLE + "role/" + roleName + "/secret-id?list=true", new HashMap<>());
|
String response = requestGet(
|
||||||
|
PATH_AUTH_APPROLE + "role/" + roleName + "/secret-id?list=true",
|
||||||
|
new HashMap<>());
|
||||||
SecretListResponse secrets = jsonMapper.readValue(response, SecretListResponse.class);
|
SecretListResponse secrets = jsonMapper.readValue(response, SecretListResponse.class);
|
||||||
return secrets.getKeys();
|
return secrets.getKeys();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -744,7 +767,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
* @throws VaultConnectorException on connection error
|
* @throws VaultConnectorException on connection error
|
||||||
* @throws URISyntaxException on invalid URI syntax
|
* @throws URISyntaxException on invalid URI syntax
|
||||||
*/
|
*/
|
||||||
private String requestGet(final String path, final Map<String, String> payload) throws VaultConnectorException, URISyntaxException {
|
private String requestGet(final String path, final Map<String, String> payload)
|
||||||
|
throws VaultConnectorException, URISyntaxException {
|
||||||
/* Add parameters to URI */
|
/* Add parameters to URI */
|
||||||
URIBuilder uriBuilder = new URIBuilder(baseURL + path);
|
URIBuilder uriBuilder = new URIBuilder(baseURL + path);
|
||||||
payload.forEach(uriBuilder::addParameter);
|
payload.forEach(uriBuilder::addParameter);
|
||||||
@ -784,7 +808,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
|
|
||||||
switch (response.getStatusLine().getStatusCode()) {
|
switch (response.getStatusLine().getStatusCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
|
try (BufferedReader br = new BufferedReader(
|
||||||
|
new InputStreamReader(response.getEntity().getContent()))) {
|
||||||
return br.lines().collect(Collectors.joining("\n"));
|
return br.lines().collect(Collectors.joining("\n"));
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
@ -793,7 +818,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
case 403:
|
case 403:
|
||||||
throw new PermissionDeniedException();
|
throw new PermissionDeniedException();
|
||||||
default:
|
default:
|
||||||
if (response.getStatusLine().getStatusCode() >= 500 && response.getStatusLine().getStatusCode() < 600 && retries > 0) {
|
if (response.getStatusLine().getStatusCode() >= 500
|
||||||
|
&& response.getStatusLine().getStatusCode() < 600 && retries > 0) {
|
||||||
/* Retry on 5xx errors */
|
/* Retry on 5xx errors */
|
||||||
return request(base, retries - 1);
|
return request(base, retries - 1);
|
||||||
} else {
|
} else {
|
||||||
@ -801,7 +827,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
InvalidResponseException ex = new InvalidResponseException("Invalid response code")
|
InvalidResponseException ex = new InvalidResponseException("Invalid response code")
|
||||||
.withStatusCode(response.getStatusLine().getStatusCode());
|
.withStatusCode(response.getStatusLine().getStatusCode());
|
||||||
if (response.getEntity() != null) {
|
if (response.getEntity() != null) {
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
|
try (BufferedReader br = new BufferedReader(
|
||||||
|
new InputStreamReader(response.getEntity().getContent()))) {
|
||||||
String responseString = br.lines().collect(Collectors.joining("\n"));
|
String responseString = br.lines().collect(Collectors.joining("\n"));
|
||||||
ErrorResponse er = jsonMapper.readValue(responseString, ErrorResponse.class);
|
ErrorResponse er = jsonMapper.readValue(responseString, ErrorResponse.class);
|
||||||
/* Check for "permission denied" response */
|
/* Check for "permission denied" response */
|
||||||
|
@ -144,7 +144,8 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @deprecated As of Vault 0.6.1 App-ID is superseded by AppRole. Consider using {@link #createAppRole} instead.
|
* @deprecated As of Vault 0.6.1 App-ID is superseded by AppRole. Consider using {@link #createAppRole} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
boolean registerAppId(final String appID, final String policy, final String displayName) throws VaultConnectorException;
|
boolean registerAppId(final String appID, final String policy, final String displayName)
|
||||||
|
throws VaultConnectorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new AppRole role from given metamodel.
|
* Register a new AppRole role from given metamodel.
|
||||||
@ -204,7 +205,8 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
default boolean createAppRole(final String roleName, final List<String> policies, final String roleID) throws VaultConnectorException {
|
default boolean createAppRole(final String roleName, final List<String> policies, final String roleID)
|
||||||
|
throws VaultConnectorException {
|
||||||
return createAppRole(new AppRoleBuilder(roleName).withPolicies(policies).withId(roleID).build());
|
return createAppRole(new AppRoleBuilder(roleName).withPolicies(policies).withId(roleID).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +271,8 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
default AppRoleSecretResponse createAppRoleSecret(final String roleName, final String secretID) throws VaultConnectorException {
|
default AppRoleSecretResponse createAppRoleSecret(final String roleName, final String secretID)
|
||||||
|
throws VaultConnectorException {
|
||||||
return createAppRoleSecret(roleName, new AppRoleSecret(secretID));
|
return createAppRoleSecret(roleName, new AppRoleSecret(secretID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +285,8 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
AppRoleSecretResponse createAppRoleSecret(final String roleName, final AppRoleSecret secret) throws VaultConnectorException;
|
AppRoleSecretResponse createAppRoleSecret(final String roleName, final AppRoleSecret secret)
|
||||||
|
throws VaultConnectorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup an AppRole secret.
|
* Lookup an AppRole secret.
|
||||||
@ -293,7 +297,8 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
AppRoleSecretResponse lookupAppRoleSecret(final String roleName, final String secretID) throws VaultConnectorException;
|
AppRoleSecretResponse lookupAppRoleSecret(final String roleName, final String secretID)
|
||||||
|
throws VaultConnectorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy an AppRole secret.
|
* Destroy an AppRole secret.
|
||||||
@ -330,7 +335,8 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @param userID The User-ID
|
* @param userID The User-ID
|
||||||
* @return TRUE on success
|
* @return TRUE on success
|
||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
* @deprecated As of Vault 0.6.1 App-ID is superseded by AppRole. Consider using {@link #createAppRoleSecret} instead.
|
* @deprecated As of Vault 0.6.1 App-ID is superseded by AppRole.
|
||||||
|
* Consider using {@link #createAppRoleSecret} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
boolean registerUserId(final String appID, final String userID) throws VaultConnectorException;
|
boolean registerUserId(final String appID, final String userID) throws VaultConnectorException;
|
||||||
@ -347,7 +353,10 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @deprecated As of Vault 0.6.1 App-ID is superseded by AppRole.
|
* @deprecated As of Vault 0.6.1 App-ID is superseded by AppRole.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
default boolean registerAppUserId(final String appID, final String policy, final String displayName, final String userID) throws VaultConnectorException {
|
default boolean registerAppUserId(final String appID,
|
||||||
|
final String policy,
|
||||||
|
final String displayName,
|
||||||
|
final String userID) throws VaultConnectorException {
|
||||||
return registerAppId(appID, policy, userID) && registerUserId(appID, userID);
|
return registerAppId(appID, policy, userID) && registerUserId(appID, userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,7 +608,8 @@ public interface VaultConnector extends AutoCloseable {
|
|||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
* @since 0.5.0
|
* @since 0.5.0
|
||||||
*/
|
*/
|
||||||
default CredentialsResponse readDbCredentials(final String role, final String mount) throws VaultConnectorException {
|
default CredentialsResponse readDbCredentials(final String role, final String mount)
|
||||||
|
throws VaultConnectorException {
|
||||||
return (CredentialsResponse) read(mount + "/creds/" + role);
|
return (CredentialsResponse) read(mount + "/creds/" + role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.factory;
|
package de.stklcode.jvault.connector.factory;
|
||||||
|
|
||||||
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
import de.stklcode.jvault.connector.HTTPVaultConnector;
|
||||||
import de.stklcode.jvault.connector.VaultConnector;
|
|
||||||
import de.stklcode.jvault.connector.exception.ConnectionException;
|
import de.stklcode.jvault.connector.exception.ConnectionException;
|
||||||
import de.stklcode.jvault.connector.exception.TlsException;
|
import de.stklcode.jvault.connector.exception.TlsException;
|
||||||
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.*;
|
import com.fasterxml.jackson.annotation.*;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ package de.stklcode.jvault.connector.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.*;
|
import com.fasterxml.jackson.annotation.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -80,8 +80,14 @@ public final class Token {
|
|||||||
* @param meta Metadata (optional)
|
* @param meta Metadata (optional)
|
||||||
* @param renewable Is the token renewable (optional)
|
* @param renewable Is the token renewable (optional)
|
||||||
*/
|
*/
|
||||||
public Token(final String id, final String displayName, final Boolean noParent, final Boolean noDefaultPolicy,
|
public Token(final String id,
|
||||||
final Integer ttl, final Integer numUses, final List<String> policies, final Map<String, String> meta,
|
final String displayName,
|
||||||
|
final Boolean noParent,
|
||||||
|
final Boolean noDefaultPolicy,
|
||||||
|
final Integer ttl,
|
||||||
|
final Integer numUses,
|
||||||
|
final List<String> policies,
|
||||||
|
final Map<String, String> meta,
|
||||||
final Boolean renewable) {
|
final Boolean renewable) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,13 +24,12 @@ import de.stklcode.jvault.connector.model.AppRole;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vault response for AppRole lookup.
|
* Vault response for AppRole lookup.
|
||||||
*
|
*
|
||||||
* @author Stefan Kalscheuer
|
* @author Stefan Kalscheuer
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public final class AppRoleResponse extends VaultDataResponse {
|
public final class AppRoleResponse extends VaultDataResponse {
|
||||||
@ -42,7 +41,9 @@ public final class AppRoleResponse extends VaultDataResponse {
|
|||||||
try {
|
try {
|
||||||
/* null empty strings on list objects */
|
/* null empty strings on list objects */
|
||||||
Map<String, Object> filteredData = new HashMap<>();
|
Map<String, Object> filteredData = new HashMap<>();
|
||||||
data.forEach((k,v) -> { if (!(v instanceof String && ((String) v).isEmpty())) filteredData.put(k,v); });
|
data.forEach((k, v) -> {
|
||||||
|
if (!(v instanceof String && ((String) v).isEmpty())) filteredData.put(k, v);
|
||||||
|
});
|
||||||
this.role = mapper.readValue(mapper.writeValueAsString(filteredData), AppRole.class);
|
this.role = mapper.readValue(mapper.writeValueAsString(filteredData), AppRole.class);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -56,4 +57,4 @@ public final class AppRoleResponse extends VaultDataResponse {
|
|||||||
public AppRole getRole() {
|
public AppRole getRole() {
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package de.stklcode.jvault.connector.model.response;
|
|||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||||
import de.stklcode.jvault.connector.model.AppRole;
|
|
||||||
import de.stklcode.jvault.connector.model.AppRoleSecret;
|
import de.stklcode.jvault.connector.model.AppRoleSecret;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -29,8 +28,8 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Vault response for AppRole lookup.
|
* Vault response for AppRole lookup.
|
||||||
*
|
*
|
||||||
* @author Stefan Kalscheuer
|
* @author Stefan Kalscheuer
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public final class AppRoleSecretResponse extends VaultDataResponse {
|
public final class AppRoleSecretResponse extends VaultDataResponse {
|
||||||
@ -42,7 +41,9 @@ public final class AppRoleSecretResponse extends VaultDataResponse {
|
|||||||
try {
|
try {
|
||||||
/* null empty strings on list objects */
|
/* null empty strings on list objects */
|
||||||
Map<String, Object> filteredData = new HashMap<>();
|
Map<String, Object> filteredData = new HashMap<>();
|
||||||
data.forEach((k,v) -> { if (!(v instanceof String && ((String) v).isEmpty())) filteredData.put(k,v); });
|
data.forEach((k, v) -> {
|
||||||
|
if (!(v instanceof String && ((String) v).isEmpty())) filteredData.put(k, v);
|
||||||
|
});
|
||||||
this.secret = mapper.readValue(mapper.writeValueAsString(filteredData), AppRoleSecret.class);
|
this.secret = mapper.readValue(mapper.writeValueAsString(filteredData), AppRoleSecret.class);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -56,4 +57,4 @@ public final class AppRoleSecretResponse extends VaultDataResponse {
|
|||||||
public AppRoleSecret getSecret() {
|
public AppRoleSecret getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,9 @@ public final class AuthMethodsResponse extends VaultDataResponse {
|
|||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
for (String path : data.keySet()) {
|
for (String path : data.keySet()) {
|
||||||
try {
|
try {
|
||||||
this.supportedMethods.put(path, mapper.readValue(mapper.writeValueAsString(data.get(path)), AuthMethod.class));
|
this.supportedMethods.put(
|
||||||
|
path, mapper.readValue(mapper.writeValueAsString(data.get(path)),
|
||||||
|
AuthMethod.class));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new InvalidResponseException();
|
throw new InvalidResponseException();
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
|
||||||
import de.stklcode.jvault.connector.model.response.embedded.TokenData;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vault response from credentials lookup. Simple wrapper for data objects containing username and password fields.
|
* Vault response from credentials lookup. Simple wrapper for data objects containing username and password fields.
|
||||||
|
@ -35,7 +35,7 @@ public final class ErrorResponse implements VaultResponse {
|
|||||||
/**
|
/**
|
||||||
* @return List of errors
|
* @return List of errors
|
||||||
*/
|
*/
|
||||||
public List<String > getErrors() {
|
public List<String> getErrors() {
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,4 +36,4 @@ public final class HelpResponse implements VaultResponse {
|
|||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return help;
|
return help;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,4 +89,4 @@ public final class AuthData {
|
|||||||
public boolean isRenewable() {
|
public boolean isRenewable() {
|
||||||
return renewable;
|
return renewable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user