@@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
2626 */
2727package org .jenkinsci .plugins ;
2828
29+ import hudson .model .*;
2930import org .acegisecurity .Authentication ;
3031import org .jenkinsci .plugins .github_branch_source .GitHubSCMSource ;
3132import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
@@ -41,10 +42,6 @@ of this software and associated documentation files (the "Software"), to deal
4142import edu .umd .cs .findbugs .annotations .NonNull ;
4243import edu .umd .cs .findbugs .annotations .Nullable ;
4344
44- import hudson .model .AbstractItem ;
45- import hudson .model .AbstractProject ;
46- import hudson .model .Describable ;
47- import hudson .model .Item ;
4845import hudson .plugins .git .GitSCM ;
4946import hudson .plugins .git .UserRemoteConfig ;
5047import hudson .security .ACL ;
@@ -64,6 +61,7 @@ public class GithubRequireOrganizationMembershipACL extends ACL {
6461
6562 private final List <String > organizationNameList ;
6663 private final List <String > adminUserNameList ;
64+ private String agentUserName ;
6765 private final boolean authenticatedUserReadPermission ;
6866 private final boolean useRepositoryPermissions ;
6967 private final boolean authenticatedUserCreateJobPermission ;
@@ -102,6 +100,12 @@ public boolean hasPermission(@NonNull Authentication a, @NonNull Permission perm
102100 return true ;
103101 }
104102
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+
105109 // Are they trying to read?
106110 if (checkReadPermission (permission )) {
107111 // if we support authenticated read return early
@@ -153,6 +157,12 @@ else if (testBuildPermission(permission) && isInWhitelistedOrgs(authenticationTo
153157 return true ;
154158 }
155159
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+
156166 if (authenticatedUserName .equals ("anonymous" )) {
157167 if (checkJobStatusPermission (permission ) && allowAnonymousJobStatusPermission ) {
158168 return true ;
@@ -239,6 +249,13 @@ private boolean checkReadPermission(@NonNull Permission permission) {
239249 || id .equals ("hudson.model.Item.Read" ));
240250 }
241251
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+
242259 private boolean checkJobStatusPermission (@ NonNull Permission permission ) {
243260 return permission .getId ().equals ("hudson.model.Item.ViewStatus" );
244261 }
@@ -314,10 +331,11 @@ public GithubRequireOrganizationMembershipACL(String adminUserNames,
314331 }
315332
316333 this .item = null ;
334+ this .agentUserName = "" ; // Initially blank - populated by a setter since this field is optional
317335 }
318336
319337 public GithubRequireOrganizationMembershipACL cloneForProject (AbstractItem item ) {
320- return new GithubRequireOrganizationMembershipACL (
338+ GithubRequireOrganizationMembershipACL acl = new GithubRequireOrganizationMembershipACL (
321339 this .adminUserNameList ,
322340 this .organizationNameList ,
323341 this .authenticatedUserReadPermission ,
@@ -328,6 +346,8 @@ public GithubRequireOrganizationMembershipACL cloneForProject(AbstractItem item)
328346 this .allowAnonymousReadPermission ,
329347 this .allowAnonymousJobStatusPermission ,
330348 item );
349+ acl .setAgentUserName (agentUserName );
350+ return acl ;
331351 }
332352
333353 public GithubRequireOrganizationMembershipACL (List <String > adminUserNameList ,
@@ -362,6 +382,11 @@ public List<String> getAdminUserNameList() {
362382 return adminUserNameList ;
363383 }
364384
385+ public void setAgentUserName (String agentUserName ) {
386+ this .agentUserName = agentUserName ;
387+ }
388+ public String getAgentUserName () { return agentUserName ; }
389+
365390 public boolean isUseRepositoryPermissions () {
366391 return useRepositoryPermissions ;
367392 }
0 commit comments