Search in sources :

Example 66 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method delete.

/**
 * Delete an application environment based on it's id.
 *
 * @param applicationEnvironmentId
 * @return
 */
@ApiOperation(value = "Delete an application environment from its id", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Boolean> delete(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    // Only APPLICATION_MANAGER on the underlying application can delete an application environment
    ApplicationEnvironment environmentToDelete = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
    int countEnvironment = applicationEnvironmentService.getByApplicationId(environmentToDelete.getApplicationId()).length;
    if (countEnvironment == 1) {
        throw new DeleteLastApplicationEnvironmentException("Application environment with id <" + applicationEnvironmentId + "> cannot be deleted as it's the last one for the application id <" + environmentToDelete.getApplicationId() + ">");
    }
    applicationEnvironmentService.delete(applicationEnvironmentId);
    return RestResponseBuilder.<Boolean>builder().data(true).build();
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeleteLastApplicationEnvironmentException(alien4cloud.exception.DeleteLastApplicationEnvironmentException) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 67 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method update.

/**
 * Update application environment
 *
 * @param applicationEnvironmentId
 * @param request
 * @return
 */
@ApiOperation(value = "Updates by merging the given request into the given application environment", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}", 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 applicationEnvironmentId, @RequestBody UpdateApplicationEnvironmentRequest request) throws OrchestratorDisabledException {
    // Only APPLICATION_MANAGER on the underlying application can update an application environment
    ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
    if (applicationEnvironment == null) {
        return RestResponseBuilder.<Void>builder().data(null).error(RestErrorBuilder.builder(RestErrorCode.APPLICATION_ENVIRONMENT_ERROR).message("Application environment with id <" + applicationEnvironmentId + "> does not exist").build()).build();
    }
    applicationEnvironmentService.ensureNameUnicity(applicationEnvironment.getApplicationId(), request.getName());
    ReflectionUtil.mergeObject(request, applicationEnvironment);
    if (applicationEnvironment.getName() == null || applicationEnvironment.getName().isEmpty()) {
        throw new UnsupportedOperationException("Application environment name cannot be set to null or empty");
    }
    if (request.getCurrentVersionId() != null) {
        // update the version of the environment
        ApplicationVersion applicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationEnvironment.getApplicationId(), request.getCurrentVersionId()));
        applicationEnvironment.setVersion(applicationVersion.getVersion());
        applicationEnvironment.setTopologyVersion(request.getCurrentVersionId());
    }
    alienDAO.save(applicationEnvironment);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 68 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentRolesController method addUserRole.

/**
 * Add a role to a user on a specific application environment
 *
 * @param applicationEnvironmentId application environment id
 * @param username user for who to add role
 * @param role the application role to add to this user
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Add a role to a user on a specific application environment", 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 applicationEnvironmentId, @PathVariable String username, @PathVariable String role) {
    ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
    resourceRoleService.addUserRole(applicationEnvironment, username, role);
    handleAddUserRoleOnApplication(applicationEnvironment.getApplicationId(), username);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) 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 69 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentRolesController method addGroupRole.

/**
 * Add a role to a group on a specific application environment
 *
 * @param applicationEnvironmentId application environment id
 * @param groupId The id of the group to update roles
 * @param role The role to add to the group on the application environment from {@link ApplicationEnvironmentRole}
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Add a role to a group on a specific application environment", notes = "Any user with application role APPLICATION_MANAGER can assign any role to a group of users. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/groups/{groupId}/{role}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> addGroupRole(@PathVariable String applicationEnvironmentId, @PathVariable String groupId, @PathVariable String role) {
    ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
    resourceRoleService.addGroupRole(applicationEnvironment, groupId, role);
    handleAddGrpRoleOnApplication(applicationEnvironment.getApplicationId(), groupId);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) 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 70 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentRolesController method handleRemoveUserRoleOnApplication.

/**
 * Handle remove roles on the targeted application
 *
 * @param applicationId
 * @param username
 */
private void handleRemoveUserRoleOnApplication(String applicationId, String username) {
    Application application = applicationService.getOrFail(applicationId);
    // Check if user has at least one role on the application or the environments
    Set<String> applicationRoles = application.getUserRoles() != null ? application.getUserRoles().get(username) : new HashSet<>();
    List<Set<String>> environmentRoles = Arrays.stream(applicationEnvironmentService.getByApplicationId(applicationId)).map(applicationEnvironment -> applicationEnvironment.getUserRoles() != null ? applicationEnvironment.getUserRoles().get(username) : null).filter(roles -> roles != null).collect(Collectors.toList());
    if (mustRemoveApplicationUserRole(applicationRoles, environmentRoles)) {
        // If we are here, it means that we must take out the APPLICATION_USER role for application as user does not have any other role than that
        resourceRoleService.removeUserRole(application, username, ApplicationRole.APPLICATION_USER.toString());
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) ApplicationRole(alien4cloud.security.model.ApplicationRole) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) MediaType(org.springframework.http.MediaType) Resource(javax.annotation.Resource) Set(java.util.Set) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ApplicationEnvironmentRole(alien4cloud.security.model.ApplicationEnvironmentRole) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) HashSet(java.util.HashSet) ApiOperation(io.swagger.annotations.ApiOperation) List(java.util.List) Audit(alien4cloud.audit.annotation.Audit) RestResponseBuilder(alien4cloud.rest.model.RestResponseBuilder) RestResponse(alien4cloud.rest.model.RestResponse) Application(alien4cloud.model.application.Application) ResourceRoleService(alien4cloud.security.ResourceRoleService) ApplicationService(alien4cloud.application.ApplicationService) Api(io.swagger.annotations.Api) Set(java.util.Set) HashSet(java.util.HashSet) Application(alien4cloud.model.application.Application)

Aggregations

ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)82 ApiOperation (io.swagger.annotations.ApiOperation)42 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 Application (alien4cloud.model.application.Application)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)35 Audit (alien4cloud.audit.annotation.Audit)27 List (java.util.List)17 Collectors (java.util.stream.Collectors)16 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)15 RestResponse (alien4cloud.rest.model.RestResponse)15 Topology (org.alien4cloud.tosca.model.templates.Topology)15 Set (java.util.Set)14 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)13 NotFoundException (alien4cloud.exception.NotFoundException)13 Map (java.util.Map)13 Resource (javax.annotation.Resource)12 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)11 Deployment (alien4cloud.model.deployment.Deployment)11 Arrays (java.util.Arrays)11 Location (alien4cloud.model.orchestrators.locations.Location)10