Skip to content

Commit

Permalink
Fix an exception when the authentication token is not exactly which i…
Browse files Browse the repository at this point in the history
…s expected from the plugin
  • Loading branch information
Wadeck committed Nov 1, 2023
1 parent 818ad9b commit b34794c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,15 @@ public int hashCode() {
@Override
public GroupDetails loadGroupByGroupname(String groupName)
throws UsernameNotFoundException, DataAccessException {
GithubAuthenticationToken authToken = (GithubAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

if(authToken == null)
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) authentication;

Check warning on line 764 in src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 756-764 are not covered by tests

try {
int idx = groupName.indexOf(GithubOAuthGroupDetails.ORG_TEAM_SEPARATOR);
Expand Down

0 comments on commit b34794c

Please sign in to comment.