use of org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext in project email-ext-plugin by jenkinsci.
the class ExtendedEmailPublisher method setPresendScript.
public void setPresendScript(String presendScript) {
presendScript = StringUtils.trim(presendScript);
if (!StringUtils.isBlank(presendScript) && !"$DEFAULT_PRESEND_SCRIPT".equals(presendScript)) {
ScriptApproval scriptApproval = ScriptApproval.get();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
StaplerRequest request = Stapler.getCurrentRequest();
if (request != null) {
Ancestor ancestor = request.findAncestor(Item.class);
if (ancestor != null) {
context = context.withItem((Item) ancestor.getObject());
}
}
scriptApproval.configuring(presendScript, GroovyLanguage.get(), context);
}
this.presendScript = presendScript;
}
use of org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext in project email-ext-plugin by jenkinsci.
the class ExtendedEmailPublisherDescriptor method setDefaultClasspath.
@DataBoundSetter
public void setDefaultClasspath(List<GroovyScriptPath> defaultClasspath) throws FormException {
if (Jenkins.get().isUseSecurity()) {
ScriptApproval approval = ScriptApproval.get();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
for (GroovyScriptPath path : defaultClasspath) {
URL u = path.asURL();
if (u != null) {
try {
approval.configuring(new ClasspathEntry(u.toString()), context);
} catch (MalformedURLException e) {
throw new FormException(e, "defaultClasspath");
}
}
}
}
this.defaultClasspath = defaultClasspath;
}
use of org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext in project email-ext-plugin by jenkinsci.
the class ExtendedEmailPublisher method setPostsendScript.
@DataBoundSetter
public void setPostsendScript(String postsendScript) {
postsendScript = StringUtils.trim(postsendScript);
if (!StringUtils.isBlank(postsendScript) && !"$DEFAULT_POSTSEND_SCRIPT".equals(postsendScript)) {
ScriptApproval scriptApproval = ScriptApproval.get();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
StaplerRequest request = Stapler.getCurrentRequest();
if (request != null) {
Ancestor ancestor = request.findAncestor(Item.class);
if (ancestor != null) {
context = context.withItem((Item) ancestor.getObject());
}
}
scriptApproval.configuring(postsendScript, GroovyLanguage.get(), context);
}
this.postsendScript = postsendScript;
}
use of org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext in project email-ext-plugin by jenkinsci.
the class ExtendedEmailPublisher method setClasspath.
public void setClasspath(List<GroovyScriptPath> classpath) {
if (classpath != null && !classpath.isEmpty() && Jenkins.get().isUseSecurity()) {
// Prepare the classpath for approval
ScriptApproval scriptApproval = ScriptApproval.get();
ApprovalContext context = ApprovalContext.create().withCurrentUser();
StaplerRequest request = Stapler.getCurrentRequest();
if (request != null) {
context = context.withItem(request.findAncestorObject(Item.class));
}
for (GroovyScriptPath path : classpath) {
URL pUrl = path.asURL();
if (pUrl != null) {
// At least we can try to catch some of them, but some might need token expansion
try {
scriptApproval.configuring(new ClasspathEntry(pUrl.toString()), context);
} catch (MalformedURLException e) {
// At least we tried, but we shouldn't end up here since path.asURL() would have returned null
assert false : e;
}
}
}
}
this.classpath = classpath;
}
Aggregations