Skip to content

Commit 57e76cb

Browse files
authored
Merge pull request #379 from amuniz/JENKINS-73163
[JENKINS-73163] Follow up on Overall/Manage permission support
2 parents c6481b4 + 3ce945b commit 57e76cb

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/main/java/org/jenkinsci/plugins/github/config/GitHubPluginConfig.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import com.google.common.base.Function;
55
import com.google.common.base.Predicate;
66
import com.google.common.base.Predicates;
7+
import edu.umd.cs.findbugs.annotations.NonNull;
78
import hudson.Extension;
89
import hudson.Util;
910
import hudson.XmlFile;
1011
import hudson.model.Descriptor;
1112
import hudson.model.Item;
13+
import hudson.security.Permission;
1214
import hudson.util.FormValidation;
1315
import jenkins.model.GlobalConfiguration;
1416
import jenkins.model.Jenkins;
@@ -212,7 +214,7 @@ public String getDisplayName() {
212214
@SuppressWarnings("unused")
213215
@RequirePOST
214216
public FormValidation doReRegister() {
215-
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
217+
Jenkins.getActiveInstance().checkPermission(Jenkins.MANAGE);
216218
if (!GitHubPlugin.configuration().isManageHooks()) {
217219
return FormValidation.warning("Works only when Jenkins manages hooks (one or more creds specified)");
218220
}
@@ -227,7 +229,7 @@ public FormValidation doReRegister() {
227229
@Restricted(DoNotUse.class) // WebOnly
228230
@SuppressWarnings("unused")
229231
public FormValidation doCheckHookUrl(@QueryParameter String value) {
230-
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
232+
Jenkins.getActiveInstance().checkPermission(Jenkins.MANAGE);
231233
try {
232234
HttpURLConnection con = (HttpURLConnection) new URL(value).openConnection();
233235
con.setRequestMethod("POST");
@@ -317,4 +319,10 @@ private URL parseHookUrl(String hookUrl) {
317319
return null;
318320
}
319321
}
322+
323+
@NonNull
324+
@Override
325+
public Permission getRequiredGlobalConfigPagePermission() {
326+
return Jenkins.MANAGE;
327+
}
320328
}

src/main/java/org/jenkinsci/plugins/github/config/GitHubServerConfig.java

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import hudson.model.AbstractDescribableImpl;
1515
import hudson.model.Descriptor;
1616
import hudson.security.ACL;
17+
import hudson.security.Permission;
1718
import hudson.util.FormValidation;
1819
import hudson.util.ListBoxModel;
1920
import hudson.util.Secret;
@@ -345,6 +346,12 @@ public String getDisplayName() {
345346
return "GitHub Server";
346347
}
347348

349+
@NonNull
350+
@Override
351+
public Permission getRequiredGlobalConfigPagePermission() {
352+
return Jenkins.MANAGE;
353+
}
354+
348355
@SuppressWarnings("unused")
349356
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String apiUrl,
350357
@QueryParameter String credentialsId) {
@@ -419,4 +426,6 @@ protected GitHub applyNullSafe(@NonNull GitHubServerConfig github) {
419426
return github.getCachedClient();
420427
}
421428
}
429+
430+
422431
}

src/main/java/org/jenkinsci/plugins/github/config/GitHubTokenCredentialsCreator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public String getDisplayName() {
9292

9393
@SuppressWarnings("unused")
9494
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String apiUrl, @QueryParameter String credentialsId) {
95-
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
95+
if (!Jenkins.getInstance().hasPermission(Jenkins.MANAGE)) {
9696
return new StandardUsernameListBoxModel().includeCurrentValue(credentialsId);
9797
}
9898
return new StandardUsernameListBoxModel()
@@ -118,7 +118,7 @@ public ListBoxModel doFillCredentialsIdItems(@QueryParameter String apiUrl, @Que
118118
public FormValidation doCreateTokenByCredentials(
119119
@QueryParameter String apiUrl,
120120
@QueryParameter String credentialsId) {
121-
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
121+
Jenkins.getActiveInstance().checkPermission(Jenkins.MANAGE);
122122
if (isEmpty(credentialsId)) {
123123
return FormValidation.error("Please specify credentials to create token");
124124
}
@@ -167,7 +167,7 @@ public FormValidation doCreateTokenByPassword(
167167
@QueryParameter String apiUrl,
168168
@QueryParameter String login,
169169
@QueryParameter String password) {
170-
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
170+
Jenkins.getActiveInstance().checkPermission(Jenkins.MANAGE);
171171
try {
172172
GHAuthorization token = createToken(login, password, defaultIfBlank(apiUrl, GITHUB_URL));
173173
StandardCredentials credentials = createCredentials(apiUrl, token.getToken(), login);

src/main/java/org/jenkinsci/plugins/github/config/HookSecretConfig.java

+8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import com.cloudbees.plugins.credentials.CredentialsMatchers;
44
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
55
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
6+
import edu.umd.cs.findbugs.annotations.NonNull;
67
import hudson.Extension;
78
import hudson.model.AbstractDescribableImpl;
89
import hudson.model.Descriptor;
910
import hudson.security.ACL;
11+
import hudson.security.Permission;
1012
import hudson.util.ListBoxModel;
1113
import hudson.util.Secret;
1214
import jenkins.model.Jenkins;
@@ -76,5 +78,11 @@ public ListBoxModel doFillCredentialsIdItems(@QueryParameter String credentialsI
7678
CredentialsMatchers.always()
7779
);
7880
}
81+
82+
@NonNull
83+
@Override
84+
public Permission getRequiredGlobalConfigPagePermission() {
85+
return Jenkins.MANAGE;
86+
}
7987
}
8088
}

0 commit comments

Comments
 (0)