|
7 | 7 | import hudson.model.Hudson; |
8 | 8 | import hudson.model.RootAction; |
9 | 9 | import hudson.model.UnprotectedRootAction; |
| 10 | +import hudson.security.ACL; |
10 | 11 | import hudson.util.AdaptedIterator; |
11 | 12 | import hudson.util.Iterators.FilterIterator; |
12 | 13 | import net.sf.json.JSONObject; |
| 14 | +import org.acegisecurity.Authentication; |
| 15 | +import org.acegisecurity.context.SecurityContextHolder; |
13 | 16 | import org.kohsuke.github.GitHub; |
14 | 17 | import org.kohsuke.stapler.StaplerRequest; |
15 | 18 |
|
@@ -152,16 +155,25 @@ public void doIndex(StaplerRequest req) { |
152 | 155 | LOGGER.fine("Full details of the POST was "+o.toString()); |
153 | 156 | Matcher matcher = REPOSITORY_NAME_PATTERN.matcher(repoUrl); |
154 | 157 | if (matcher.matches()) { |
155 | | - GitHubRepositoryName changedRepository = new GitHubRepositoryName(matcher.group(1), ownerName, repoName); |
156 | | - for (AbstractProject<?,?> job : Hudson.getInstance().getAllItems(AbstractProject.class)) { |
157 | | - GitHubPushTrigger trigger = job.getTrigger(GitHubPushTrigger.class); |
158 | | - if (trigger!=null) { |
159 | | - LOGGER.fine("Considering to poke "+job.getFullDisplayName()); |
160 | | - if (trigger.getGitHubRepositories().contains(changedRepository)) |
161 | | - trigger.onPost(); |
162 | | - else |
163 | | - LOGGER.fine("Skipped "+job.getFullDisplayName()+" because it doesn't have a matching repository."); |
| 158 | + // run in high privilege to see all the projects anonymous users don't see. |
| 159 | + // this is safe because when we actually schedule a build, it's a build that can |
| 160 | + // happen at some random time anyway. |
| 161 | + Authentication old = SecurityContextHolder.getContext().getAuthentication(); |
| 162 | + SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM); |
| 163 | + try { |
| 164 | + GitHubRepositoryName changedRepository = new GitHubRepositoryName(matcher.group(1), ownerName, repoName); |
| 165 | + for (AbstractProject<?,?> job : Hudson.getInstance().getAllItems(AbstractProject.class)) { |
| 166 | + GitHubPushTrigger trigger = job.getTrigger(GitHubPushTrigger.class); |
| 167 | + if (trigger!=null) { |
| 168 | + LOGGER.fine("Considering to poke "+job.getFullDisplayName()); |
| 169 | + if (trigger.getGitHubRepositories().contains(changedRepository)) |
| 170 | + trigger.onPost(); |
| 171 | + else |
| 172 | + LOGGER.fine("Skipped "+job.getFullDisplayName()+" because it doesn't have a matching repository."); |
| 173 | + } |
164 | 174 | } |
| 175 | + } finally { |
| 176 | + SecurityContextHolder.getContext().setAuthentication(old); |
165 | 177 | } |
166 | 178 | } else { |
167 | 179 | LOGGER.warning("Malformed repo url "+repoUrl); |
|
0 commit comments