Skip to content

Commit

Permalink
Merge pull request #426 from jtnord/crumb-refresh
Browse files Browse the repository at this point in the history
Resuse the original user principal to avoid crumb issues.
  • Loading branch information
jtnord authored Oct 24, 2024
2 parents 636339f + 0fdc550 commit b5d5c2a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,21 @@ private boolean refreshExpiredToken(
HttpServletResponse.SC_UNAUTHORIZED, "User name was not the same after refresh request");
return false;
}
// the username may have changed case during a call, but still be the same user (as we have checked the
// idStrategy)
// we need to keep using exactly the same principal otherwise there is a potential for crumbs not to match.
// whilst we could do some normalization of the username, just use the original (expected) username
// see https://github.com/jenkinsci/oic-auth-plugin/issues/411
if (LOGGER.isLoggable(Level.FINE)) {

Check warning on line 1436 in src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1436 is only partially covered, one branch is missing
Authentication a = SecurityContextHolder.getContext().getAuthentication();
User u = User.get2(a);
LOGGER.log(
Level.FINE,
"Token refresh. Current Authentitcation principal: " + a.getName() + " user id:"
+ (u == null ? "null user" : u.getId()) + " newly retreived username would have been: "

Check warning on line 1442 in src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1437-1442 are not covered by tests
+ username);
}
username = expectedUsername;

if (failedCheckOfTokenField(idToken)) {
throw new FailedCheckOfTokenException(client.getConfiguration().findLogoutUrl());
Expand Down

0 comments on commit b5d5c2a

Please sign in to comment.