@@ -26,24 +26,32 @@ of this software and associated documentation files (the "Software"), to deal
26
26
*/
27
<
10000
td data-grid-cell-id="diff-cc7ab75bded9621aa042633b3d55ab401e4141ae1ab84e22b3b1a00dac737148-27-27-1" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">27
package org .jenkinsci .plugins ;
28
28
29
- import hudson .model .AbstractProject ;
30
- import hudson .model .Item ;
31
- import hudson .plugins .git .GitSCM ;
32
- import hudson .plugins .git .UserRemoteConfig ;
33
- import hudson .scm .SCM ;
34
- import hudson .security .ACL ;
35
- import hudson .security .Permission ;
36
- import jenkins .model .Jenkins ;
37
29
import org .acegisecurity .Authentication ;
30
+ import org .jenkinsci .plugins .github_branch_source .GitHubSCMSource ;
31
+ import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
32
+ import org .jenkinsci .plugins .workflow .multibranch .BranchJobProperty ;
38
33
import org .kohsuke .stapler .Stapler ;
39
34
import org .kohsuke .stapler .StaplerRequest ;
40
35
41
- import javax .annotation .Nonnull ;
42
36
import java .net .URI ;
43
37
import java .util .LinkedList ;
44
38
import java .util .List ;
45
39
import java .util .logging .Logger ;
46
40
41
+ import javax .annotation .Nonnull ;
42
+
43
+ import hudson .model .AbstractItem ;
44
+ import hudson .model .AbstractProject ;
45
+ import hudson .model .Describable ;
46
+ import hudson .model .Item ;
47
+ import hudson .plugins .git .GitSCM ;
48
+ import hudson .plugins .git .UserRemoteConfig ;
49
+ import hudson .security .ACL ;
50
+ import hudson .security .Permission ;
51
+ import jenkins .branch .MultiBranchProject ;
52
+ import jenkins .model .Jenkins ;
53
+ import jenkins .scm .api .SCMSource ;
54
+
47
55
/**
48
56
* @author Mike
49
57
*
@@ -62,7 +70,7 @@ public class GithubRequireOrganizationMembershipACL extends ACL {
62
70
private final boolean allowCcTrayPermission ;
63
71
private final boolean allowAnonymousReadPermission ;
64
72
private final boolean allowAnonymousJobStatusPermission ;
65
- private final AbstractProject project ;
73
+ private final AbstractItem item ;
66
74
67
75
/*
68
76
* (non-Javadoc)
@@ -86,19 +94,19 @@ public boolean hasPermission(@Nonnull Authentication a, @Nonnull Permission perm
86
94
return true ;
87
95
}
88
96
89
- if (this .project != null ) {
97
+ if (this .item != null ) {
90
98
if (useRepositoryPermissions ) {
91
99
if (hasRepositoryPermission (authenticationToken , permission )) {
92
100
log .finest ("Granting Authenticated User " + permission .getId () +
93
- " permission on project " + project .getName () +
101
+ " permission on project " + item .getName () +
94
102
"to user " + candidateName );
95
103
return true ;
96
104
}
97
105
} else {
98
106
if (authenticatedUserReadPermission ) {
99
107
if (checkReadPermission (permission )) {
100
108
log .finest ("Granting Authenticated User read permission " +
101
- "on project " + project .getName () +
109
+ "on project " + item .getName () +
102
110
"to user " + candidateName );
103
111
return true ;
104
112
}
@@ -270,18 +278,34 @@ public boolean hasRepositoryPermission(GithubAuthenticationToken authenticationT
270
278
271
279
private String getRepositoryName () {
272
280
String repositoryName = null ;
273
- SCM scm = this .project .getScm ();
274
- if (scm instanceof GitSCM ) {
275
- GitSCM git = (GitSCM )scm ;
281
+ String repoUrl = null ;
282
+ Describable scm = null ;
283
+ if (this .item instanceof WorkflowJob ) {
284
+ WorkflowJob project = (WorkflowJob ) item ;
285
+ scm = project .getProperty (BranchJobProperty .class ).getBranch ().getScm ();
286
+ } else if (this .item instanceof MultiBranchProject ) {
287
+ MultiBranchProject project = (MultiBranchProject ) item ;
288
+ scm = (SCMSource ) project .getSCMSources ().get (0 );
289
+ } else if (this .item instanceof AbstractProject ) {
290
+ AbstractProject project = (AbstractProject ) item ;
291
+ scm = project .getScm ();
292
+ }
293
+ if (scm instanceof GitHubSCMSource ) {
294
+ GitHubSCMSource git = (GitHubSCMSource ) scm ;
295
+ repoUrl = git .getRemote ();
296
+ } else if (scm instanceof GitSCM ) {
297
+ GitSCM git = (GitSCM ) scm ;
276
298
List <UserRemoteConfig > userRemoteConfigs = git .getUserRemoteConfigs ();
277
299
if (!userRemoteConfigs .isEmpty ()) {
278
- String repoUrl = userRemoteConfigs .get (0 ).getUrl ();
279
- if (repoUrl != null ) {
280
- GitHubRepositoryName githubRepositoryName = GitHubRepositoryName .create (repoUrl );
281
- if (githubRepositoryName != null ) {
282
- repositoryName = githubRepositoryName .userName + "/" + githubRepositoryName .repositoryName ;
283
- }
284
- }
300
+ repoUrl = userRemoteConfigs .get (0 ).getUrl ();
301
+ }
302
+ }
303
+ if (repoUrl != null ) {
304
+ GitHubRepositoryName githubRepositoryName =
305
+ GitHubRepositoryName .create (repoUrl );
306
+ if (githubRepositoryName != null ) {
307
+ repositoryName = githubRepositoryName .userName + "/"
308
+ + githubRepositoryName .repositoryName ;
285
309
}
286
310
}
287
311
return repositoryName ;
@@ -321,7 +345,21 @@ public GithubRequireOrganizationMembershipACL(String adminUserNames,
321
345
organizationNameList .add (part .trim ());
322
346
}
323
347
324
- this .project = null ;
348
+ this .item = null ;
349
+ }
350
+
351
+ public GithubRequireOrganizationMembershipACL cloneForProject (AbstractItem item ) {
352
+ return new GithubRequireOrganizationMembershipACL (
353
+ this .adminUserNameList ,
354
+ this .organizationNameList ,
355
+ this .authenticatedUserReadPermission ,
356
+ this .useRepositoryPermissions ,
357
+ this .authenticatedUserCreateJobPermission ,
358
+ this .allowGithubWebHookPermission ,
359
+ this .allowCcTrayPermission ,
360
+ this .allowAnonymousReadPermission ,
361
+ this .allowAnonymousJobStatusPermission ,
362
+ item );
325
363
}
326
364
327
365
public GithubRequireOrganizationMembershipACL (List <String > adminUserNameList ,
@@ -333,7 +371,7 @@ public GithubRequireOrganizationMembershipACL(List<String> adminUserNameList,
333
371
boolean allowCcTrayPermission ,
334
372
boolean allowAnonymousReadPermission ,
335
373
boolean allowAnonymousJobStatusPermission ,
336
- AbstractProject project ) {
374
+ AbstractItem item ) {
337
375
super ();
338
376
339
377
this .adminUserNameList = adminUserNameList ;
@@ -345,21 +383,7 @@ public GithubRequireOrganizationMembershipACL(List<String> adminUserNameList,
345
383
this .allowCcTrayPermission = allowCcTrayPermission ;
346
384
this .allowAnonymousReadPermission = allowAnonymousReadPermission ;
347
385
this .allowAnonymousJobStatusPermission = allowAnonymousJobStatusPermission ;
348
- this .project = project ;
349
- }
350
-
351
- public GithubRequireOrganizationMembershipACL cloneForProject (AbstractProject project ) {
352
- return new GithubRequireOrganizationMembershipACL (
353
- this .adminUserNameList ,
354
- this .organizationNameList ,
355
- this .authenticatedUserReadPermission ,
356
- this .useRepositoryPermissions ,
357
- this .authenticatedUserCreateJobPermission ,
358
- this .allowGithubWebHookPermission ,
359
- this .allowCcTrayPermission ,
360
- this .allowAnonymousReadPermission ,
361
- this .allowAnonymousJobStatusPermission ,
362
- project );
386
+ this .item = item ;
363
387
}
364
388
365
389
public List <String > getOrganizationNameList () {
0 commit comments