Search in sources :

Example 11 with Application

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

the class ApplicationEnvironmentController method getTopologyId.

@Deprecated
@ApiOperation(value = "Deprecated: Get the id of the topology linked to the environment", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}/topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<String> getTopologyId(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    Application application = applicationService.getOrFail(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
    String topologyId = applicationEnvironmentService.getTopologyId(applicationEnvironmentId);
    if (topologyId == null) {
        throw new ApplicationVersionNotFoundException("An application version is required by an application environment.");
    }
    return RestResponseBuilder.<String>builder().data(topologyId).build();
}
Also used : ApplicationVersionNotFoundException(alien4cloud.exception.ApplicationVersionNotFoundException) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with Application

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

the class ApplicationEnvironmentController method getApplicationEnvironment.

/**
 * Get application environment from its id
 *
 * @param applicationId The application id
 * @param applicationEnvironmentId the environment for which to get the status
 * @return A {@link RestResponse} that contains the application environment {@link ApplicationEnvironment}.
 */
@ApiOperation(value = "Get an application environment from its id", notes = "Returns the application environment. Roles required: Application environment [ APPLICATION_USER | DEPLOYMENT_MANAGER ], or application [APPLICATION_MANAGER]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<ApplicationEnvironmentDTO> getApplicationEnvironment(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    Application application = applicationService.checkAndGetApplication(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
    return RestResponseBuilder.<ApplicationEnvironmentDTO>builder().data(dtoBuilder.getApplicationEnvironmentDTO(environment)).build();
}
Also used : Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 13 with Application

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

the class ApplicationEnvironmentGitController method checkEnvironmentAuthorization.

private void checkEnvironmentAuthorization(String applicationId, String environmentId) {
    ApplicationEnvironment environment = environmentService.getOrFail(environmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Cannot find environement <" + environmentId + "> for application <" + applicationId + ">.");
    }
    Application application = applicationService.getOrFail(applicationId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application)

Example 14 with Application

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

the class ApplicationEnvironmentRolesController method handleRemoveGrpRoleOnApplication.

/**
 * Handle group roles on the targeted application
 *
 * @param applicationId
 * @param groupId
 */
private void handleRemoveGrpRoleOnApplication(String applicationId, String groupId) {
    Application application = applicationService.getOrFail(applicationId);
    // Check if group has at least one role on the application or the environments
    Set<String> applicationRoles = application.getGroupRoles() != null ? application.getGroupRoles().get(groupId) : new HashSet<>();
    List<Set<String>> environmentRoles = Arrays.stream(applicationEnvironmentService.getByApplicationId(applicationId)).map(applicationEnvironment -> applicationEnvironment.getGroupRoles() != null ? applicationEnvironment.getGroupRoles().get(groupId) : 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 group does not have any other role than that
        resourceRoleService.removeGroupRole(application, groupId, 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)

Example 15 with Application

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

the class ApplicationEnvironmentRolesController method handleAddUserRoleOnApplication.

/**
 * Handle user roles on the targeted application
 * Any role on an environment implies APPLICATION_USER role on the linked application
 *
 * @param applicationId
 * @param username
 */
private void handleAddUserRoleOnApplication(String applicationId, String username) {
    Application application = applicationService.getOrFail(applicationId);
    resourceRoleService.addUserRole(application, username, ApplicationRole.APPLICATION_USER.toString());
}
Also used : Application(alien4cloud.model.application.Application)

Aggregations

Application (alien4cloud.model.application.Application)103 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)45 ApiOperation (io.swagger.annotations.ApiOperation)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)39 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)38 Audit (alien4cloud.audit.annotation.Audit)28 List (java.util.List)14 Topology (org.alien4cloud.tosca.model.templates.Topology)14 Set (java.util.Set)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)11 RestResponse (alien4cloud.rest.model.RestResponse)11 Collectors (java.util.stream.Collectors)11 Map (java.util.Map)10 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)9 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)9 Arrays (java.util.Arrays)9 When (cucumber.api.java.en.When)8 Deployment (alien4cloud.model.deployment.Deployment)7 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)7 ApplicationEnvironmentAuthorizationDTO (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO)7