Class SandboxMethodContributor

java.lang.Object
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxMethodContributor
All Implemented Interfaces:
ExtensionPoint

@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public abstract class SandboxMethodContributor extends Object implements ExtensionPoint
Extension point for plugins to expose additional methods on existing types to sandboxed scripts, using Groovy's extension method pattern.

A contributed class declares static methods whose first parameter is the receiver type. Sandboxed scripts can then call those methods as if they were instance methods:

// helper class contributed by a plugin:
public class MyHelpers {
    @Whitelisted
    public static String getLabel(Job job) { return job.getFullDisplayName(); }
}

// in a sandboxed script:
echo job.getLabel()  // method call form
echo job.label       // property shorthand

Whitelist.permitsStaticMethod(Method, Object[]) runs before every dispatch; a method must be annotated @Whitelisted or have a StaticWhitelist entry, otherwise RejectedAccessException is thrown.

Execution trust: the whitelist check is an entrance gate only. Once permitted, the contributed method body runs as trusted plugin code outside the sandbox; calls within it are not subject to whitelist checks. Installed plugins are trusted by the admin.

  • Constructor Details

    • SandboxMethodContributor

      public SandboxMethodContributor()
  • Method Details

    • getContributedClasses

      @NonNull public abstract Class<?>[] getContributedClasses()
      Returns the static helper classes contributed by this extension. Each class must declare static methods whose first parameter is the receiver type. Methods callable from sandbox scripts must be annotated @Whitelisted. Must not return null or contain null elements.
    • all

      public static List<SandboxMethodContributor> all()