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);
}
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());
}
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);
}
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;
}
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);
}
}
Aggregations