Skip to content

Commit

Permalink
Fix duplicate keymanager name issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chamilaadhi committed Jan 10, 2025
1 parent bd27617 commit 8a25a77
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class OrganizationKeyManagerDto {

private Map<String, KeyManagerDto> keyManagerMap = new LinkedHashMap<>();
private Map<String, List<String>> issuerNameMap = new HashMap<>();
private Map<String, Set<String>> issuerNameMap = new HashMap<>();

public Map<String, KeyManagerDto> getKeyManagerMap() {

Expand All @@ -53,7 +55,7 @@ public void putKeyManagerDto(KeyManagerDto keyManagerDto) {
} else {
keyManagerMap.put(keyManagerDto.getName(), keyManagerDto);
}
issuerNameMap.computeIfAbsent(keyManagerDto.getIssuer(), k -> new ArrayList<>()).add(keyManagerDto.getName());
issuerNameMap.computeIfAbsent(keyManagerDto.getIssuer(), k -> new HashSet<>()).add(keyManagerDto.getName());

}

Expand All @@ -71,9 +73,10 @@ public void removeKeyManagerDtoByName(String name) {

public JWTValidator getJWTValidatorByIssuer(String issuer) {

List<String> keyManagerNames = issuerNameMap.get(issuer);
Set<String> keyManagerNames = issuerNameMap.get(issuer);
if (keyManagerNames != null && !keyManagerNames.isEmpty()) {
KeyManagerDto keyManagerDto = keyManagerMap.get(keyManagerNames.get(0));
String keyManagerName = keyManagerNames.iterator().next();
KeyManagerDto keyManagerDto = keyManagerMap.get(keyManagerName);
if (keyManagerDto != null) {
return keyManagerDto.getJwtValidator();
}
Expand All @@ -84,7 +87,7 @@ public JWTValidator getJWTValidatorByIssuer(String issuer) {
public List<KeyManagerDto> getKeyManagerDtoByIssuer(String issuer) {

List<KeyManagerDto> dtoList = new ArrayList<KeyManagerDto>();
List<String> keyManagerNames = issuerNameMap.get(issuer);
Set<String> keyManagerNames = issuerNameMap.get(issuer);
if (keyManagerNames != null && !keyManagerNames.isEmpty()) {
for (String keyManagerName : keyManagerNames) {
dtoList.add(keyManagerMap.get(keyManagerName));
Expand Down

0 comments on commit 8a25a77

Please sign in to comment.