|
36 | 36 | import java.io.InputStream; |
37 | 37 | import java.util.Collections; |
38 | 38 |
|
| 39 | +import jenkins.model.Jenkins; |
39 | 40 | import org.apache.commons.io.IOUtils; |
40 | 41 | import org.jenkinsci.Symbol; |
41 | 42 | import org.jenkinsci.plugins.credentialsbinding.BindingDescriptor; |
42 | 43 | import org.jenkinsci.plugins.plaincredentials.FileCredentials; |
43 | 44 | import org.kohsuke.stapler.AncestorInPath; |
44 | 45 | import org.kohsuke.stapler.DataBoundConstructor; |
45 | 46 | import org.kohsuke.stapler.QueryParameter; |
| 47 | +import org.kohsuke.stapler.StaplerRequest; |
46 | 48 |
|
47 | 49 | public class ZipFileBinding extends AbstractOnDiskBinding<FileCredentials> { |
48 | 50 |
|
@@ -72,7 +74,22 @@ public class ZipFileBinding extends AbstractOnDiskBinding<FileCredentials> { |
72 | 74 | return Messages.ZipFileBinding_secret_zip_file(); |
73 | 75 | } |
74 | 76 |
|
75 | | - public FormValidation doCheckCredentialsId(@AncestorInPath Item owner, @QueryParameter String value) { |
| 77 | + // @RequirePOST |
| 78 | + public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath Item owner, @QueryParameter String value) { |
| 79 | + //TODO due to weird behavior in c:select, there are initial calls using GET |
| 80 | + // so using this approach will prevent 405 errors |
| 81 | + if (!req.getMethod().equals("POST")) { |
| 82 | + return FormValidation.ok(); |
| 83 | + } |
| 84 | + if (owner == null) { |
| 85 | + if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { |
| 86 | + return FormValidation.ok(); |
| 87 | + } |
| 88 | + } else { |
| 89 | + if (!owner.hasPermission(Item.EXTENDED_READ) && !owner.hasPermission(CredentialsProvider.USE_ITEM)) { |
| 90 | + return FormValidation.ok(); |
| 91 | + } |
| 92 | + } |
76 | 93 | for (FileCredentials c : CredentialsProvider.lookupCredentials(FileCredentials.class, owner, null, Collections.<DomainRequirement>emptyList())) { |
77 | 94 | if (c.getId().equals(value)) { |
78 | 95 | InputStream is = null; |
|
0 commit comments