// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Account.java
// @Component
// @Data
// @EqualsAndHashCode(callSuper = false)
// public class Account extends BaseAccessControlled<Account> implements Viewable {
//   final ResourceType resourceType = ResourceType.ACCOUNT;
// 
//   private String name;
//   private String cloudProvider;
//   private Permissions permissions = Permissions.EMPTY;
// 
//   @JsonIgnore
//   @Override
//   public View getView(Set<Role> userRoles, boolean isAdmin) {
//     return new View(this, userRoles, isAdmin);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends BaseView implements Authorizable {
//     String name;
//     Set<Authorization> authorizations;
// 
//     public View(Account account, Set<Role> userRoles, boolean isAdmin) {
//       this.name = account.name;
//       if (isAdmin) {
//         this.authorizations = Authorization.ALL;
//       } else {
//         this.authorizations = account.permissions.getAuthorizations(userRoles);
//       }
//     }
//   }
// }
// 
// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Application.java
// @Component
// @Data
// @EqualsAndHashCode(callSuper = false)
// public class Application extends BaseAccessControlled<Application> implements Viewable {
//   final ResourceType resourceType = ResourceType.APPLICATION;
// 
//   private String name;
//   private Permissions permissions = Permissions.EMPTY;
// 
//   private Map<String, Object> details = new HashMap<>();
// 
//   @JsonAnySetter
//   public void setDetails(String name, Object value) {
//     this.details.put(name, value);
//   }
// 
//   @JsonIgnore
//   public View getView(Set<Role> userRoles, boolean isAdmin) {
//     return new View(this, userRoles, isAdmin);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends BaseView implements Authorizable {
//     String name;
//     Set<Authorization> authorizations;
// 
//     public View(Application application, Set<Role> userRoles, boolean isAdmin) {
//       this.name = application.name;
//       if (isAdmin) {
//         this.authorizations = Authorization.ALL;
//       } else {
//         this.authorizations = application.permissions.getAuthorizations(userRoles);
//       }
//     }
//   }
// }
// 
// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/BuildService.java
// @Component
// @Data
// @EqualsAndHashCode(callSuper = false)
// public class BuildService implements Resource.AccessControlled, Viewable {
// 
//   private final ResourceType resourceType = ResourceType.BUILD_SERVICE;
// 
//   private String name;
//   private Permissions permissions = Permissions.EMPTY;
// 
//   @Override
//   public BaseView getView(Set<Role> userRoles, boolean isAdmin) {
//     return new View(this, userRoles, isAdmin);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends Viewable.BaseView implements Authorizable {
// 
//     private String name;
//     Set<Authorization> authorizations;
// 
//     public View(BuildService buildService, Set<Role> userRoles, boolean isAdmin) {
//       this.name = buildService.name;
//       if (isAdmin) {
//         this.authorizations = Authorization.ALL;
//       } else {
//         this.authorizations = buildService.permissions.getAuthorizations(userRoles);
//       }
//     }
//   }
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.fiat.model.resources.Account;
import com.netflix.spinnaker.fiat.model.resources.Application;
import com.netflix.spinnaker.fiat.model.resources.BuildService;
import com.netflix.spinnaker.fiat.providers.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
      matchIfMissing = true)
  public ResourcePermissionProvider<Account> defaultAccountPermissionProvider(
      ResourcePermissionSource<Account> accountResourcePermissionSource) {
    return new DefaultResourcePermissionProvider<>(accountResourcePermissionSource);
  }

  @Bean
  @ConditionalOnProperty(
      value = "auth.permissions.source.application.resource.enabled",
      matchIfMissing = true)
  @Order(Ordered.HIGHEST_PRECEDENCE + 100)
  ResourcePermissionSource<Application> applicationResourcePermissionSource() {
    return new ApplicationResourcePermissionSource();
  }

  @Bean
  @ConditionalOnProperty(
      value = "auth.permissions.provider.application",
      havingValue = "default",
      matchIfMissing = true)
  public ResourcePermissionProvider<Application> defaultApplicationPermissionProvider(
      ResourcePermissionSource<Application> applicationResourcePermissionSource) {
    return new DefaultResourcePermissionProvider<>(applicationResourcePermissionSource);
  }

  @Bean
  @ConditionalOnProperty(
      value = "auth.permissions.source.build-service.resource.enabled",
      matchIfMissing = true)
  @Order(Ordered.HIGHEST_PRECEDENCE + 100)
// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Account.java
// @Component
// @Data
// @EqualsAndHashCode(callSuper = false)
// public class Account extends BaseAccessControlled<Account> implements Viewable {
//   final ResourceType resourceType = ResourceType.ACCOUNT;
// 
//   private String name;
//   private String cloudProvider;
//   private Permissions permissions = Permissions.EMPTY;
// 
//   @JsonIgnore
//   @Override
//   public View getView(Set<Role> userRoles, boolean isAdmin) {
//     return new View(this, userRoles, isAdmin);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends BaseView implements Authorizable {
//     String name;
//     Set<Authorization> authorizations;
// 
//     public View(Account account, Set<Role> userRoles, boolean isAdmin) {
//       this.name = account.name;
//       if (isAdmin) {
//         this.authorizations = Authorization.ALL;
//       } else {
//         this.authorizations = account.permissions.getAuthorizations(userRoles);
//       }
//     }
//   }
// }
// 
// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Application.java
// @Component
// @Data
// @EqualsAndHashCode(callSuper = false)
// public class Application extends BaseAccessControlled<Application> implements Viewable {
//   final ResourceType resourceType = ResourceType.APPLICATION;
// 
//   private String name;
//   private Permissions permissions = Permissions.EMPTY;
// 
//   private Map<String, Object> details = new HashMap<>();
// 
//   @JsonAnySetter
//   public void setDetails(String name, Object value) {
//     this.details.put(name, value);
//   }
// 
//   @JsonIgnore
//   public View getView(Set<Role> userRoles, boolean isAdmin) {
//     return new View(this, userRoles, isAdmin);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends BaseView implements Authorizable {
//     String name;
//     Set<Authorization> authorizations;
// 
//     public View(Application application, Set<Role> userRoles, boolean isAdmin) {
//       this.name = application.name;
//       if (isAdmin) {
//         this.authorizations = Authorization.ALL;
//       } else {
//         this.authorizations = application.permissions.getAuthorizations(userRoles);
//       }
//     }
//   }
// }
// 
// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/BuildService.java
// @Component
// @Data
// @EqualsAndHashCode(callSuper = false)
// public class BuildService implements Resource.AccessControlled, Viewable {
// 
//   private final ResourceType resourceType = ResourceType.BUILD_SERVICE;
// 
//   private String name;
//   private Permissions permissions = Permissions.EMPTY;
// 
//   @Override
//   public BaseView getView(Set<Role> userRoles, boolean isAdmin) {
//     return new View(this, userRoles, isAdmin);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends Viewable.BaseView implements Authorizable {
// 
//     private String name;
//     Set<Authorization> authorizations;
// 
//     public View(BuildService buildService, Set<Role> userRoles, boolean isAdmin) {
//       this.name = buildService.name;
//       if (isAdmin) {
//         this.authorizations = Authorization.ALL;
//       } else {
//         this.authorizations = buildService.permissions.getAuthorizations(userRoles);
//       }
//     }
//   }
// }


// Path: fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/DefaultResourcePermissionConfig.java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.fiat.model.resources.Account;
import com.netflix.spinnaker.fiat.model.resources.Application;
import com.netflix.spinnaker.fiat.model.resources.BuildService;
import com.netflix.spinnaker.fiat.providers.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

      matchIfMissing = true)
  public ResourcePermissionProvider<Account> defaultAccountPermissionProvider(
      ResourcePermissionSource<Account> accountResourcePermissionSource) {
    return new DefaultResourcePermissionProvider<>(accountResourcePermissionSource);
  }

  @Bean
  @ConditionalOnProperty(
      value = "auth.permissions.source.application.resource.enabled",
      matchIfMissing = true)
  @Order(Ordered.HIGHEST_PRECEDENCE + 100)
  ResourcePermissionSource<Application> applicationResourcePermissionSource() {
    return new ApplicationResourcePermissionSource();
  }

  @Bean
  @ConditionalOnProperty(
      value = "auth.permissions.provider.application",
      havingValue = "default",
      matchIfMissing = true)
  public ResourcePermissionProvider<Application> defaultApplicationPermissionProvider(
      ResourcePermissionSource<Application> applicationResourcePermissionSource) {
    return new DefaultResourcePermissionProvider<>(applicationResourcePermissionSource);
  }

  @Bean
  @ConditionalOnProperty(
      value = "auth.permissions.source.build-service.resource.enabled",
      matchIfMissing = true)
  @Order(Ordered.HIGHEST_PRECEDENCE + 100)
  ResourcePermissionSource<BuildService> buildServiceResourcePermissionSource() {