Class BitwardenConfig

All Implemented Interfaces:
ExtensionPoint, Describable<GlobalConfiguration>, Saveable, Loadable, OnMaster

@Extension @Symbol("bitwarden") public class BitwardenConfig extends GlobalConfiguration
Manages the system-wide configuration for the Bitwarden Credentials Provider plugin.

This class is a singleton managed by Jenkins, responsible for storing the plugin's global settings, presenting them in the "Configure System" UI, and handling the logic when the configuration is saved by a user or by JCasC.

  • Constructor Details

    • BitwardenConfig

      public BitwardenConfig()
      Called by Jenkins at startup to create the singleton instance of this class.

      The constructor first calls Descriptor.load() to populate the fields from the persisted XML configuration on disk.

  • Method Details

    • getDisplayName

      @Nonnull public String getDisplayName()
      Provides the display name for this configuration section in the "Configure System" page.
      Overrides:
      getDisplayName in class Descriptor<GlobalConfiguration>
      Returns:
      The internationalized display name.
    • getInstance

      public static BitwardenConfig getInstance()
      Provides global access to the single instance of this configuration.
      Returns:
      The singleton instance of BitwardenConfig.
    • getServerUrl

      public String getServerUrl()
    • getApiCredentialId

      public String getApiCredentialId()
    • getMasterPasswordCredentialId

      public String getMasterPasswordCredentialId()
    • getCliExecutablePath

      public String getCliExecutablePath()
    • getCacheDuration

      public int getCacheDuration()
    • getFileCredentialSuffixes

      public String getFileCredentialSuffixes()
    • setServerUrl

      @DataBoundSetter public void setServerUrl(String serverUrl)
    • setApiCredentialId

      @DataBoundSetter public void setApiCredentialId(String apiCredentialId)
    • setMasterPasswordCredentialId

      @DataBoundSetter public void setMasterPasswordCredentialId(String masterPasswordCredentialId)
    • setCliExecutablePath

      @DataBoundSetter public void setCliExecutablePath(String cliExecutablePath)
    • setCacheDuration

      @DataBoundSetter public void setCacheDuration(int cacheDuration)
    • setFileCredentialSuffixes

      @DataBoundSetter public void setFileCredentialSuffixes(String fileCredentialSuffixes)
    • isConfigured

      public boolean isConfigured()
      A helper method to check if the essential configuration (API key and master password) is present.
      Returns:
      true if the plugin is configured with the minimum required credentials.
    • configure

      public boolean configure(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject json) throws Descriptor.FormException
      The entry point for Jenkins when a user saves the global configuration from the UI. It binds the form data to this object's fields and then calls save().

      By calling save(), we create a single, unified hook that ensures changes made by both users (via this method) and by JCasC are handled consistently.

      Overrides:
      configure in class GlobalConfiguration
      Parameters:
      req - The current web request.
      json - The JSON object representing the form data for this configuration section.
      Returns:
      true to indicate success.
      Throws:
      Descriptor.FormException - if the form data cannot be processed.
    • save

      public void save()
      The unified hook for all configuration changes, called by both the UI (via configure(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject)) and JCasC.

      This method performs a "dirty check" to see if any critical settings have actually changed. If they have, it triggers a background task to re-authenticate and refresh the credential cache.

      Specified by:
      save in interface Saveable
      Overrides:
      save in class Descriptor<GlobalConfiguration>
    • doFillApiCredentialIdItems

      @POST public ListBoxModel doFillApiCredentialIdItems(@AncestorInPath Jenkins context, @QueryParameter String apiCredentialId)
      Populates the "Bitwarden API Key Credential" dropdown in the UI.

      This method is called by Stapler.

      Parameters:
      context - The current Jenkins context.
      apiCredentialId - The ID of the currently selected credential.
      Returns:
      A ListBoxModel containing suitable credentials.
    • doFillMasterPasswordCredentialIdItems

      @POST public ListBoxModel doFillMasterPasswordCredentialIdItems(@AncestorInPath Jenkins context, @QueryParameter String masterPasswordCredentialId)
      Populates the "Bitwarden Master Password Credential" dropdown in the UI.

      This method is called by Stapler.

      Parameters:
      context - The current Jenkins context.
      masterPasswordCredentialId - The ID of the currently selected credential.
      Returns:
      A ListBoxModel containing suitable credentials.
    • doRefreshCache

      @POST public FormValidation doRefreshCache()
      An action method for the "Refresh Now" button in the UI.

      This method is called by Stapler.

      Forces a re-authentication and triggers a non-destructive background refresh of the cache.

      Returns:
      A FormValidation object indicating the action has started.
    • doCheckCliVersion

      @POST public FormValidation doCheckCliVersion()
      An action method for the "Check Version" button in the UI.

      This method is called by Stapler.

      Returns:
      A FormValidation object showing the installed CLI version or an error.
    • doForceUpdateCli

      @POST public FormValidation doForceUpdateCli()
      An action method for the "Download Latest" button in the UI.

      This method is called by Stapler.

      Returns:
      A FormValidation object indicating the result of the download attempt.
    • doVerifySession

      @POST public FormValidation doVerifySession()
      An action method for the "Verify Session" button in the UI.

      This method is called by Stapler. It performs a fast, read-only check to see if the BitwardenSessionManager currently holds a valid, unlocked session token.

      Returns:
      A FormValidation object indicating if the current session is active or not.