SecurityProperties.java

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

  2. import lombok.Data;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.springframework.boot.context.properties.ConfigurationProperties;
  5. import org.springframework.context.annotation.Configuration;

  6. import java.util.List;

  7. import static no.nav.data.common.utils.StreamUtils.safeStream;
  8. import static no.nav.data.common.utils.StreamUtils.tryFind;

  9. @Data
  10. @Configuration
  11. @ConfigurationProperties(prefix = "team-catalog.security")
  12. public class SecurityProperties {

  13.     private boolean enabled = true;
  14.     private String encKey = "";

  15.     private List<String> adminGroups;
  16.     private List<String> redirectUris;
  17.     private String env;
  18.     private List<String> devEmailAllowList;

  19.     public boolean isValidRedirectUri(String uri) {
  20.         return uri == null || safeStream(redirectUris).anyMatch(origin -> StringUtils.startsWithIgnoreCase(uri, origin));
  21.     }

  22.     public boolean isDev() {
  23.         return env.startsWith("dev");
  24.     }

  25.     public String findBaseUrl() {
  26.         return tryFind(getRedirectUris(), uri -> uri.contains("teamkatalog.nav.no")).orElse(getRedirectUris().get(0));
  27.     }

  28.     public boolean isDevEmailAllowed(String email) {
  29.         return devEmailAllowList.stream().anyMatch(email::equalsIgnoreCase);
  30.     }
  31. }