Class VaultClient

java.lang.Object
com.veeva.vault.vapil.api.client.VaultClient

public class VaultClient extends Object
Base class for all Vault integration calls where a Vault session is established via:
1. Basic authentication using Vault user name and password
2. Existing Vault session, such as a session passed from Vault Web Action/Tab or Vault Job Scheduler
3. OAuth

New API requests are created via the "newRequest" method, passing in the request class to instantiate.

  • Field Details

    • VAULT_API_VERSION

      public static final String VAULT_API_VERSION
      The current Vault API Version "v25.1". This variable drives the version used in all API calls.
      See Also:
  • Constructor Details

    • VaultClient

      protected VaultClient()
  • Method Details

    • newRequest

      public <T> T newRequest(Class<T> requestClass)
      Instantiate a new request to the Vault API endpoint.

      The Vault Client Id is required for all new requests. An error is thrown if no client id is set.

      Type Parameters:
      T - The request class to instantiate
      Parameters:
      requestClass - The request class to instantiate
      Returns:
      Object of the instantiated class
    • getVaultDNS

      public String getVaultDNS()
      Returns:
      Vault DNS in format "myvault.veevavault.com"
    • setVaultDNS

      public void setVaultDNS(String vaultDNS)
      Parameters:
      vaultDNS - Vault DNS in format "myvault.veevavault.com"
    • getVaultUrl

      public String getVaultUrl()
      Returns:
      Vault URL in format "https://myvault.veevavault.com"
    • getUsername

      public String getUsername()
      Returns:
      Vault user name
    • getPassword

      public String getPassword()
      Returns:
      Vault user password
    • setPassword

      public void setPassword(String password)
      Parameters:
      password - to set
    • setUsername

      public void setUsername(String username)
      Parameters:
      username - to set
    • getVaultClientId

      public String getVaultClientId()
      Returns:
      The client id for Vault API calls
    • setVaultClientId

      protected void setVaultClientId(String vaultClientId)
      Set the client id for Vault API requests
      Parameters:
      vaultClientId - Vault Client Id
    • setAllowAllCertificates

      public void setAllowAllCertificates(boolean allowAllCertificates)
      Allow Vault Client to trust all certificates
      Parameters:
      allowAllCertificates - true/false
    • getAllowAllCertificates

      public boolean getAllowAllCertificates()
    • getAPIEndpoint

      public String getAPIEndpoint(boolean includeVersion)
      Get the fully formed root API URL consisting of the Vault DNS
      Parameters:
      includeVersion - include version
      Returns:
      URL for the API endpoint in form https://myvault.com/api/{version}
    • getAPIEndpoint

      public String getAPIEndpoint(String endpoint)
      Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.
      Parameters:
      endpoint - API endpoint in form "/objects/documents"
      Returns:
      URL for the API endpoint in form https://myvault.com/api/{version}/objects/documents
    • getAPIEndpoint

      public String getAPIEndpoint(String endpoint, boolean includeVersion)
      Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.
      Parameters:
      endpoint - API endpoint in form "/objects/documents"
      includeVersion - include version in final endpoint
      Returns:
      URL for the API endpoint in form: includeVersion(true) - https://myvault.com/api/{version}/objects/documents includeVersion(false) - https://myvault.com/api/mdl/components
    • getLoginEndpoint

      public String getLoginEndpoint(String endpoint)
      Get a fully formed API URL consisting of the Vault login URL and the API endpoint.
      Parameters:
      endpoint - API endpoint in form "/objects/documents"
      Returns:
      URL for the API endpoint in form https://login.veevavault.com/auth/discovery
    • getPaginationEndpoint

      public String getPaginationEndpoint(String pageUrl)
      Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.
      Parameters:
      pageUrl - The URL from the previous_page or next_page parameter
      Returns:
      URL for the API endpoint in form https://myvault.com/api/{version}/objects/documents
    • getHrefEndpoint

      public String getHrefEndpoint(String href)
    • getAuthenticationResponse

      public AuthenticationResponse getAuthenticationResponse()
      Returns:
      The response from an authentication request, which includes the Vault session id and the vaults that the user has access to. Note that only the session id is set if VaultConnection was instantiated with an existing Vault session (since an authentication call was not performed).
    • getSessionId

      public String getSessionId()
      Returns the session ID from the Vault client's auth response.
      Returns:
      The Vault session id from an Authentication Response
    • hasSessionId

      public boolean hasSessionId()
      Check if the Vault client has an auth response with a session ID.
      Returns:
      true if the Vault Client has an auth response with a session id.
    • getUserId

      public String getUserId()
      Returns the user ID from the Vault client's auth response. Note that this will return null if VaultConnection was instantiated with an existing Vault session (since an authentication call was not performed).
      Returns:
      The user id for the authenticated user
    • setLogApiErrors

      public VaultClient setLogApiErrors(boolean logApiErrors)
      Sets whether or not to log api errors. Default=true
      Parameters:
      logApiErrors - true/false
      Returns:
      VaultClient
    • isLogApiErrorsEnabled

      public Boolean isLogApiErrorsEnabled()
      Indicates whether or not to log api errors. Default=true
      Returns:
      true/false
    • setAuthenticationResponse

      protected void setAuthenticationResponse(AuthenticationResponse authenticationResponse)
    • validateSession

      public boolean validateSession()
      Validate the current sessionId. The session must be active and the vaultDNS from the request and the response must equal. If the session or vaultDNS is not valid, the current sessionId will be cleared and an error logged.
      Returns:
      true if the session is valid.
    • newClientBuilder

      public static VaultClient.Builder newClientBuilder(VaultClient.AuthenticationType authenticationType)
      Create a new instance of a VaultClient.Builder
      Parameters:
      authenticationType - VaultClient.AuthenticationType
      Returns:
      VaultClient.Builder
    • newClientBuilderFromSettings

      public static VaultClient.Builder newClientBuilderFromSettings(File settingsFile)
      Create a new instance of a VaultClient.Builder with client parameters initialized from a .json file

      Example

       File settingsFile = new File("settings.json");
      
       VaultClient vaultClient = VaultClient
                      .newClientBuilderFromSettings(settingsFile)
                      .build();
       
      Parameters:
      settingsFile - settings from a .json file
      Returns:
      VaultClient.Builder
    • newClientBuilderFromSettings

      public static VaultClient.Builder newClientBuilderFromSettings(String settingsJson)
      Create a new instance of a VaultClient.Builder with client parameters initialized from a JSON string

      Example

       String jsonString =
                      "{\n" +
                      "  \"authenticationType\": \"BASIC\",\n" +
                      "  \"idpOauthAccessToken\": \"\",\n" +
                      "  \"idpOauthScope\": \"openid\",\n" +
                      "  \"idpUsername\": \"\",\n" +
                      "  \"idpPassword\": \"\",\n" +
                      "  \"vaultUsername\": \"USERNAME\",\n" +
                      "  \"vaultPassword\": \"PASSWORD\",\n" +
                      "  \"vaultDNS\": \"DNS\",\n" +
                      "  \"vaultSessionId\": \"\",\n" +
                      "  \"vaultClientId\": \"veeva-vault-devsupport-client-vapil\",\n" +
                      "  \"vaultOauthClientId\": \"\",\n" +
                      "  \"vaultOauthProfileId\": \"\",\n" +
                      "  \"logApiErrors\": true,\n" +
                      "  \"httpTimeout\": null,\n" +
                      "  \"validateSession\": true\n" +
                      "}";
      
       VaultClient vaultClient = VaultClient
                      .newClientBuilderFromSettings(jsonString)
                      .build();
       
      Parameters:
      settingsJson - settings in JSON format
      Returns:
      VaultClient.Builder
    • newClientBuilderFromSettings

      public static VaultClient.Builder newClientBuilderFromSettings(VaultClient.Settings vaultClientSettings)