simonbence commented on code in PR #9115:
URL: https://github.com/apache/nifi/pull/9115#discussion_r1727385859
##########
nifi-commons/nifi-security-identity/src/main/java/org/apache/nifi/authorization/util/IdentityMappingUtil.java:
##########
@@ -140,8 +141,12 @@ public int compare(IdentityMapping m1, IdentityMapping m2)
{
* @return the mapped identity, or the same identity if no mappings matched
*/
public static String mapIdentity(final String identity,
List<IdentityMapping> mappings) {
- for (IdentityMapping mapping : mappings) {
- Matcher m = mapping.getPattern().matcher(identity);
+ final List<String> keys = mappings.stream().map(m ->
m.getKey()).collect(Collectors.toList());
+ Collections.sort(keys);
+
+ for (final String key : keys) {
+ final IdentityMapping mapping = mappings.stream().filter(m ->
m.getKey().equals(key)).findFirst().orElseThrow();
Review Comment:
I did not think of this, but a good idea. For the whole picture, I was
hesitant with the change because while the `TreeMap` avoids the constructs
above (which in this case as we are not talking about bigger data structures,
might not be have as much affect on performance, using an `entrySet` [1], where
the contract would allow too much freedom on the order of the elements (even if
the implementation provides further restrictions) seems like a questionable
move forward. In the end, after weighting the implications, I decided to go
with the `TreeMap`. I will commit the changes soonish.
[1] using the `keySet` would result the same, and the `forEach` looks to be
a bit convoluted here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]