com.netflix.spinnaker.fiat.model.resources.Permissions Java Examples

The following examples show how to use com.netflix.spinnaker.fiat.model.resources.Permissions. 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: ChaosMonkeyEventListener.java    From front50 with Apache License 2.0 6 votes vote down vote up
protected void applyNewPermissions(
    Application.Permission updatedPermission, boolean chaosMonkeyEnabled) {
  Permissions permissions = updatedPermission.getPermissions();

  Map<Authorization, List<String>> unpackedPermissions = permissions.unpack();
  unpackedPermissions.forEach(
      (key, value) -> {
        List<String> roles = new ArrayList<>(value);
        if (key == Authorization.READ || key == Authorization.WRITE) {
          if (chaosMonkeyEnabled && shouldAdd(updatedPermission, key)) {
            roles.add(properties.getUserRole());
          } else if (chaosMonkeyEnabled && shouldRemove(updatedPermission, key)) {
            roles.removeAll(Collections.singletonList(properties.getUserRole()));
          } else if (!chaosMonkeyEnabled) {
            roles.removeAll(Collections.singletonList(properties.getUserRole()));
          }
        }
        unpackedPermissions.put(key, roles);
      });
  Permissions newPermissions = Permissions.factory(unpackedPermissions);

  updatedPermission.setPermissions(newPermissions);
}
 
Example #2
Source File: Application.java    From front50 with Apache License 2.0 6 votes vote down vote up
@JsonSetter
public void setRequiredGroupMembership(List<String> requiredGroupMembership) {
  log.warn(
      "Required group membership settings detected in application {} "
          + "Please update to `permissions` format.",
      StructuredArguments.value("application", name));

  if (!permissions.isRestricted()) { // Do not overwrite permissions if it contains values
    final Permissions.Builder b = new Permissions.Builder();
    requiredGroupMembership.forEach(
        it -> {
          b.add(Authorization.READ, it.trim().toLowerCase());
          b.add(Authorization.WRITE, it.trim().toLowerCase());
        });
    permissions = b.build();
  }
}
 
Example #3
Source File: AbstractConfigCommand.java    From halyard with Apache License 2.0 6 votes vote down vote up
protected static void updatePermissions(
    Permissions.Builder permissions,
    List<String> readPermissions,
    String addReadPermission,
    String removeReadPermission,
    List<String> writePermissions,
    String addWritePermission,
    String removeWritePermission) {
  List<String> resolvedReadPermissions =
      updateStringList(
          permissions.get(Authorization.READ),
          readPermissions,
          addReadPermission,
          removeReadPermission);
  List<String> resolvedWritePermissions =
      updateStringList(
          permissions.get(Authorization.WRITE),
          writePermissions,
          addWritePermission,
          removeWritePermission);

  permissions.clear();
  permissions.add(Authorization.READ, resolvedReadPermissions);
  permissions.add(Authorization.WRITE, resolvedWritePermissions);
}
 
Example #4
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 #5
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());
  }
}
 
Example #6
Source File: ResourcePrefixPermissionSource.java    From fiat with Apache License 2.0 5 votes vote down vote up
private Permissions getMostSpecificPermissions(List<PrefixEntry<T>> matchingPrefixes) {
  return matchingPrefixes.stream()
      .min(
          (p1, p2) -> {
            if (p1.isFullApplicationName()) {
              return -1;
            }
            return p2.getPrefix().length() - p1.getPrefix().length();
          })
      .get()
      .getPermissions();
}
 
Example #7
Source File: DefaultApplicationResourceProvider.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Override
protected Set<Application> loadAll() throws ProviderException {
  try {
    List<Application> front50Applications = front50Service.getAllApplications();
    List<Application> clouddriverApplications = clouddriverService.getApplications();

    // Stream front50 first so that if there's a name collision, we'll keep that one instead of
    // the clouddriver application (since front50 might have permissions stored on it, but the
    // clouddriver version definitely won't)
    List<Application> applications =
        Streams.concat(front50Applications.stream(), clouddriverApplications.stream())
            .filter(distinctByKey(a -> a.getName().toUpperCase()))
            // Collect to a list instead of set since we're about to modify the applications
            .collect(toImmutableList());

    applications.forEach(
        application -> {
          Permissions permissions = permissionProvider.getPermissions(application);

          // Check to see if we need to fallback permissions to the configured fallback
          application.setPermissions(
              executeFallbackPermissionsResolver.shouldResolve(permissions)
                  ? executeFallbackPermissionsResolver.resolve(permissions)
                  : permissions);
        });

    if (allowAccessToUnknownApplications) {
      // no need to include applications w/o explicit permissions if we're allowing access to
      // unknown applications by default
      return applications.stream()
          .filter(a -> a.getPermissions().isRestricted())
          .collect(toImmutableSet());
    } else {
      return ImmutableSet.copyOf(applications);
    }
  } catch (RuntimeException e) {
    throw new ProviderException(this.getClass(), e);
  }
}
 
