From e0c3480fcbd051668ad42a446d5eb7a944770fd7 Mon Sep 17 00:00:00 2001 From: Andreas Nygard Date: Sat, 4 Nov 2023 21:42:15 +1100 Subject: [PATCH] Revert "[JENKINS-72268] Missing permission due to desync with cache (#256)" This reverts commit 0646c4a0a962d1dd3f6a68349e643fbd70bea945. --- .../jenkinsci/plugins/GithubAuthenticationToken.java | 3 --- .../org/jenkinsci/plugins/GithubSecurityRealm.java | 11 +++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/GithubAuthenticationToken.java b/src/main/java/org/jenkinsci/plugins/GithubAuthenticationToken.java index 28462fe4..0a997f45 100644 --- a/src/main/java/org/jenkinsci/plugins/GithubAuthenticationToken.java +++ b/src/main/java/org/jenkinsci/plugins/GithubAuthenticationToken.java @@ -504,9 +504,6 @@ private GHMyself loadMyself(@NonNull String token) throws IOException { // Also stick into usersByIdCache (to have latest copy) String username = ghMyself.getLogin(); usersByIdCache.put(username, new GithubUser(ghMyself)); - } else { - // force creation of the gh variable, esp. in case of impersonation - getGitHub(); } } catch (IOException e) { LOGGER.log(Level.INFO, e.getMessage(), e); diff --git a/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java b/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java index a55abed5..803fd1c5 100644 --- a/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java +++ b/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java @@ -753,15 +753,10 @@ public int hashCode() { @Override public GroupDetails loadGroupByGroupname(String groupName) throws UsernameNotFoundException, DataAccessException { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) { - throw new UsernameNotFoundException("No known group: " + groupName); - } - if (!(authentication instanceof GithubAuthenticationToken)) { - throw new UserMayOrMayNotExistException("The received token is not a GitHub one"); - } + GithubAuthenticationToken authToken = (GithubAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); - GithubAuthenticationToken authToken = (GithubAuthenticationToken) authentication; + if(authToken == null) + throw new UsernameNotFoundException("No known group: " + groupName); try { int idx = groupName.indexOf(GithubOAuthGroupDetails.ORG_TEAM_SEPARATOR);