Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 3083: check user_name claim type #3084

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ public AuthenticationData getExternalAuthenticationDetails(Authentication authen

String userNameAttributePrefix = (String) attributeMappings.get(USER_NAME_ATTRIBUTE_NAME);
String username;
if (StringUtils.hasText(userNameAttributePrefix)) {
username = (String) claims.get(userNameAttributePrefix);
if (hasText(userNameAttributePrefix)) {
username = getMappedClaim(userNameAttributePrefix, USER_NAME_ATTRIBUTE_NAME, claims);
logger.debug(String.format("Extracted username for claim: %s and username is: %s", userNameAttributePrefix, username));
} else {
username = (String) claims.get(SUB);
username = getMappedClaim(null, SUB, claims);
logger.debug(String.format("Extracted username for claim: %s and username is: %s", SUB, username));
}
if (!hasText(username)) {
Expand Down Expand Up @@ -424,7 +424,7 @@ private String getMappedClaim(String externalName, String internalName, Map<Stri
return (String) claimObject;
}
if (claimObject instanceof Collection) {
Set<String> entry = ((Collection<?>) claimObject).stream().map(String.class::cast).collect(Collectors.toSet());
Set<String> entry = ((Collection<?>) claimObject).stream().filter(String.class::isInstance).map(String.class::cast).collect(Collectors.toSet());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will collection items always going to be a string? Should we consider handle it in more generic way:

Set entry = ((Collection<?>) claimObject).stream()
.map(claim -> String.valueOf(claim))
.collect(Collectors.toSet());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not wanted to have such a generic approach, but simple check if the entries inside of the token are strings. With your approach we allow all but then we are incompatible with now. I mean if claims are type of Boolean or int we would allow them now. But that is not wanted

if (entry.size() == 1 ) {
return entry.stream().collect(Collectors.toList()).get(0);
} else if (entry.isEmpty()) {
Expand Down
Loading