Search in sources :

Example 21 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updateSubstitution.

/**
 * Update node substitution.
 *
 * @param appId id of the application.
 * @param environmentId id of the environment.
 * @return response containing the available substitutions.
 */
@ApiOperation(value = "Substitute a specific node by the location resource template in the topology of an application given an environment.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/substitutions/{nodeId}", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<DeploymentTopologyDTO> updateSubstitution(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestParam String locationResourceTemplateId) {
    Application application = applicationService.getOrFail(appId);
    ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
    Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
    DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> nodeMatchingSubstitutionService.updateSubstitution(application, environment, topology, nodeId, locationResourceTemplateId));
    return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) 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 22 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updateSubstitutionCapabilityProperty.

@ApiOperation(value = "Update substitution's capability property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/substitutions/{nodeId}/capabilities/{capabilityName}/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updateSubstitutionCapabilityProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @PathVariable String capabilityName, @RequestBody UpdatePropertyRequest updateRequest) {
    try {
        Application application = applicationService.getOrFail(appId);
        ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
        AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
        ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
        Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
        DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.of(capabilityName), updateRequest.getPropertyName(), updateRequest.getPropertyValue()));
        return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
    } catch (ConstraintTechnicalException e) {
        if (e.getCause() instanceof ConstraintFunctionalException) {
            return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue());
        }
        throw e;
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) 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 23 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class PluginController method upload.

@ApiOperation(value = "Upload a plugin archive.", notes = "Content of the zip file must be compliant with the expected alien 4 cloud plugin structure.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public RestResponse<Void> upload(@ApiParam(value = "Zip file that contains the plugin.", required = true) @RequestParam("file") MultipartFile pluginArchive) {
    Path pluginPath = null;
    try {
        // save the plugin archive in the temp directory
        pluginPath = Files.createTempFile(tempDirPath, null, ".zip");
        FileUploadUtil.safeTransferTo(pluginPath, pluginArchive);
        // upload the plugin archive
        Plugin plugin = pluginManager.uploadPlugin(pluginPath);
        // TODO as we do not manage many version of a same plugin, is this still relevant ?
        if (plugin.isConfigurable()) {
            tryReusePreviousVersionConf(plugin);
        }
    } catch (MissingPlugingDescriptorFileException e) {
        log.error("Your plugin don't have the META-INF/plugin.yml file.", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.MISSING_PLUGIN_DESCRIPTOR_FILE_EXCEPTION.getCode(), "Your plugin don't have the META-INF/plugin.yml file.")).build();
    } catch (IOException e) {
        log.error("Unexpected IO error on plugin upload.", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.INDEXING_SERVICE_ERROR.getCode(), "A technical issue occurred during the plugin upload <" + e.getMessage() + ">.")).build();
    } catch (PluginLoadingException e) {
        log.error("Fail to enable and load the plugin. The plugin will remain disabled", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.ENABLE_PLUGIN_ERROR.getCode(), e.getMessage())).build();
    } finally {
        if (pluginPath != null) {
            try {
                FileUtil.delete(pluginPath);
            } catch (IOException e) {
                log.error("Failed to cleanup temporary file <" + pluginPath.toString() + ">", e);
            }
        }
    }
    return RestResponseBuilder.<Void>builder().build();
}
Also used : Path(java.nio.file.Path) PluginLoadingException(alien4cloud.plugin.exception.PluginLoadingException) RestError(alien4cloud.rest.model.RestError) IOException(java.io.IOException) Plugin(alien4cloud.plugin.Plugin) MissingPlugingDescriptorFileException(alien4cloud.plugin.exception.MissingPlugingDescriptorFileException) 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 24 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class ApplicationMetaPropertyController method upsertProperty.

/**
 * Update or create a property for an application
 *
 * @param applicationId id of the application
 * @param propertyRequest property request
 * @return information on the constraint
 * @throws ConstraintValueDoNotMatchPropertyTypeException
 * @throws ConstraintViolationException
 */
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<ConstraintUtil.ConstraintInformation> upsertProperty(@PathVariable String applicationId, @RequestBody PropertyRequest propertyRequest) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    Application application = alienDAO.findById(Application.class, applicationId);
    AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
    try {
        metaPropertiesService.upsertMetaProperty(application, propertyRequest.getDefinitionId(), propertyRequest.getValue());
    } catch (ConstraintViolationException e) {
        log.error("Constraint violation error for property <" + propertyRequest.getDefinitionId() + "> with value <" + propertyRequest.getValue() + ">", e);
        return RestResponseBuilder.<ConstraintUtil.ConstraintInformation>builder().data(e.getConstraintInformation()).error(RestErrorBuilder.builder(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR).message(e.getMessage()).build()).build();
    } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
        log.error("Constraint value violation error for property <" + e.getConstraintInformation().getName() + "> with value <" + e.getConstraintInformation().getValue() + "> and type <" + e.getConstraintInformation().getType() + ">", e);
        return RestResponseBuilder.<ConstraintUtil.ConstraintInformation>builder().data(e.getConstraintInformation()).error(RestErrorBuilder.builder(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR).message(e.getMessage()).build()).build();
    }
    return RestResponseBuilder.<ConstraintUtil.ConstraintInformation>builder().data(null).error(null).build();
}
Also used : ConstraintUtil(alien4cloud.tosca.properties.constraints.ConstraintUtil) ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 25 with Audit

use of alien4cloud.audit.annotation.Audit in project alien4cloud by alien4cloud.

the class ApplicationRolesController method addUserRole.

/**
 * Add a role to a user on a specific application
 *
 * @param applicationId The id of the application.
 * @param username The username of the user to update roles.
 * @param role The role to add to the user on the application.
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Add a role to a user on a specific application", notes = "Any user with application role APPLICATION_MANAGER can assign any role to another user. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/users/{username}/{role}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> addUserRole(@PathVariable String applicationId, @PathVariable String username, @PathVariable String role) {
    Application application = applicationService.getOrFail(applicationId);
    AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
    resourceRoleService.addUserRole(application, username, role);
    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)

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