use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.
the class ApplicationTopologyVersionController method create.
@ApiOperation(value = "Create a new application topology version", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> create(@PathVariable String applicationId, @PathVariable String applicationVersionId, @RequestBody CreateApplicationTopologyVersionRequest request) {
Application application = applicationService.getOrFail(applicationId);
AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
String originalId = request.getTopologyTemplateId();
boolean originalIsAppVersion = false;
if (originalId == null) {
originalId = request.getApplicationTopologyVersion();
originalIsAppVersion = true;
} else if (request.getApplicationTopologyVersion() != null) {
throw new IllegalArgumentException("topologyTemplateId and applicationTopologyVersion are mutually exclusive.");
}
String qualifier = request.getQualifier() == null ? null : request.getQualifier().trim();
applicationVersionService.createTopologyVersion(applicationId, applicationVersionId, qualifier, request.getDescription(), originalId, originalIsAppVersion);
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.
the class ApplicationVersionController method update.
/**
* Update application version
*
* @param applicationId The id of the application for which to update a version.
* @param applicationVersionId The id of the application version.
* @param request The update request that eventually contains a new name and description.
* @return A void rest response with no error.
*/
@ApiOperation(value = "Updates by merging the given request into the given application version", notes = "Updates by merging the given request into the given application version. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationVersionId:.+}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> update(@PathVariable String applicationId, @PathVariable String applicationVersionId, @RequestBody UpdateApplicationVersionRequest request) {
Application application = applicationService.getOrFail(applicationId);
AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
appVersionService.update(applicationId, applicationVersionId, request.getVersion(), request.getDescription());
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.
the class ApplicationVersionController method delete.
/**
* Delete an application environment based on it's id. Should not be able to delete a deployed version.
*
* @param applicationId
* @param applicationVersionId
* @return boolean is delete
*/
@ApiOperation(value = "Delete an application version from its id", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationVersionId:.+}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Boolean> delete(@PathVariable String applicationId, @PathVariable String applicationVersionId) {
Application application = applicationService.getOrFail(applicationId);
AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
appVersionService.delete(applicationVersionId);
return RestResponseBuilder.<Boolean>builder().data(true).build();
}
use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.
the class AuditController method getAllAvailableMethodsForAudit.
private <T extends Method> Map<T, Boolean> getAllAvailableMethodsForAudit(RequestMappingHandlerMapping requestMappingHandlerMapping, IAuditedMethodFactory<T> methodFactory) {
Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
Map<T, Boolean> allMethods = Maps.newHashMap();
for (Map.Entry<RequestMappingInfo, HandlerMethod> handlerMethodEntry : handlerMethods.entrySet()) {
HandlerMethod method = handlerMethodEntry.getValue();
Method auditedMethod = auditService.getAuditedMethod(method);
if (auditedMethod != null) {
Audit audit = method.getMethodAnnotation(Audit.class);
boolean enabledByDefault = audit != null && audit.enabledByDefault();
allMethods.put(methodFactory.buildAuditedMethod(auditedMethod, method), enabledByDefault);
}
}
return allMethods;
}
use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.
the class AuditService method getAuditedMethod.
public Method getAuditedMethod(HandlerMethod controllerMethod) {
RequestMapping methodMapping = AnnotationUtils.findAnnotation(controllerMethod.getMethod(), RequestMapping.class);
RequestMapping controllerMapping = AnnotationUtils.findAnnotation(controllerMethod.getMethod().getDeclaringClass(), RequestMapping.class);
String httpMethod = null;
if (controllerMapping != null) {
httpMethod = getRequestMappingMethod(controllerMapping);
if (methodMapping != null) {
String methodHttpMethod = getRequestMappingMethod(methodMapping);
if (httpMethod == null) {
// Controller http method override method http method
httpMethod = methodHttpMethod;
}
}
} else if (methodMapping != null) {
httpMethod = getRequestMappingMethod(methodMapping);
}
if (httpMethod == null) {
return null;
}
Audit audit = getAuditAnnotation(controllerMethod);
return new Method(controllerMethod.getMethod().toGenericString(), httpMethod, getAuditCategoryName(controllerMethod, audit), getAuditActionName(controllerMethod, audit), getAuditHiddenFields(audit));
}
Aggregations