Skip to content

Commit 393ada3

Browse files
authored
Merge pull request jenkinsci#92 from Wadeck/SPEED_UP_API_TOKEN_AUTHORITIES
[JENKINS-48412] Fix authorities retrieval for API Token
2 parents 7e13146 + 99e3d13 commit 393ada3

File tree

2 files changed

+1
-50
lines changed

2 files changed

+1
-50
lines changed

src/main/java/org/jenkinsci/plugins/GithubAuthenticationToken.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -409,53 +409,4 @@ public GithubOAuthUserDetails getUserDetails(String username) throws IOException
409409
}
410410
return null;
411411
}
412-
413-
public GrantedAuthority[] getGrantedAuthorities(GHUser user) {
414-
List<GrantedAuthority> groups = new ArrayList<GrantedAuthority>();
415-
groups.add(SecurityRealm.AUTHENTICATED_AUTHORITY);
416-
417-
try {
418-
GHPersonSet<GHOrganization> orgs;
419-
if(myRealm == null) {
420-
Jenkins jenkins = Jenkins.getInstance();
421-
if (jenkins == null) {
422-
throw new IllegalStateException("Jenkins not started");
423-
}
424-
myRealm = (GithubSecurityRealm) jenkins.getSecurityRealm();
425-
}
426-
//Search for scopes that allow fetching team membership. This is documented online.
427-
//https://developer.github.com/v3/orgs/#list-your-organizations
428-
//https://developer.github.com/v3/orgs/teams/#list-user-teams
429-
if(this.userName.equals(user.getLogin()) && (myRealm.hasScope("read:org") || myRealm.hasScope("admin:org") || myRealm.hasScope("user") || myRealm.hasScope("repo"))) {
430-
//This allows us to search for private organization membership.
431-
orgs = getMyself().getAllOrganizations();
432-
} else {
433-
//This searches for public organization membership.
434-
orgs = user.getOrganizations();
435-
}
436-
for (GHOrganization ghOrganization : orgs) {
437-
String orgLogin = ghOrganization.getLogin();
438-
LOGGER.log(Level.FINE, "Fetch teams for user " + user.getLogin() + " in organization " + orgLogin);
439-
groups.add(new GrantedAuthorityImpl(orgLogin));
440-
try {
441-
if (!getMyself().isMemberOf(ghOrganization)) {
442-
continue;
443-
}
444-
Map<String, GHTeam> teams = ghOrganization.getTeams();
445-
for (Map.Entry<String, GHTeam> entry : teams.entrySet()) {
446-
GHTeam team = entry.getValue();
447-
if (team.hasMember(user)) {
448-
groups.add(new GrantedAuthorityImpl(orgLogin + GithubOAuthGroupDetails.ORG_TEAM_SEPARATOR
449-
+ team.getName()));
450-
}
451-
}
452-
} catch (IOException | Error ignore) {
453-
LOGGER.log(Level.FINEST, "not enough rights to list teams from " + orgLogin, ignore);
454-
}
455-
}
456-
} catch(IOException e) {
457-
LOGGER.log(Level.FINE, e.getMessage(), e);
458-
}
459-
return groups.toArray(new GrantedAuthority[groups.size()]);
460-
}
461412
}

src/main/java/org/jenkinsci/plugins/GithubOAuthUserDetails.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public GrantedAuthority[] getAuthorities() {
4343
try {
4444
GHUser user = authenticationToken.loadUser(getUsername());
4545
if(user != null) {
46-
setAuthorities(authenticationToken.getGrantedAuthorities(user));
46+
setAuthorities(authenticationToken.getAuthorities());
4747
}
4848
} catch (IOException e) {
4949
throw new RuntimeException(e);

0 commit comments

Comments
 (0)