Search in sources :

Example 1 with Permission

use of com.netflix.spinnaker.front50.model.application.Application.Permission in project front50 by spinnaker.

the class ApplicationPermissionsService method deleteApplicationPermission.

public void deleteApplicationPermission(@Nonnull String appName) {
    Permission oldPerm;
    try {
        oldPerm = applicationPermissionDAO().findById(appName);
    } catch (NotFoundException e) {
        // Nothing to see here, we're all done already.
        return;
    }
    performWrite(supportingEventListeners(Type.PRE_DELETE), supportingEventListeners(Type.POST_DELETE), (unused, newPerm) -> {
        applicationPermissionDAO().delete(appName);
        syncUsers(null, oldPerm);
        return newPerm;
    }, oldPerm, null);
}
Also used : Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Example 2 with Permission

use of com.netflix.spinnaker.front50.model.application.Application.Permission in project front50 by spinnaker.

the class ApplicationPermissionsService method getAllApplicationPermissions.

public Set<Permission> getAllApplicationPermissions() {
    Map<String, Permission> actualPermissions = applicationPermissionDAO().all().stream().map(permission -> new SimpleEntry<>(permission.getName().toLowerCase(), permission)).collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));
    applicationDAO.all().stream().filter(app -> !actualPermissions.containsKey(app.getName().toLowerCase())).forEach(app -> {
        Permission p = new Permission();
        p.setName(app.getName());
        p.setLastModified(-1L);
        p.setLastModifiedBy("auto-generated");
        actualPermissions.put(app.getName().toLowerCase(), p);
    });
    return new HashSet<>(actualPermissions.values());
}
Also used : ApplicationDAO(com.netflix.spinnaker.front50.model.application.ApplicationDAO) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) ApplicationPermissionEventListener(com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) FiatService(com.netflix.spinnaker.fiat.shared.FiatService) Type(com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener.Type) FiatClientConfigurationProperties(com.netflix.spinnaker.fiat.shared.FiatClientConfigurationProperties) ApplicationPermissionDAO(com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO) SimpleEntry(java.util.AbstractMap.SimpleEntry) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) FiatConfigurationProperties(com.netflix.spinnaker.front50.config.FiatConfigurationProperties) Collection(java.util.Collection) Set(java.util.Set) Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) Collectors(java.util.stream.Collectors) SystemException(com.netflix.spinnaker.kork.exceptions.SystemException) Permissions(com.netflix.spinnaker.fiat.model.resources.Permissions) List(java.util.List) Component(org.springframework.stereotype.Component) RetrofitError(retrofit.RetrofitError) Optional(java.util.Optional) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) SimpleEntry(java.util.AbstractMap.SimpleEntry) Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) HashSet(java.util.HashSet)

Example 3 with Permission

use of com.netflix.spinnaker.front50.model.application.Application.Permission in project front50 by spinnaker.

the class ApplicationPermissionsService method createApplicationPermission.

public Permission createApplicationPermission(@Nonnull Permission newPermission) {
    return performWrite(supportingEventListeners(Type.PRE_CREATE), supportingEventListeners(Type.POST_CREATE), (unused, newPerm) -> {
        Permission perm = applicationPermissionDAO().create(newPerm.getId(), newPerm);
        syncUsers(perm, null);
        return perm;
    }, null, newPermission);
}
Also used : Permission(com.netflix.spinnaker.front50.model.application.Application.Permission)

Example 4 with Permission

use of com.netflix.spinnaker.front50.model.application.Application.Permission in project front50 by spinnaker.

the class ApplicationPermissionsService method update.

private Permission update(@Nonnull String appName, @Nonnull Permission newPermission) {
    try {
        Permission oldPerm = applicationPermissionDAO().findById(appName);
        applicationPermissionDAO().update(appName, newPermission);
        syncUsers(newPermission, oldPerm);
    } catch (NotFoundException e) {
        createApplicationPermission(newPermission);
    }
    return newPermission;
}
Also used : Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Example 5 with Permission

use of com.netflix.spinnaker.front50.model.application.Application.Permission in project front50 by spinnaker.

the class ReorderPipelinesController method handlePipelineReorder.

private void handlePipelineReorder(Map<String, Object> requestBody, ItemDAO<Pipeline> pipelineItemDAO) {
    String application = (String) requestBody.get("application");
    Map<String, Integer> idsToIndices = (Map<String, Integer>) requestBody.get("idsToIndices");
    if (application == null) {
        throw new InvalidRequestException("`application` is required field on request body");
    }
    if (idsToIndices == null) {
        throw new InvalidRequestException("`idsToIndices` is required field on request body");
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!fiatPermissionEvaluator.storeWholePermission() && !fiatPermissionEvaluator.hasPermission(auth, application, "APPLICATION", "WRITE")) {
        throw new InvalidRequestException("Application write permission is required to reorder pipelines");
    }
    for (String id : idsToIndices.keySet()) {
        Pipeline pipeline = pipelineItemDAO.findById(id);
        if (pipeline == null) {
            throw new NotFoundException(String.format("No pipeline of id %s found", id));
        }
        if (!pipeline.getApplication().equals(application)) {
            throw new InvalidRequestException(String.format("Pipeline with id %s does not belong to application %s", id, application));
        }
        pipeline.setIndex(idsToIndices.get(id));
        pipelineItemDAO.update(id, pipeline);
    }
}
Also used : Authentication(org.springframework.security.core.Authentication) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Map(java.util.Map) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)

Aggregations

Permission (com.netflix.spinnaker.front50.model.application.Application.Permission)4 NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)4 Map (java.util.Map)2 Permissions (com.netflix.spinnaker.fiat.model.resources.Permissions)1 FiatClientConfigurationProperties (com.netflix.spinnaker.fiat.shared.FiatClientConfigurationProperties)1 FiatService (com.netflix.spinnaker.fiat.shared.FiatService)1 Pipeline (com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)1 FiatConfigurationProperties (com.netflix.spinnaker.front50.config.FiatConfigurationProperties)1 ApplicationPermissionEventListener (com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener)1 Type (com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener.Type)1 InvalidRequestException (com.netflix.spinnaker.front50.exceptions.InvalidRequestException)1 ApplicationDAO (com.netflix.spinnaker.front50.model.application.ApplicationDAO)1 ApplicationPermissionDAO (com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO)1 SystemException (com.netflix.spinnaker.kork.exceptions.SystemException)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1