JavaDoc fixes

Added various JavaDoc blocks for public methods in model classes and some minor style corrections.
This commit is contained in:
Stefan Kalscheuer 2017-08-02 17:05:24 +02:00
parent d7365dcaf1
commit 259747afae
30 changed files with 473 additions and 50 deletions

View File

@ -125,11 +125,13 @@ public class HTTPVaultConnector implements VaultConnector {
/** /**
* Create connector using hostname, schema, port, path and trusted certificate. * Create connector using hostname, schema, port, path and trusted certificate.
* *
* @param hostname The hostname * @param hostname The hostname
* @param useTLS If TRUE, use HTTPS, otherwise HTTP * @param useTLS If TRUE, use HTTPS, otherwise HTTP
* @param port The port * @param port The port
* @param prefix HTTP API prefix (default: /v1/) * @param prefix HTTP API prefix (default: /v1/)
* @param sslContext Custom SSL Context * @param sslContext Custom SSL Context
* @param numberOfRetries Number of retries on 5xx errors
* @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, final boolean useTLS, final Integer port, final String prefix, final SSLContext sslContext, final int numberOfRetries, final Integer timeout) {
this(((useTLS) ? "https" : "http") + this(((useTLS) ? "https" : "http") +
@ -165,7 +167,7 @@ public class HTTPVaultConnector implements VaultConnector {
* *
* @param baseURL The URL * @param baseURL The URL
* @param sslContext Custom SSL Context * @param sslContext Custom SSL Context
* @param numberOfRetries number of retries on 5xx errors * @param numberOfRetries Number of retries on 5xx errors
*/ */
public HTTPVaultConnector(final String baseURL, final SSLContext sslContext, final int numberOfRetries) { public HTTPVaultConnector(final String baseURL, final SSLContext sslContext, final int numberOfRetries) {
this(baseURL, sslContext, numberOfRetries, null); this(baseURL, sslContext, numberOfRetries, null);
@ -176,7 +178,8 @@ public class HTTPVaultConnector implements VaultConnector {
* *
* @param baseURL The URL * @param baseURL The URL
* @param sslContext Custom SSL Context * @param sslContext Custom SSL Context
* @param numberOfRetries number of retries on 5xx errors * @param numberOfRetries Number of retries on 5xx errors
* @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;
@ -294,7 +297,7 @@ public class HTTPVaultConnector implements VaultConnector {
} }
/** /**
* Query authorization request to given backend * Query authorization request to given backend.
* *
* @param path The path to request * @param path The path to request
* @param payload Payload (credentials) * @param payload Payload (credentials)
@ -537,6 +540,7 @@ public class HTTPVaultConnector implements VaultConnector {
} }
} }
@Override
public final void write(final String key, final Map<String, Object> data) throws VaultConnectorException { public final void write(final String key, final Map<String, Object> data) throws VaultConnectorException {
if (!isAuthorized()) if (!isAuthorized())
throw new AuthorizationRequiredException(); throw new AuthorizationRequiredException();
@ -738,6 +742,7 @@ public class HTTPVaultConnector implements VaultConnector {
* @param payload Map of payload values (will be converted to JSON) * @param payload Map of payload values (will be converted to JSON)
* @return HTTP response * @return HTTP response
* @throws VaultConnectorException on connection error * @throws VaultConnectorException on connection error
* @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 */

View File

@ -324,7 +324,7 @@ public interface VaultConnector extends AutoCloseable {
List<String> listAppRoleSecretss(final String roleName) throws VaultConnectorException; List<String> listAppRoleSecretss(final String roleName) throws VaultConnectorException;
/** /**
* Register User-ID with App-ID * Register User-ID with App-ID.
* *
* @param appID The App-ID * @param appID The App-ID
* @param userID The User-ID * @param userID The User-ID
@ -352,7 +352,7 @@ public interface VaultConnector extends AutoCloseable {
} }
/** /**
* Get authorization status * Get authorization status.
* *
* @return TRUE, if successfully authorized * @return TRUE, if successfully authorized
*/ */
@ -543,7 +543,7 @@ public interface VaultConnector extends AutoCloseable {
TokenResponse lookupToken(final String token) throws VaultConnectorException; TokenResponse lookupToken(final String token) throws VaultConnectorException;
/** /**
* Read credentials for MySQL backend at default mount point * Read credentials for MySQL backend at default mount point.
* *
* @param role the role name * @param role the role name
* @return the credentials response * @return the credentials response
@ -555,7 +555,7 @@ public interface VaultConnector extends AutoCloseable {
} }
/** /**
* Read credentials for PostgreSQL backend at default mount point * Read credentials for PostgreSQL backend at default mount point.
* *
* @param role the role name * @param role the role name
* @return the credentials response * @return the credentials response
@ -567,7 +567,7 @@ public interface VaultConnector extends AutoCloseable {
} }
/** /**
* Read credentials for MSSQL backend at default mount point * Read credentials for MSSQL backend at default mount point.
* *
* @param role the role name * @param role the role name
* @return the credentials response * @return the credentials response
@ -579,7 +579,7 @@ public interface VaultConnector extends AutoCloseable {
} }
/** /**
* Read credentials for MSSQL backend at default mount point * Read credentials for MSSQL backend at default mount point.
* *
* @param role the role name * @param role the role name
* @return the credentials response * @return the credentials response

View File

@ -19,21 +19,40 @@ package de.stklcode.jvault.connector.exception;
/** /**
* Exception thrown on problems with connection to Vault backend. * Exception thrown on problems with connection to Vault backend.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
public class ConnectionException extends VaultConnectorException { public class ConnectionException extends VaultConnectorException {
/**
* Constructs a new empty exception.
*/
public ConnectionException() { public ConnectionException() {
} }
/**
* Constructs a new exception with the specified detail message.
*
* @param message the detail message
*/
public ConnectionException(final String message) { public ConnectionException(final String message) {
super(message); super(message);
} }
/**
* Constructs a new exception with the specified cause.
*
* @param cause the cause
*/
public ConnectionException(final Throwable cause) { public ConnectionException(final Throwable cause) {
super(cause); super(cause);
} }
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause
*/
public ConnectionException(final String message, final Throwable cause) { public ConnectionException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@ -23,17 +23,36 @@ package de.stklcode.jvault.connector.exception;
* @since 0.1 * @since 0.1
*/ */
public class InvalidRequestException extends VaultConnectorException { public class InvalidRequestException extends VaultConnectorException {
/**
* Constructs a new empty exception.
*/
public InvalidRequestException() { public InvalidRequestException() {
} }
/**
* Constructs a new exception with the specified detail message.
*
* @param message the detail message
*/
public InvalidRequestException(final String message) { public InvalidRequestException(final String message) {
super(message); super(message);
} }
/**
* Constructs a new exception with the specified cause.
*
* @param cause the cause
*/
public InvalidRequestException(final Throwable cause) { public InvalidRequestException(final Throwable cause) {
super(cause); super(cause);
} }
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause
*/
public InvalidRequestException(final String message, final Throwable cause) { public InvalidRequestException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@ -20,42 +20,83 @@ package de.stklcode.jvault.connector.exception;
* Exception thrown when response from vault returned with erroneous status code or payload could not be parsed * Exception thrown when response from vault returned with erroneous status code or payload could not be parsed
* to entity class. * to entity class.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
public final class InvalidResponseException extends VaultConnectorException { public final class InvalidResponseException extends VaultConnectorException {
private Integer statusCode; private Integer statusCode;
private String response; private String response;
/**
* Constructs a new empty exception.
*/
public InvalidResponseException() { public InvalidResponseException() {
} }
/**
* Constructs a new exception with the specified detail message.
*
* @param message the detail message
*/
public InvalidResponseException(final String message) { public InvalidResponseException(final String message) {
super(message); super(message);
} }
/**
* Constructs a new exception with the specified cause.
*
* @param cause the cause
*/
public InvalidResponseException(final Throwable cause) { public InvalidResponseException(final Throwable cause) {
super(cause); super(cause);
} }
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause
*/
public InvalidResponseException(final String message, final Throwable cause) { public InvalidResponseException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }
/**
* Specify the HTTP status code. Can be retrieved by {@link #getStatusCode()} later.
*
* @param statusCode the status code
* @return self
*/
public InvalidResponseException withStatusCode(final Integer statusCode) { public InvalidResponseException withStatusCode(final Integer statusCode) {
this.statusCode = statusCode; this.statusCode = statusCode;
return this; return this;
} }
/**
* Specify the response string. Can be retrieved by {@link #getResponse()} later.
*
* @param response response text
* @return self
*/
public InvalidResponseException withResponse(final String response) { public InvalidResponseException withResponse(final String response) {
this.response = response; this.response = response;
return this; return this;
} }
/**
* Retrieve the HTTP status code.
*
* @return the status code or {@code null} if none specified.
*/
public Integer getStatusCode() { public Integer getStatusCode() {
return statusCode; return statusCode;
} }
/**
* Retrieve the response text.
*
* @return the response text or {@code null} if none specified.
*/
public String getResponse() { public String getResponse() {
return response; return response;
} }

View File

@ -23,18 +23,37 @@ package de.stklcode.jvault.connector.exception;
* @since 0.1 * @since 0.1
*/ */
public class PermissionDeniedException extends VaultConnectorException { public class PermissionDeniedException extends VaultConnectorException {
/**
* Constructs a new empty exception.
*/
public PermissionDeniedException() { public PermissionDeniedException() {
super("Permission denied"); super("Permission denied");
} }
/**
* Constructs a new exception with the specified detail message.
*
* @param message the detail message
*/
public PermissionDeniedException(final String message) { public PermissionDeniedException(final String message) {
super(message); super(message);
} }
/**
* Constructs a new exception with the specified cause.
*
* @param cause the cause
*/
public PermissionDeniedException(final Throwable cause) { public PermissionDeniedException(final Throwable cause) {
super(cause); super(cause);
} }
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause
*/
public PermissionDeniedException(final String message, final Throwable cause) { public PermissionDeniedException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@ -23,17 +23,36 @@ package de.stklcode.jvault.connector.exception;
* @since 0.4.0 * @since 0.4.0
*/ */
public class TlsException extends VaultConnectorException { public class TlsException extends VaultConnectorException {
/**
* Constructs a new empty exception.
*/
public TlsException() { public TlsException() {
} }
/**
* Constructs a new exception with the specified detail message.
*
* @param message the detail message
*/
public TlsException(final String message) { public TlsException(final String message) {
super(message); super(message);
} }
/**
* Constructs a new exception with the specified cause.
*
* @param cause the cause
*/
public TlsException(final Throwable cause) { public TlsException(final Throwable cause) {
super(cause); super(cause);
} }
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause
*/
public TlsException(final String message, final Throwable cause) { public TlsException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@ -23,17 +23,36 @@ package de.stklcode.jvault.connector.exception;
* @since 0.1 * @since 0.1
*/ */
public abstract class VaultConnectorException extends Exception { public abstract class VaultConnectorException extends Exception {
/**
* Constructs a new empty exception.
*/
public VaultConnectorException() { public VaultConnectorException() {
} }
/**
* Constructs a new exception with the specified detail message.
*
* @param message the detail message
*/
public VaultConnectorException(final String message) { public VaultConnectorException(final String message) {
super(message); super(message);
} }
/**
* Constructs a new exception with the specified cause.
*
* @param cause the cause
*/
public VaultConnectorException(final Throwable cause) { public VaultConnectorException(final Throwable cause) {
super(cause); super(cause);
} }
/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause
*/
public VaultConnectorException(final String message, final Throwable cause) { public VaultConnectorException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@ -77,7 +77,7 @@ public final class HTTPVaultConnectorFactory extends VaultConnectorFactory {
} }
/** /**
* Set hostname (default: 127.0.0.1) * Set hostname (default: 127.0.0.1).
* *
* @param host Hostname or IP address * @param host Hostname or IP address
* @return self * @return self
@ -88,7 +88,7 @@ public final class HTTPVaultConnectorFactory extends VaultConnectorFactory {
} }
/** /**
* Set port (default: 8200) * Set port (default: 8200).
* *
* @param port Vault TCP port * @param port Vault TCP port
* @return self * @return self
@ -99,7 +99,7 @@ public final class HTTPVaultConnectorFactory extends VaultConnectorFactory {
} }
/** /**
* Set TLS usage (default: TRUE) * Set TLS usage (default: TRUE).
* *
* @param useTLS use TLS or not * @param useTLS use TLS or not
* @return self * @return self
@ -110,7 +110,7 @@ public final class HTTPVaultConnectorFactory extends VaultConnectorFactory {
} }
/** /**
* Convenience Method for TLS usage (enabled by default) * Convenience Method for TLS usage (enabled by default).
* *
* @return self * @return self
*/ */
@ -119,7 +119,7 @@ public final class HTTPVaultConnectorFactory extends VaultConnectorFactory {
} }
/** /**
* Convenience Method for NOT using TLS * Convenience Method for NOT using TLS.
* *
* @return self * @return self
*/ */
@ -172,7 +172,7 @@ public final class HTTPVaultConnectorFactory extends VaultConnectorFactory {
* @return self * @return self
* @since 0.6.0 * @since 0.6.0
*/ */
public HTTPVaultConnectorFactory withToken(final String token) throws VaultConnectorException { public HTTPVaultConnectorFactory withToken(final String token) {
this.token = token; this.token = token;
return this; return this;
} }
@ -181,6 +181,7 @@ public final class HTTPVaultConnectorFactory extends VaultConnectorFactory {
* Build connector based on the {@code }VAULT_ADDR} and {@code VAULT_CACERT} (optional) environment variables. * Build connector based on the {@code }VAULT_ADDR} and {@code VAULT_CACERT} (optional) environment variables.
* *
* @return self * @return self
* @throws VaultConnectorException if Vault address from environment variables is malformed
* @since 0.6.0 * @since 0.6.0
*/ */
public HTTPVaultConnectorFactory fromEnv() throws VaultConnectorException { public HTTPVaultConnectorFactory fromEnv() throws VaultConnectorException {

View File

@ -28,7 +28,7 @@ import de.stklcode.jvault.connector.exception.VaultConnectorException;
*/ */
public abstract class VaultConnectorFactory { public abstract class VaultConnectorFactory {
/** /**
* Get Factory implementation for HTTP Vault Connector * Get Factory implementation for HTTP Vault Connector.
* *
* @return HTTP Connector Factory * @return HTTP Connector Factory
*/ */
@ -47,6 +47,7 @@ public abstract class VaultConnectorFactory {
* Build connector and authenticate with token set in factory or from environment. * Build connector and authenticate with token set in factory or from environment.
* *
* @return Authenticated Vault connector instance. * @return Authenticated Vault connector instance.
* @throws VaultConnectorException if authentication failed
* @since 0.6.0 * @since 0.6.0
*/ */
public abstract VaultConnector buildAndAuth() throws VaultConnectorException; public abstract VaultConnector buildAndAuth() throws VaultConnectorException;

View File

@ -64,10 +64,27 @@ public final class AppRole {
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
private Integer period; private Integer period;
/**
* Construct empty {@link AppRole} object.
*/
public AppRole() { public AppRole() {
} }
/**
* Construct complete {@link AppRole} object.
*
* @param name Role name (required)
* @param id Role ID (optional)
* @param bindSecretId Bind secret ID (optional)
* @param boundCidrList Whitelist of subnets in CIDR notation (optional)
* @param policies List of policies (optional)
* @param secretIdNumUses Maximum number of uses per secret (optional)
* @param secretIdTtl Maximum TTL in seconds for secrets (optional)
* @param tokenTtl Token TTL in seconds (optional)
* @param tokenMaxTtl Maximum token TTL in seconds, including renewals (optional)
* @param period Duration in seconds, if set the token is a periodic token (optional)
*/
public AppRole(final String name, final String id, final Boolean bindSecretId, final List<String> boundCidrList, public AppRole(final String name, final String id, final Boolean bindSecretId, final List<String> boundCidrList,
final List<String> policies, final Integer secretIdNumUses, final Integer secretIdTtl, final List<String> policies, final Integer secretIdNumUses, final Integer secretIdTtl,
final Integer tokenTtl, final Integer tokenMaxTtl, final Integer period) { final Integer tokenTtl, final Integer tokenMaxTtl, final Integer period) {
@ -83,27 +100,45 @@ public final class AppRole {
this.period = period; this.period = period;
} }
/**
* @return the role name
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
* @return the role ID
*/
public String getId() { public String getId() {
return id; return id;
} }
/**
* @return bind secret ID
*/
public Boolean getBindSecretId() { public Boolean getBindSecretId() {
return bindSecretId; return bindSecretId;
} }
/**
* @return list of bound CIDR subnets
*/
public List<String> getBoundCidrList() { public List<String> getBoundCidrList() {
return boundCidrList; return boundCidrList;
} }
/**
* @param boundCidrList list of subnets in CIDR notation to bind role to
*/
@JsonSetter("bound_cidr_list") @JsonSetter("bound_cidr_list")
public void setBoundCidrList(final List<String> boundCidrList) { public void setBoundCidrList(final List<String> boundCidrList) {
this.boundCidrList = boundCidrList; this.boundCidrList = boundCidrList;
} }
/**
* @return list of subnets in CIDR notation as comma-separated {@link String}
*/
@JsonGetter("bound_cidr_list") @JsonGetter("bound_cidr_list")
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
public String getBoundCidrListString() { public String getBoundCidrListString() {
@ -112,15 +147,24 @@ public final class AppRole {
return String.join(",", boundCidrList); return String.join(",", boundCidrList);
} }
/**
* @return list of policies
*/
public List<String> getPolicies() { public List<String> getPolicies() {
return policies; return policies;
} }
/**
* @param policies list of policies
*/
@JsonSetter("policies") @JsonSetter("policies")
public void setPolicies(final List<String> policies) { public void setPolicies(final List<String> policies) {
this.policies = policies; this.policies = policies;
} }
/**
* @return list of policies as comma-separated {@link String}
*/
@JsonGetter("policies") @JsonGetter("policies")
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
public String getPoliciesString() { public String getPoliciesString() {
@ -129,22 +173,37 @@ public final class AppRole {
return String.join(",", policies); return String.join(",", policies);
} }
/**
* @return maximum number of uses per secret
*/
public Integer getSecretIdNumUses() { public Integer getSecretIdNumUses() {
return secretIdNumUses; return secretIdNumUses;
} }
/**
* @return maximum TTL in seconds for secrets
*/
public Integer getSecretIdTtl() { public Integer getSecretIdTtl() {
return secretIdTtl; return secretIdTtl;
} }
/**
* @return token TTL in seconds
*/
public Integer getTokenTtl() { public Integer getTokenTtl() {
return tokenTtl; return tokenTtl;
} }
/**
* @return maximum token TTL in seconds, including renewals
*/
public Integer getTokenMaxTtl() { public Integer getTokenMaxTtl() {
return tokenMaxTtl; return tokenMaxTtl;
} }
/**
* @return duration in seconds, if specified
*/
public Integer getPeriod() { public Integer getPeriod() {
return period; return period;
} }

View File

@ -37,12 +37,17 @@ public final class AppRoleBuilder {
private Integer tokenMaxTtl; private Integer tokenMaxTtl;
private Integer period; private Integer period;
/**
* Construct {@link AppRoleBuilder} with only the role name set.
*
* @param name Role name
*/
public AppRoleBuilder(final String name) { public AppRoleBuilder(final String name) {
this.name = name; this.name = name;
} }
/** /**
* Add custom role ID (optional) * Add custom role ID. (optional)
* *
* @param id the ID * @param id the ID
* @return self * @return self
@ -53,7 +58,7 @@ public final class AppRoleBuilder {
} }
/** /**
* Set if role is bound to secret ID * Set if role is bound to secret ID.
* *
* @param bindSecretId the display name * @param bindSecretId the display name
* @return self * @return self
@ -108,7 +113,7 @@ public final class AppRoleBuilder {
} }
/** /**
* Add given policies * Add given policies.
* *
* @param policies the policies * @param policies the policies
* @return self * @return self

View File

@ -58,41 +58,73 @@ public final class AppRoleSecret {
@JsonProperty(value = "secret_id_ttl", access = JsonProperty.Access.WRITE_ONLY) @JsonProperty(value = "secret_id_ttl", access = JsonProperty.Access.WRITE_ONLY)
private Integer ttl; private Integer ttl;
/**
* Construct empty {@link AppRoleSecret} object.
*/
public AppRoleSecret() { public AppRoleSecret() {
} }
/**
* Construct {@link AppRoleSecret} with secret ID.
*
* @param id Secret ID
*/
public AppRoleSecret(final String id) { public AppRoleSecret(final String id) {
this.id = id; this.id = id;
} }
/**
* Construct {@link AppRoleSecret} with ID and metadata.
*
* @param id Secret ID
* @param metadata Secret metadata
* @param cidrList List of subnets in CIDR notation, the role is bound to
*/
public AppRoleSecret(final String id, final Map<String, Object> metadata, final List<String> cidrList) { public AppRoleSecret(final String id, final Map<String, Object> metadata, final List<String> cidrList) {
this.id = id; this.id = id;
this.metadata = metadata; this.metadata = metadata;
this.cidrList = cidrList; this.cidrList = cidrList;
} }
/**
* @return Secret ID
*/
public String getId() { public String getId() {
return id; return id;
} }
/**
* @return Secret accessor
*/
public String getAccessor() { public String getAccessor() {
return accessor; return accessor;
} }
/**
* @return Secret metadata
*/
public Map<String, Object> getMetadata() { public Map<String, Object> getMetadata() {
return metadata; return metadata;
} }
/**
* @return List of bound subnets in CIDR notation
*/
public List<String> getCidrList() { public List<String> getCidrList() {
return cidrList; return cidrList;
} }
/**
* @param cidrList List of subnets in CIDR notation
*/
@JsonSetter("cidr_list") @JsonSetter("cidr_list")
public void setCidrList(final List<String> cidrList) { public void setCidrList(final List<String> cidrList) {
this.cidrList = cidrList; this.cidrList = cidrList;
} }
/**
* @return List of bound subnets in CIDR notation as comma-separated {@link String}
*/
@JsonGetter("cidr_list") @JsonGetter("cidr_list")
public String getCidrListString() { public String getCidrListString() {
if (cidrList == null || cidrList.isEmpty()) if (cidrList == null || cidrList.isEmpty())
@ -100,22 +132,37 @@ public final class AppRoleSecret {
return String.join(",", cidrList); return String.join(",", cidrList);
} }
/**
* @return Creation time
*/
public String getCreationTime() { public String getCreationTime() {
return creationTime; return creationTime;
} }
/**
* @return Expiration time
*/
public String getExpirationTime() { public String getExpirationTime() {
return expirationTime; return expirationTime;
} }
/**
* @return Time of last update
*/
public String getLastUpdatedTime() { public String getLastUpdatedTime() {
return lastUpdatedTime; return lastUpdatedTime;
} }
/**
* @return Number of uses
*/
public Integer getNumUses() { public Integer getNumUses() {
return numUses; return numUses;
} }
/**
* @return Time-to-live
*/
public Integer getTtl() { public Integer getTtl() {
return ttl; return ttl;
} }

View File

@ -19,8 +19,8 @@ package de.stklcode.jvault.connector.model;
/** /**
* Currently supported authentication backends. * Currently supported authentication backends.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
public enum AuthBackend { public enum AuthBackend {
TOKEN("token"), TOKEN("token"),
@ -31,10 +31,21 @@ public enum AuthBackend {
private final String type; private final String type;
/**
* Construct {@link AuthBackend} of given type.
*
* @param type Backend type
*/
AuthBackend(final String type) { AuthBackend(final String type) {
this.type = type; this.type = type;
} }
/**
* Retrieve {@link AuthBackend} value for given type string.
*
* @param type Type string
* @return Auth backend value
*/
public static AuthBackend forType(final String type) { public static AuthBackend forType(final String type) {
for (AuthBackend v : values()) for (AuthBackend v : values())
if (v.type.equalsIgnoreCase(type)) if (v.type.equalsIgnoreCase(type))

View File

@ -67,6 +67,19 @@ public final class Token {
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean renewable; private Boolean renewable;
/**
* Construct complete {@link Token} object.
*
* @param id Token ID (optional)
* @param displayName Token display name (optional)
* @param noParent Token has no parent (optional)
* @param noDefaultPolicy Do not add default policy (optional)
* @param ttl Token TTL in seconds (optional)
* @param numUses Number of uses (optional)
* @param policies List of policies (optional)
* @param meta Metadata (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 String displayName, final Boolean noParent, final Boolean noDefaultPolicy,
final Integer ttl, final Integer numUses, final List<String> policies, final Map<String, String> meta, final Integer ttl, final Integer numUses, final List<String> policies, final Map<String, String> meta,
final Boolean renewable) { final Boolean renewable) {
@ -81,38 +94,65 @@ public final class Token {
this.renewable = renewable; this.renewable = renewable;
} }
/**
* @return Token ID
*/
public String getId() { public String getId() {
return id; return id;
} }
/**
* @return Token display name
*/
public String getDisplayName() { public String getDisplayName() {
return displayName; return displayName;
} }
/**
* @return Token has no parent
*/
public Boolean getNoParent() { public Boolean getNoParent() {
return noParent; return noParent;
} }
/**
* @return Token has no default policy
*/
public Boolean getNoDefaultPolicy() { public Boolean getNoDefaultPolicy() {
return noDefaultPolicy; return noDefaultPolicy;
} }
/**
* @return Time-to-live in seconds
*/
public Integer getTtl() { public Integer getTtl() {
return ttl; return ttl;
} }
/**
* @return Number of uses
*/
public Integer getNumUses() { public Integer getNumUses() {
return numUses; return numUses;
} }
/**
* @return List of policies
*/
public List<String> getPolicies() { public List<String> getPolicies() {
return policies; return policies;
} }
/**
* @return Metadata
*/
public Map<String, String> getMeta() { public Map<String, String> getMeta() {
return meta; return meta;
} }
/**
* @return Token is renewable
*/
public Boolean isRenewable() { public Boolean isRenewable() {
return renewable; return renewable;
} }

View File

@ -23,7 +23,7 @@ import java.util.*;
/** /**
* A builder for vault tokens. * A builder for vault tokens.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.4.0 * @since 0.4.0
*/ */
public final class TokenBuilder { public final class TokenBuilder {
@ -38,7 +38,7 @@ public final class TokenBuilder {
private Boolean renewable; private Boolean renewable;
/** /**
* Add token ID (optional) * Add token ID. (optional)
* *
* @param id the ID * @param id the ID
* @return self * @return self
@ -49,7 +49,7 @@ public final class TokenBuilder {
} }
/** /**
* Add display name * Add display name.
* *
* @param displayName the display name * @param displayName the display name
* @return self * @return self
@ -61,6 +61,7 @@ public final class TokenBuilder {
/** /**
* Set desired time to live. * Set desired time to live.
*
* @param ttl the ttl * @param ttl the ttl
* @return self * @return self
*/ */
@ -71,6 +72,7 @@ public final class TokenBuilder {
/** /**
* Set desired number of uses. * Set desired number of uses.
*
* @param numUses the number of uses * @param numUses the number of uses
* @return self * @return self
*/ */
@ -80,7 +82,7 @@ public final class TokenBuilder {
} }
/** /**
* Set TRUE if the token should be created without parent * Set TRUE if the token should be created without parent.
* *
* @param noParent if TRUE, token is created as orphan * @param noParent if TRUE, token is created as orphan
* @return self * @return self
@ -142,7 +144,7 @@ public final class TokenBuilder {
} }
/** /**
* Add given policies * Add given policies.
* *
* @param policies the policies * @param policies the policies
* @return self * @return self
@ -153,7 +155,7 @@ public final class TokenBuilder {
} }
/** /**
* Add given policies * Add given policies.
* *
* @param policies the policies * @param policies the policies
* @return self * @return self

View File

@ -50,6 +50,9 @@ public final class AppRoleResponse extends VaultDataResponse {
} }
} }
/**
* @return The role
*/
public AppRole getRole() { public AppRole getRole() {
return role; return role;
} }

View File

@ -50,6 +50,9 @@ public final class AppRoleSecretResponse extends VaultDataResponse {
} }
} }
/**
* @return The secret
*/
public AppRoleSecret getSecret() { public AppRoleSecret getSecret() {
return secret; return secret;
} }

View File

@ -35,6 +35,9 @@ import java.util.Map;
public final class AuthMethodsResponse extends VaultDataResponse { public final class AuthMethodsResponse extends VaultDataResponse {
private Map<String, AuthMethod> supportedMethods; private Map<String, AuthMethod> supportedMethods;
/**
* Construct empty {@link AuthMethodsResponse} object.
*/
public AuthMethodsResponse() { public AuthMethodsResponse() {
this.supportedMethods = new HashMap<>(); this.supportedMethods = new HashMap<>();
} }
@ -51,6 +54,9 @@ public final class AuthMethodsResponse extends VaultDataResponse {
} }
} }
/**
* @return Supported authentication methods
*/
public Map<String, AuthMethod> getSupportedMethods() { public Map<String, AuthMethod> getSupportedMethods() {
return supportedMethods; return supportedMethods;
} }

View File

@ -28,8 +28,8 @@ import java.util.Map;
/** /**
* Vault response for authentication providing auth info in {@link AuthData} field. * Vault response for authentication providing auth info in {@link AuthData} field.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public final class AuthResponse extends VaultDataResponse { public final class AuthResponse extends VaultDataResponse {
@ -37,6 +37,12 @@ public final class AuthResponse extends VaultDataResponse {
private AuthData auth; private AuthData auth;
/**
* Set authentication data. The input will be mapped to the {@link AuthData} model.
*
* @param auth Raw authentication data
* @throws InvalidResponseException on mapping errors
*/
@JsonProperty("auth") @JsonProperty("auth")
public void setAuth(final Map<String, Object> auth) throws InvalidResponseException { public void setAuth(final Map<String, Object> auth) throws InvalidResponseException {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@ -53,10 +59,16 @@ public final class AuthResponse extends VaultDataResponse {
this.data = data; this.data = data;
} }
/**
* @return Raw data
*/
public Map<String, Object> getData() { public Map<String, Object> getData() {
return data; return data;
} }
/**
* @return Authentication data
*/
public AuthData getAuth() { public AuthData getAuth() {
return auth; return auth;
} }

View File

@ -32,6 +32,9 @@ public final class ErrorResponse implements VaultResponse {
@JsonProperty("errors") @JsonProperty("errors")
private List<String> errors; private List<String> errors;
/**
* @return List of errors
*/
public List<String > getErrors() { public List<String > getErrors() {
return errors; return errors;
} }

View File

@ -30,6 +30,9 @@ public final class HelpResponse implements VaultResponse {
@JsonProperty("help") @JsonProperty("help")
private String help; private String help;
/**
* @return Help text
*/
public String getHelp() { public String getHelp() {
return help; return help;
} }

View File

@ -35,6 +35,9 @@ public final class RawDataResponse extends VaultDataResponse {
this.data = data; this.data = data;
} }
/**
* @return Raw data {@link Map}
*/
public Map<String, Object> getData() { public Map<String, Object> getData() {
return data; return data;
} }

View File

@ -39,18 +39,30 @@ public final class SealResponse implements VaultResponse {
@JsonProperty("progress") @JsonProperty("progress")
private Integer progress; private Integer progress;
/**
* @return Seal status
*/
public boolean isSealed() { public boolean isSealed() {
return sealed; return sealed;
} }
/**
* @return Required threshold of secret shares
*/
public Integer getThreshold() { public Integer getThreshold() {
return threshold; return threshold;
} }
/**
* @return Number of secret shares
*/
public Integer getNumberOfShares() { public Integer getNumberOfShares() {
return numberOfShares; return numberOfShares;
} }
/**
* @return Current unseal progress (remaining required shares)
*/
public Integer getProgress() { public Integer getProgress() {
return progress; return progress;
} }

View File

@ -26,23 +26,31 @@ import java.util.Map;
/** /**
* Vault response for secret list request. * Vault response for secret list request.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public final class SecretListResponse extends VaultDataResponse { public final class SecretListResponse extends VaultDataResponse {
private List<String> keys; private List<String> keys;
/**
* Set data. Extracts list of keys from raw response data.
*
* @param data Raw data
* @throws InvalidResponseException on parsing errors
*/
@JsonProperty("data") @JsonProperty("data")
public void setData(final Map<String, Object> data) throws InvalidResponseException { public void setData(final Map<String, Object> data) throws InvalidResponseException {
try { try {
this.keys = (List<String>)data.get("keys"); this.keys = (List<String>) data.get("keys");
} } catch (ClassCastException e) {
catch (ClassCastException e) {
throw new InvalidResponseException("Keys could not be parsed from data.", e); throw new InvalidResponseException("Keys could not be parsed from data.", e);
} }
} }
/**
* @return List of secret keys
*/
public List<String> getKeys() { public List<String> getKeys() {
return keys; return keys;
} }

View File

@ -79,7 +79,7 @@ public class SecretResponse extends VaultDataResponse {
} }
/** /**
* Get response parsed as JSON * Get response parsed as JSON.
* *
* @param type Class to parse response * @param type Class to parse response
* @param <T> Class to parse response * @param <T> Class to parse response
@ -94,7 +94,7 @@ public class SecretResponse extends VaultDataResponse {
} }
/** /**
* Get response parsed as JSON * Get response parsed as JSON.
* *
* @param key the key * @param key the key
* @param type Class to parse response * @param type Class to parse response

View File

@ -28,8 +28,8 @@ import java.util.Map;
/** /**
* Vault response from token lookup providing Token information in {@link TokenData} field. * Vault response from token lookup providing Token information in {@link TokenData} field.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public final class TokenResponse extends VaultDataResponse { public final class TokenResponse extends VaultDataResponse {
@ -38,6 +38,12 @@ public final class TokenResponse extends VaultDataResponse {
@JsonProperty("auth") @JsonProperty("auth")
private Boolean auth; private Boolean auth;
/**
* Set data. Parses response data map to {@link TokenData}.
*
* @param data Raw response data
* @throws InvalidResponseException on parsing errors
*/
@Override @Override
public void setData(final Map<String, Object> data) throws InvalidResponseException { public void setData(final Map<String, Object> data) throws InvalidResponseException {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@ -49,6 +55,9 @@ public final class TokenResponse extends VaultDataResponse {
} }
} }
/**
* @return Token data
*/
public TokenData getData() { public TokenData getData() {
return data; return data;
} }

View File

@ -25,8 +25,8 @@ import java.util.Map;
/** /**
* Abstract Vault response with default payload fields. * Abstract Vault response with default payload fields.
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
public abstract class VaultDataResponse implements VaultResponse { public abstract class VaultDataResponse implements VaultResponse {
@JsonProperty("lease_id") @JsonProperty("lease_id")
@ -41,21 +41,39 @@ public abstract class VaultDataResponse implements VaultResponse {
@JsonProperty("warnings") @JsonProperty("warnings")
private List<String> warnings; private List<String> warnings;
/**
* Set data. To be implemented in the specific subclasses, as data can be of arbitrary structure.
*
* @param data Raw response data
* @throws InvalidResponseException on parsing errors
*/
@JsonProperty("data") @JsonProperty("data")
public abstract void setData(final Map<String, Object> data) throws InvalidResponseException; public abstract void setData(final Map<String, Object> data) throws InvalidResponseException;
/**
* @return Lease ID
*/
public final String getLeaseId() { public final String getLeaseId() {
return leaseId; return leaseId;
} }
/**
* @return Lease is renewable
*/
public final boolean isRenewable() { public final boolean isRenewable() {
return renewable; return renewable;
} }
/**
* @return Lease duration
*/
public final Integer getLeaseDuration() { public final Integer getLeaseDuration() {
return leaseDuration; return leaseDuration;
} }
/**
* @return List of warnings
*/
public final List<String> getWarnings() { public final List<String> getWarnings() {
return warnings; return warnings;
} }

View File

@ -48,26 +48,44 @@ public final class AuthData {
@JsonProperty("renewable") @JsonProperty("renewable")
private boolean renewable; private boolean renewable;
/**
* @return Client token
*/
public String getClientToken() { public String getClientToken() {
return clientToken; return clientToken;
} }
/**
* @return Token accessor
*/
public String getAccessor() { public String getAccessor() {
return accessor; return accessor;
} }
/**
* @return List of policies
*/
public List<String> getPolicies() { public List<String> getPolicies() {
return policies; return policies;
} }
/**
* @return Metadata
*/
public Map<String, Object> getMetadata() { public Map<String, Object> getMetadata() {
return metadata; return metadata;
} }
/**
* @return Lease duration
*/
public Integer getLeaseDuration() { public Integer getLeaseDuration() {
return leaseDuration; return leaseDuration;
} }
/**
* @return Lease is renewable
*/
public boolean isRenewable() { public boolean isRenewable() {
return renewable; return renewable;
} }

View File

@ -43,28 +43,46 @@ public final class AuthMethod {
@JsonProperty("local") @JsonProperty("local")
private boolean local; private boolean local;
/**
* @param type Backend type, passed to {@link AuthBackend#forType(String)}
*/
@JsonSetter("type") @JsonSetter("type")
public void setType(final String type) { public void setType(final String type) {
this.rawType = type; this.rawType = type;
this.type = AuthBackend.forType(type); this.type = AuthBackend.forType(type);
} }
/**
* @return Backend type
*/
public AuthBackend getType() { public AuthBackend getType() {
return type; return type;
} }
/**
* @return Raw backend type string
*/
public String getRawType() { public String getRawType() {
return rawType; return rawType;
} }
/**
* @return Description
*/
public String getDescription() { public String getDescription() {
return description; return description;
} }
/**
* @return Configuration data
*/
public Map<String, String> getConfig() { public Map<String, String> getConfig() {
return config; return config;
} }
/**
* @return Is local backend
*/
public boolean isLocal() { public boolean isLocal() {
return local; return local;
} }