Skip to content

Commit

Permalink
Allow duplicated keys in the HardcodedKeyLocator (keycloak#25069)
Browse files Browse the repository at this point in the history
Closes keycloak#24961

Signed-off-by: rmartinc <[email protected]>
  • Loading branch information
rmartinc authored Nov 29, 2023
1 parent ad2be74 commit 2530cb3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public HardcodedKeyLocator(Collection<? extends Key> keys) {
Objects.requireNonNull(keys, "Keys must not be null");
this.byName = Collections.emptyMap();
this.byKey = Collections.unmodifiableMap(keys.stream().collect(
Collectors.toMap(k -> new KeyHash(k), k -> k)));
Collectors.toMap(k -> new KeyHash(k), k -> k, (k1, k2) -> k1)));
}

public HardcodedKeyLocator(Map<String, ? extends Key> keys) {
Objects.requireNonNull(keys, "Keys must not be null");
this.byName = Collections.unmodifiableMap(keys);
this.byKey = Collections.unmodifiableMap(keys.values().stream().collect(
Collectors.toMap(k -> new KeyHash(k), k -> k)));
Collectors.toMap(k -> new KeyHash(k), k -> k, (k1, k2) -> k1)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,13 @@ public void testKeyNameWithOneCertificatesWithoutName() throws Exception {
Assert.assertNotNull(found);
Assert.assertEquals(cert1.getPublicKey(), found);
}

@Test
public void testDuplicateKey() throws Exception {
KeyLocator locator = createLocatorWithoutName(cert1, cert1);
KeyInfo info = XMLSignatureUtil.createKeyInfo(null, null, cert1);
Key found = locator.getKey(info);
Assert.assertNotNull(found);
Assert.assertEquals(cert1.getPublicKey(), found);
}
}

0 comments on commit 2530cb3

Please sign in to comment.