Example #8
Source File: AccessControlledResourcePermissionSource.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Permissions getPermissions(@Nonnull T resource) {
  return Optional.ofNullable(resource)
      .map(Resource.AccessControlled::getPermissions)
      .filter(Permissions::isRestricted)
      .orElse(Permissions.EMPTY);
}
 
Example #9
Source File: ChaosMonkeyApplicationResourcePermissionSource.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Permissions getPermissions(@Nonnull Application application) {
  Permissions.Builder builder = new Permissions.Builder();
  Permissions permissions = application.getPermissions();

  if (permissions.isRestricted()) {
    if (isChaosMonkeyEnabled(application)) {
      builder.add(Authorization.READ, roles).add(Authorization.WRITE, roles).build();
    }
  }

  return builder.build();
}
 
Example #10
Source File: AggregatingResourcePermissionProvider.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Permissions getPermissions(@Nonnull T resource) {
  Permissions.Builder builder = new Permissions.Builder();
  for (ResourcePermissionSource<T> source : resourcePermissionSources) {
    Permissions permissions = source.getPermissions(resource);
    if (permissions.isRestricted()) {
      for (Authorization auth : Authorization.values()) {
        builder.add(auth, permissions.get(auth));
      }
    }
  }

  return builder.build();
}
 
Example #11
Source File: ResourcePrefixPermissionSource.java    From fiat with Apache License 2.0 5 votes vote down vote up
private Permissions getAggregatePermissions(List<PrefixEntry<T>> matchingPrefixes) {
  Permissions.Builder builder = new Permissions.Builder();
  for (PrefixEntry<T> prefix : matchingPrefixes) {
    Permissions permissions = prefix.getPermissions();
    if (permissions.isRestricted()) {
      for (Authorization auth : Authorization.values()) {
        builder.add(auth, permissions.get(auth));
      }
    }
  }

  return builder.build();
}
 
Example #12
Source File: DefaultFallbackPermissionsResolver.java    From fiat with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldResolve(@Nonnull Permissions permissions) {
  return permissions.isRestricted() && permissions.get(fallbackFrom).isEmpty();
}
 
Example #13
Source File: ResourcePrefixPermissionSource.java    From fiat with Apache License 2.0 4 votes vote down vote up
public PrefixEntry setPermissions(Map<Authorization, List<String>> permissions) {
  this.permissions = Permissions.factory(permissions);
  return this;
}
 
Example #14
Source File: DefaultResourcePermissionProvider.java    From fiat with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public Permissions getPermissions(@Nonnull T resource) {
  return resourcePermissionSource.getPermissions(resource);
}
 
Example #15
Source File: Application.java    From front50 with Apache License 2.0 4 votes vote down vote up
public Permissions getPermissions() {
  return permissions;
}
 
Example #16
Source File: Application.java    From front50 with Apache License 2.0 4 votes vote down vote up
public void setPermissions(Permissions permissions) {
  this.permissions = permissions;
}
 
Example #17
Source File: DefaultFallbackPermissionsResolver.java    From fiat with Apache License 2.0 4 votes vote down vote up
@Override
public Permissions resolve(@Nonnull Permissions permissions) {
  Map<Authorization, List<String>> authorizations = permissions.unpack();
  authorizations.put(fallbackFrom, authorizations.get(fallbackTo));
  return Permissions.Builder.factory(authorizations).build();
}
 
Example #18
Source File: ResourcePermissionProvider.java    From fiat with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves Permissions for the supplied resource.
 *
 * @param resource the resource for which to get permissions (never null)
 * @return the Permissions for the resource (never null - use Permissions.EMPTY or apply some
 *     restriction)
 */
@Nonnull
Permissions getPermissions(@Nonnull T resource);
 
Example #19
Source File: ResourcePermissionSource.java    From fiat with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves Permissions for the supplied resource.
 *
 * @param resource the resource for which to get permissions (never null)
 * @return the Permissions for the resource (never null - use Permissions.EMPTY or apply some
 *     restriction)
 */
@Nonnull
Permissions getPermissions(@Nonnull T resource);
 
Example #20
Source File: FallbackPermissionsResolver.java    From fiat with Apache License 2.0 2 votes vote down vote up
/**
 * Resolve fallback permissions.
 *
 * @param permissions
 * @return The resolved Permissions
 */
Permissions resolve(@Nonnull Permissions permissions);
 
Example #21
Source File: FallbackPermissionsResolver.java    From fiat with Apache License 2.0 2 votes vote down vote up
/**
 * Determine if resolving fallback permissions is necessary - typically checking if permissions
 * are restricted.
 *
 * @param permissions
 * @return boolean
 */
boolean shouldResolve(@Nonnull Permissions permissions);