Search in sources :

Example 26 with Audit

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();
}
Also used : Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with Audit

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();
}
Also used : Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with Audit

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();
}
Also used : Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with Audit

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;
}
Also used : Audit(alien4cloud.audit.annotation.Audit) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) Method(alien4cloud.audit.model.Method) AuditedMethod(alien4cloud.audit.model.AuditedMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Map(java.util.Map) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 30 with Audit

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));
}
Also used : Audit(alien4cloud.audit.annotation.Audit) Method(alien4cloud.audit.model.Method) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Audit (alien4cloud.audit.annotation.Audit)71 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)69 ApiOperation (io.swagger.annotations.ApiOperation)67 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)63 Application (alien4cloud.model.application.Application)27 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)24 Location (alien4cloud.model.orchestrators.locations.Location)15 List (java.util.List)15 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)11 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)11 RestResponse (alien4cloud.rest.model.RestResponse)10 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)9 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)7 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)7 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)7 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)7 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)7 ApplicationEnvironmentAuthorizationDTO (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO)7 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)7 Subject (alien4cloud.security.Subject)7