Skip to content

Commit 0646c4a

Browse files
authored
[JENKINS-72268] Missing permission due to desync with cache (#256)
* [JENKINS-72268] Ensure "gh" is present In case of impersonation the gh variable and the usersByTokenCache could be de-sync, leading to token not able to connect. Could be related to JENKINS-72209 as well. * Fix an exception when the authentication token is not exactly which is expected from the plugin
1 parent d9f0051 commit 0646c4a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ private GHMyself loadMyself(@NonNull String token) throws IOException {
504504
// Also stick into usersByIdCache (to have latest copy)
505505
String username = ghMyself.getLogin();
506506
usersByIdCache.put(username, new GithubUser(ghMyself));
507+
} else {
508+
// force creation of the gh variable, esp. in case of impersonation
509+
getGitHub();
507510
}
508511
} catch (IOException e) {
509512
LOGGER.log(Level.INFO, e.getMessage(), e);

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,15 @@ public int hashCode() {
753753
@Override
754754
public GroupDetails loadGroupByGroupname(String groupName)
755755
throws UsernameNotFoundException, DataAccessException {
756-
GithubAuthenticationToken authToken = (GithubAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
757-
758-
if(authToken == null)
756+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
757+
if (authentication == null) {
759758
throw new UsernameNotFoundException("No known group: " + groupName);
759+
}
760+
if (!(authentication instanceof GithubAuthenticationToken)) {
761+
throw new UserMayOrMayNotExistException("The received token is not a GitHub one");
762+
}
763+
764+
GithubAuthenticationToken authToken = (GithubAuthenticationToken) authentication;
760765

761766
try {
762767
int idx = groupName.indexOf(GithubOAuthGroupDetails.ORG_TEAM_SEPARATOR);

0 commit comments

Comments
 (0)