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 aDataBoundConstructor
, be sure to usewithCurrentUser()
. Also usewithItem(hudson.model.Item)
orwithKey(java.lang.String)
orwithItemAsKey(hudson.model.Item)
whenever possible.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ApprovalContext
create()
Creates a new context with no information.Item
getItem()
Gets any associated item which should be displayed to an administrator.String
getKey()
Gets the unique key, if any.String
getUser()
Gets the associated user ID, if any.ApprovalContext
withCurrentUser()
Creates a context with the user associated with the current thread.ApprovalContext
withItem(Item item)
Associates an item with this approval, used only for display purposes.ApprovalContext
withItemAsKey(Item item)
Associates an item with this approval for display, as well as setting a unique key based on theItem.getFullName()
which would cancel any previous approvals for the same item.ApprovalContext
withKey(String key)
Associates a unique key with this approval.ApprovalContext
withUser(String user)
Creates a context with a specified user ID.
-
-
-
Method Detail
-
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 beJenkins.ANONYMOUS2
.)
-
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 theItem.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.
-
-