Class ApprovalContext

java.lang.Object
org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext

public final class ApprovalContext extends Object
Represents background information about who requested that a script or signature be approved and for what purpose. When created from a thread that generally carries authentication, such as within a DataBoundConstructor, be sure to use withCurrentUser(). Also use withItem(hudson.model.Item) or withKey(java.lang.String) or withItemAsKey(hudson.model.Item) whenever possible.
  • Method Details

    • create

      public static ApprovalContext create()
      Creates a new context with no information.
    • withUser

      public ApprovalContext withUser(@CheckForNull String user)
      Creates a context with a specified user ID. (ACL.SYSTEM2 is automatically ignored.)
    • withCurrentUser

      public ApprovalContext withCurrentUser()
      Creates a context with the user associated with the current thread. (ACL.SYSTEM2 is automatically ignored, but the user might be Jenkins.ANONYMOUS2.)
    • getUser

      @CheckForNull public String getUser()
      Gets the associated user ID, if any.
    • withItem

      public ApprovalContext withItem(@CheckForNull Item item)
      Associates an item with this approval, used only for display purposes.
    • getItem

      @CheckForNull public Item getItem()
      Gets any associated item which should be displayed to an administrator.
    • withKey

      public ApprovalContext withKey(@CheckForNull String key)
      Associates a unique key with this approval. If not null, any previous approval of the same kind with the same key will be canceled and replaced by this one. Only considered for whole-script approvals, not signature approvals which are generic.
    • getKey

      @CheckForNull public String getKey()
      Gets the unique key, if any.
    • withItemAsKey

      public ApprovalContext withItemAsKey(@CheckForNull Item item)
      Associates an item with this approval for display, as well as setting a unique key based on the Item.getFullName() which would cancel any previous approvals for the same item. Note that this only makes sense in cases where it is guaranteed that at most one approvable script is configured on a given item, so do not use this with (for example) build steps.