AppIdMapping.java

  1. package no.nav.data.common.security;

  2. import com.fasterxml.jackson.core.type.TypeReference;
  3. import lombok.Data;
  4. import no.nav.data.common.utils.Constants;
  5. import no.nav.data.common.utils.JsonUtils;

  6. import java.util.Collection;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;

  10. public class AppIdMapping {

  11.     public static final TypeReference<List<AuthApps>> AUTH_APP_LIST = new TypeReference<>() {
  12.     };

  13.     private static final Map<String, String> appIdAppNameMap = new HashMap<>();

  14.     public AppIdMapping(String mappings, String teamCatAppId) {
  15.         appIdAppNameMap.put(teamCatAppId, Constants.APP_ID);
  16.         List<AuthApps> authApps = JsonUtils.readValue(mappings, AUTH_APP_LIST);
  17.         authApps.forEach(app -> appIdAppNameMap.put(app.clientId, app.name));
  18.     }

  19.     public static String getAppNameForAppId(String appId) {
  20.         return appId == null ? null : appIdAppNameMap.getOrDefault(appId, "not-found");
  21.     }

  22.     public Collection<String> getIds() {
  23.         return appIdAppNameMap.keySet();
  24.     }

  25.     @Data
  26.     static class AuthApps {

  27.         private String name;
  28.         private String clientId;
  29.     }
  30. }