@@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
26
26
*/
27
27
package org .jenkinsci .plugins ;
28
28
29
+ import hudson .model .*;
29
30
import org .acegisecurity .Authentication ;
30
31
import org .jenkinsci .plugins .github_branch_source .GitHubSCMSource ;
31
32
import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
@@ -41,10 +42,6 @@ of this software and associated documentation files (the "Software"), to deal
41
42
import edu .umd .cs .findbugs .annotations .NonNull ;
42
43
import edu .umd .cs .findbugs .annotations .Nullable ;
43
44
44
- import hudson .model .AbstractItem ;
45
- import hudson .model .AbstractProject ;
46
- import hudson .model .Describable ;
47
- import hudson .model .Item ;
48
45
import hudson .plugins .git .GitSCM ;
49
46
import hudson .plugins .git .UserRemoteConfig ;
50
47
import hudson .security .ACL ;
@@ -64,6 +61,7 @@ public class GithubRequireOrganizationMembershipACL extends ACL {
64
61
65
62
private final List <String > organizationNameList ;
66
63
private final List <String > adminUserNameList ;
64
+ private String agentUserName ;
67
65
private final boolean authenticatedUserReadPermission ;
68
66
private final boolean useRepositoryPermissions ;
69
67
private final boolean authenticatedUserCreateJobPermission ;
@@ -102,6 +100,12 @@ public boolean hasPermission(@NonNull Authentication a, @NonNull Permission perm
102
100
return true ;
103
101
}
104
102
103
+ // Grant agent permissions to agent user
104
+ if (candidateName .equalsIgnoreCase (agentUserName ) && checkAgentUserPermission (permission )) {
105
+ log .finest ("Granting Agent Connect rights to user " + candidateName );
106
+ return true ;
107
+ }
108
+
105
109
// Are they trying to read?
106
110
if (checkReadPermission (permission )) {
107
111
// if we support authenticated read return early
@@ -153,6 +157,12 @@ else if (testBuildPermission(permission) && isInWhitelistedOrgs(authenticationTo
153
157
return true ;
154
158
}
155
159
160
+ // Grant agent permissions to agent user
161
+ if (authenticatedUserName .equalsIgnoreCase (agentUserName ) && checkAgentUserPermission (permission )) {
162
+ log .finest ("Granting Agent Connect rights to user " + authenticatedUserName );
163
+ return true ;
164
+ }
165
+
156
166
if (authenticatedUserName .equals ("anonymous" )) {
157
167
if (checkJobStatusPermission (permission ) && allowAnonymousJobStatusPermission ) {
158
168
return true ;
@@ -239,6 +249,13 @@ private boolean checkReadPermission(@NonNull Permission permission) {
239
249
|| id .equals ("hudson.model.Item.Read" ));
240
250
}
241
251
252
+ private boolean checkAgentUserPermission (@ NonNull Permission permission ) {
253
+ return permission .equals (Hudson .READ )
254
+ || permission .equals (Computer .CREATE )
255
+ || permission .equals (Computer .CONNECT )
256
+ || permission .equals (Computer .CONFIGURE );
257
+ }
258
+
242
259
private boolean checkJobStatusPermission (@ NonNull Permission permission ) {
243
260
return permission .getId ().equals ("hudson.model.Item.ViewStatus" );
244
261
}
@@ -314,10 +331,11 @@ public GithubRequireOrganizationMembershipACL(String adminUserNames,
314
331
}
315
332
316
333
this .item = null ;
334
+ this .agentUserName = "" ; // Initially blank - populated by a setter since this field is optional
317
335
}
318
336
319
337
public GithubRequireOrganizationMembershipACL cloneForProject (AbstractItem item ) {
320
- return new GithubRequireOrganizationMembershipACL (
338
+ GithubRequireOrganizationMembershipACL acl = new GithubRequireOrganizationMembershipACL (
321
339
this .adminUserNameList ,
322
340
this .organizationNameList ,
323
341
this .authenticatedUserReadPermission ,
@@ -328,6 +346,8 @@ public GithubRequireOrganizationMembershipACL cloneForProject(AbstractItem item)
328
346
this .allowAnonymousReadPermission ,
329
347
this .allowAnonymousJobStatusPermission ,
330
348
item );
349
+ acl .setAgentUserName (agentUserName );
350
+ return acl ;
331
351
}
332
352
333
353
public GithubRequireOrganizationMembershipACL (List <String > adminUserNameList ,
@@ -362,6 +382,11 @@ public List<String> getAdminUserNameList() {
362
382
return adminUserNameList ;
363
383
}
364
384
385
+ public void setAgentUserName (String agentUserName ) {
386
+ this .agentUserName = agentUserName ;
387
+ }
388
+ public String getAgentUserName () { return agentUserName ; }
389
+
365
390
public boolean isUseRepositoryPermissions () {
366
391
return useRepositoryPermissions ;
367
392
}
0 commit comments