@Deprecated public AbstractScriptTrigger(List<RecipientProvider> recipientProviders, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType, String triggerScript) { this(recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType, new SecureGroovyScript(triggerScript, false, null)); }
@Deprecated public String getTriggerScript() { return secureTriggerScript.getScript(); }
@DataBoundConstructor public StringSystemScriptSource(SecureGroovyScript script) { this.script = script.configuringWithNonKeyItem(); }
/** * Compiles the script. * * @return the compiled script * @throws CompilationFailedException * if the script contains compile errors */ public Script compile() throws CompilationFailedException { Binding binding = new Binding(); GroovyShell shell = new GroovyShell(GroovySandbox.createSecureClassLoader(GroovyExpressionMatcher.class.getClassLoader()), binding, GroovySandbox.createSecureCompilerConfiguration()); return shell.parse(script); }
/** * Called when object has been deserialized from a stream. * * @return {@code this}, or a replacement for {@code this}. * @throws ObjectStreamException if the object cannot be restored. * @see <a href="http://download.oracle.com/javase/1.3/docs/guide/serialization/spec/input.doc6.html">The Java Object Serialization Specification</a> */ private Object readResolve() throws ObjectStreamException { if (triggerScript != null && secureTriggerScript == null) { this.secureTriggerScript = new SecureGroovyScript(triggerScript, false, null); this.secureTriggerScript.configuring(ApprovalContext.create()); triggerScript = null; } return this; } }
public GroovyScriptExecutor(Script script, List<String> arguments, AbstractBuild<?, ?> build, Logger log) { this.arguments = new ArrayList<>(arguments); this.build = build; this.log = log; String enrichedScript = Util.replaceMacro(script.getContent(), EnvVars.masterEnvVars); secureGroovyScript = new SecureGroovyScript(enrichedScript, script.isSandboxed(), null); secureGroovyScript.configuringWithNonKeyItem(); }
private ClassLoader makeClassLoader() { ClassLoader cl = Jenkins.get().getPluginManager().uberClassLoader; return GroovySandbox.createSecureClassLoader(cl); }
public AbstractScriptTrigger(List<RecipientProvider> recipientProviders, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType, SecureGroovyScript secureTriggerScript) { super(recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType); this.secureTriggerScript = secureTriggerScript; StaplerRequest request = Stapler.getCurrentRequest(); ApprovalContext context = ApprovalContext.create().withCurrentUser(); if (request != null) { context = context.withItem(request.findAncestorObject(Item.class)); } this.secureTriggerScript.configuring(context); }
/** * @param context * Variables the script will see. */ private boolean evaluate(Binding context) { script.setBinding(context); try { return TRUE.equals(GroovySandbox.run(script, Whitelist.all())); } catch (RejectedAccessException x) { throw ScriptApproval.get().accessRejected(x, ApprovalContext.create()); } }
private CompilerConfiguration makeConfig() { CompilerConfiguration cc = sandbox ? GroovySandbox.createBaseCompilerConfiguration() : new CompilerConfiguration(); cc.addCompilationCustomizers(makeImportCustomizer()); cc.addCompilationCustomizers(makeCpsTransformer()); cc.setScriptBaseClass(CpsScript.class.getName()); for (GroovyShellDecorator d : decorators) { d.configureCompiler(execution,cc); } return cc; }
/** * Compiles the script. * * @return the compiled script * @throws CompilationFailedException if the script contains compile errors */ public Script compile() throws CompilationFailedException { Binding binding = new Binding(); binding.setVariable("falsePositive", falsePositive); GroovyShell shell = new GroovyShell(GroovySandbox.createSecureClassLoader(WarningsDescriptor.class.getClassLoader()), binding, GroovySandbox.createSecureCompilerConfiguration()); return shell.parse(script); }
@SuppressWarnings("deprecation") private Object readResolve() { if (secureGroovyScript == null && !StringUtils.isBlank(groovyScriptContent)) { secureGroovyScript = new SecureGroovyScript(groovyScriptContent, false, null).configuring(ApprovalContext.create()); groovyScriptContent = null; } return this; }
@Override public EmailTrigger createDefault() { return new PreBuildScriptTrigger(defaultRecipientProviders, "", "$PROJECT_DEFAULT_REPLYTO", "$PROJECT_DEFAULT_SUBJECT", "$PROJECT_DEFAULT_CONTENT", "", 0, "project", new SecureGroovyScript("", false, null)); } }
@DataBoundConstructor public GroovyCondition(final SecureGroovyScript script, final String unmetQualificationLabel, final String metQualificationLabel) { this.unmetQualificationLabel = Util.fixEmptyAndTrim(unmetQualificationLabel); this.metQualificationLabel = Util.fixEmptyAndTrim(metQualificationLabel); this.script = script.configuringWithNonKeyItem(); }
@Override public boolean configure(@Nonnull StaplerRequest req, @Nonnull JSONObject formData) { super.configure(req, formData); if(formData.containsKey("secureTriggerScript")) { this.secureTriggerScript = req.bindJSON(SecureGroovyScript.class, formData.getJSONObject("secureTriggerScript")); this.secureTriggerScript.configuring(ApprovalContext.create().withCurrentUser().withItem(req.findAncestorObject(Item.class))); } return true; }
private boolean hasScript() { return secureTriggerScript != null && StringUtils.isNotEmpty(secureTriggerScript.getScript()); }
/** * @since 1.541 */ public static FilterScript parse(String expression, FilterScript defaultScript) { if (Util.fixEmptyAndTrim(expression)==null) return defaultScript; GroovyShell shell = new GroovyShell(GroovySandbox.createSecureClassLoader(FilterScript.class.getClassLoader()), new Binding(), GroovySandbox.createSecureCompilerConfiguration()); return new FilterScript(shell.parse(expression)); }
@Override public SecureGroovyScript getSecureGroovyScript(FilePath projectWorkspace, AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException { EnvVars env = build.getEnvironment(listener); String expandedScriptFile = env.expand(this.scriptFile); String text = new FilePath(projectWorkspace, expandedScriptFile).readToString(); return new SecureGroovyScript(text, true, null).configuring(ApprovalContext.create()/* unused but just in case: */.withItem(build.getParent())); }
@Override public EmailTrigger createDefault() { return new ScriptTrigger(defaultRecipientProviders, "", "$PROJECT_DEFAULT_REPLYTO", "$PROJECT_DEFAULT_SUBJECT", "$PROJECT_DEFAULT_CONTENT", "", 0, "project", new SecureGroovyScript("", false, null)); } }
@CheckForNull @Deprecated public String getGroovyScriptContent() { return secureGroovyScript != null ? Util.fixEmpty(secureGroovyScript.getScript()) : null; }