Skip to content

Commit

Permalink
[JENKINS-21103] "Priorities (...) first match" does not work correctly
Browse files Browse the repository at this point in the history
Since the listener is not called as SYSTEM but rather as a user
I added impersonating for all getPriority() lookups to make
sure that the code can read all Views and all Jobs.
  • Loading branch information
emsa23 committed Jan 2, 2014
1 parent 035da32 commit f91ad33
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/jenkins/advancedqueue/PriorityConfiguration.java
Expand Up @@ -34,6 +34,7 @@
import hudson.model.RootAction;
import hudson.model.TopLevelItem;
import hudson.model.View;
import hudson.security.ACL;
import hudson.security.Permission;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
Expand All @@ -59,6 +60,8 @@
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand Down Expand Up @@ -189,8 +192,18 @@ public FormValidation doCheckJobPattern(@QueryParameter String value) throws IOE
}
return FormValidation.ok();
}

public PriorityConfigurationCallback getPriority(Queue.Item item, PriorityConfigurationCallback priorityCallback) {
SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
try {
return getPriorityInternal(item, priorityCallback);
} finally {
SecurityContextHolder.setContext(saveCtx);
}
}

private PriorityConfigurationCallback getPriorityInternal(Queue.Item item,
PriorityConfigurationCallback priorityCallback) {
Job<?, ?> job = (Job<?, ?>) item.task;

// [JENKINS-8597]
Expand Down

0 comments on commit f91ad33

Please sign in to comment.