Java Code Examples for com.netflix.spinnaker.fiat.model.resources.Permissions#EMPTY

The following examples show how to use com.netflix.spinnaker.fiat.model.resources.Permissions#EMPTY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationResourcePermissionSource.java    From fiat with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public Permissions getPermissions(@Nonnull Application resource) {
  Permissions storedPermissions = resource.getPermissions();
  if (storedPermissions == null || !storedPermissions.isRestricted()) {
    return Permissions.EMPTY;
  }

  Map<Authorization, List<String>> authorizations =
      Arrays.stream(Authorization.values()).collect(toMap(identity(), storedPermissions::get));

  // CREATE permissions are not allowed on the resource level.
  authorizations.remove(Authorization.CREATE);

  return Permissions.Builder.factory(authorizations).build();
}
 
Example 2
Source File: ResourcePrefixPermissionSource.java    From fiat with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Permissions getPermissions(@Nonnull T resource) {

  List<PrefixEntry<T>> matchingPrefixes =
      prefixes.stream().filter(prefix -> prefix.contains(resource)).collect(Collectors.toList());

  if (matchingPrefixes.isEmpty()) {
    return Permissions.EMPTY;
  }

  switch (resolutionStrategy) {
    case AGGREGATE:
      return getAggregatePermissions(matchingPrefixes);
    case MOST_SPECIFIC:
      return getMostSpecificPermissions(matchingPrefixes);
    default:
      throw new IllegalStateException(
          "Unrecognized Resolution Stratgey " + resolutionStrategy.name());
  }
}