// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Role.java
// @Component
// @Data
// @EqualsAndHashCode(of = "name")
// @NoArgsConstructor
// public class Role implements Resource, Viewable {
// 
//   private final ResourceType resourceType = ResourceType.ROLE;
//   private String name;
// 
//   public enum Source {
//     EXTERNAL,
//     FILE,
//     GOOGLE_GROUPS,
//     GITHUB_TEAMS,
//     LDAP
//   }
// 
//   private Source source;
// 
//   public Role(String name) {
//     this.setName(name);
//   }
// 
//   public Role setName(@Nonnull String name) {
//     if (!StringUtils.hasText(name)) {
//       throw new IllegalArgumentException("name cannot be empty");
//     }
//     this.name = name.toLowerCase();
//     return this;
//   }
// 
//   @JsonIgnore
//   @Override
//   public View getView(Set<Role> ignored, boolean isAdmin) {
//     return new View(this);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends BaseView {
//     private String name;
//     private Source source;
// 
//     public View(Role role) {
//       this.name = role.name;
//       this.source = role.getSource();
//     }
//   }
// }
// 
// Path: fiat-roles/src/main/java/com/netflix/spinnaker/fiat/permissions/ExternalUser.java
// @Data
// public class ExternalUser {
//   private String id;
//   private List<Role> externalRoles = new ArrayList<>();
// }
// 
// Path: fiat-roles/src/main/java/com/netflix/spinnaker/fiat/roles/UserRolesProvider.java
// public interface UserRolesProvider {
// 
//   default List<Role> loadUnrestrictedRoles() {
//     return new ArrayList<>();
//   }
// 
//   /**
//    * Load the roles assigned to the {@link com.netflix.spinnaker.fiat.permissions.ExternalUser
//    * user}.
//    *
//    * @param user to load roles for
//    * @return Roles assigned to the {@link com.netflix.spinnaker.fiat.permissions.ExternalUser user}
//    *     with the given id.
//    */
//   List<Role> loadRoles(ExternalUser user);
// 
//   /**
//    * Load the roles assigned to each {@link com.netflix.spinnaker.fiat.permissions.ExternalUser
//    * user's} id in users.
//    *
//    * @param users to load roles for
//    * @return Map whose keys are the {@link com.netflix.spinnaker.fiat.permissions.ExternalUser
//    *     user's} id and values are their assigned roles.
//    */
//   Map<String, Collection<Role>> multiLoadRoles(Collection<ExternalUser> users);
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.netflix.spinnaker.fiat.model.resources.Role;
import com.netflix.spinnaker.fiat.permissions.ExternalUser;
import com.netflix.spinnaker.fiat.roles.UserRolesProvider;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.*;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
/*
 * Copyright 2017 Google, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.fiat.roles.file;


@Slf4j
@Component
@ConditionalOnProperty(value = "auth.group-membership.service", havingValue = "file")
// Path: fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Role.java
// @Component
// @Data
// @EqualsAndHashCode(of = "name")
// @NoArgsConstructor
// public class Role implements Resource, Viewable {
// 
//   private final ResourceType resourceType = ResourceType.ROLE;
//   private String name;
// 
//   public enum Source {
//     EXTERNAL,
//     FILE,
//     GOOGLE_GROUPS,
//     GITHUB_TEAMS,
//     LDAP
//   }
// 
//   private Source source;
// 
//   public Role(String name) {
//     this.setName(name);
//   }
// 
//   public Role setName(@Nonnull String name) {
//     if (!StringUtils.hasText(name)) {
//       throw new IllegalArgumentException("name cannot be empty");
//     }
//     this.name = name.toLowerCase();
//     return this;
//   }
// 
//   @JsonIgnore
//   @Override
//   public View getView(Set<Role> ignored, boolean isAdmin) {
//     return new View(this);
//   }
// 
//   @Data
//   @EqualsAndHashCode(callSuper = false)
//   @NoArgsConstructor
//   public static class View extends BaseView {
//     private String name;
//     private Source source;
// 
//     public View(Role role) {
//       this.name = role.name;
//       this.source = role.getSource();
//     }
//   }
// }
// 
// Path: fiat-roles/src/main/java/com/netflix/spinnaker/fiat/permissions/ExternalUser.java
// @Data
// public class ExternalUser {
//   private String id;
//   private List<Role> externalRoles = new ArrayList<>();
// }
// 
// Path: fiat-roles/src/main/java/com/netflix/spinnaker/fiat/roles/UserRolesProvider.java
// public interface UserRolesProvider {
// 
//   default List<Role> loadUnrestrictedRoles() {
//     return new ArrayList<>();
//   }
// 
//   /**
//    * Load the roles assigned to the {@link com.netflix.spinnaker.fiat.permissions.ExternalUser
//    * user}.
//    *
//    * @param user to load roles for
//    * @return Roles assigned to the {@link com.netflix.spinnaker.fiat.permissions.ExternalUser user}
//    *     with the given id.
//    */
//   List<Role> loadRoles(ExternalUser user);
// 
//   /**
//    * Load the roles assigned to each {@link com.netflix.spinnaker.fiat.permissions.ExternalUser
//    * user's} id in users.
//    *
//    * @param users to load roles for
//    * @return Map whose keys are the {@link com.netflix.spinnaker.fiat.permissions.ExternalUser
//    *     user's} id and values are their assigned roles.
//    */
//   Map<String, Collection<Role>> multiLoadRoles(Collection<ExternalUser> users);
// }


// Path: fiat-file/src/main/java/com/netflix/spinnaker/fiat/roles/file/FileBasedUserRolesProvider.java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.netflix.spinnaker.fiat.model.resources.Role;
import com.netflix.spinnaker.fiat.permissions.ExternalUser;
import com.netflix.spinnaker.fiat.roles.UserRolesProvider;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.*;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/*
 * Copyright 2017 Google, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.fiat.roles.file;


@Slf4j
@Component
@ConditionalOnProperty(value = "auth.group-membership.service", havingValue = "file")
public class FileBasedUserRolesProvider implements UserRolesProvider {