Search in sources :

Example 1 with ApprovalContext

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;
}
Also used : ApprovalContext(org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext) Item(hudson.model.Item) StaplerRequest(org.kohsuke.stapler.StaplerRequest) Ancestor(org.kohsuke.stapler.Ancestor) ScriptApproval(org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval)

Example 2 with ApprovalContext

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;
}
Also used : ApprovalContext(org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext) MalformedURLException(java.net.MalformedURLException) ClasspathEntry(org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry) ScriptApproval(org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval) URL(java.net.URL) DataBoundSetter(org.kohsuke.stapler.DataBoundSetter)

Example 3 with ApprovalContext

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;
}
Also used : ApprovalContext(org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext) Item(hudson.model.Item) StaplerRequest(org.kohsuke.stapler.StaplerRequest) Ancestor(org.kohsuke.stapler.Ancestor) ScriptApproval(org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval) DataBoundSetter(org.kohsuke.stapler.DataBoundSetter)

Example 4 with ApprovalContext

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;
}
Also used : ApprovalContext(org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext) MalformedURLException(java.net.MalformedURLException) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ClasspathEntry(org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry) ScriptApproval(org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval) URL(java.net.URL)

Aggregations

ApprovalContext (org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext)4 ScriptApproval (org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval)4 StaplerRequest (org.kohsuke.stapler.StaplerRequest)3 Item (hudson.model.Item)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ClasspathEntry (org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry)2 Ancestor (org.kohsuke.stapler.Ancestor)2 DataBoundSetter (org.kohsuke.stapler.DataBoundSetter)2