@SuppressWarnings("deprecation") private Object readResolve() { if (secureGroovyScript == null && !StringUtils.isBlank(groovyScriptContent)) { secureGroovyScript = new SecureGroovyScript(groovyScriptContent, false, null).configuring(ApprovalContext.create()); groovyScriptContent = null; } return this; }
/** * 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; } }
StringUtils.isNotBlank(groovyScriptContent) ? new SecureGroovyScript(groovyScriptContent, false, null).configuring(ApprovalContext.create()) : null);
@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; }
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); }
@SuppressWarnings("deprecation") private Object readResolve() throws Exception { if (command != null) { source = new StringSystemScriptSource(new SecureGroovyScript(command, false, null).configuring(ApprovalContext.create())); command = null; } else if (scriptSource instanceof StringScriptSource) { List<ClasspathEntry> classpathEntries = new ArrayList<ClasspathEntry>(); if (classpath != null) { StringTokenizer tokens = new StringTokenizer(classpath); while (tokens.hasMoreTokens()) { ClasspathEntry ce = new ClasspathEntry(tokens.nextToken()); if (ce.isClassDirectory()) { throw new UnsupportedOperationException("directory-based classpath entries not supported in system Groovy script string source"); } classpathEntries.add(ce); } } source = new StringSystemScriptSource(new SecureGroovyScript(Util.fixNull(((StringScriptSource) scriptSource).getCommand()), false, classpathEntries).configuring(ApprovalContext.create())); scriptSource = null; } else if (scriptSource instanceof FileScriptSource) { if (Util.fixEmpty(classpath) != null) { throw new UnsupportedOperationException("classpath no longer supported in conjunction with system Groovy script file source"); } else { source = new FileSystemScriptSource(((FileScriptSource) scriptSource).getScriptFile()); scriptSource = null; } } return this; }
@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())); }