Search in sources :

Example 96 with Application

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

the class ApplicationEnvironmentAuthorizationDTO method convert.

public static GetMultipleDataResult<ApplicationEnvironmentAuthorizationDTO> convert(GetMultipleDataResult<Application> toConvert, List<ApplicationEnvironmentAuthorizationDTO> allDTOs) {
    if (toConvert == null) {
        return null;
    }
    GetMultipleDataResult<ApplicationEnvironmentAuthorizationDTO> converted = new GetMultipleDataResult<>();
    ReflectionUtil.mergeObject(toConvert, converted, "data");
    List<ApplicationEnvironmentAuthorizationDTO> data = Lists.newArrayList();
    for (Application app : toConvert.getData()) {
        for (ApplicationEnvironmentAuthorizationDTO appEnvDTO : allDTOs) {
            if (app.getId().equals(appEnvDTO.getApplication().getId())) {
                data.add(appEnvDTO);
            }
        }
    }
    converted.setData(data.toArray(new ApplicationEnvironmentAuthorizationDTO[toConvert.getData().length]));
    return converted;
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Application(alien4cloud.model.application.Application)

Example 97 with Application

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

the class ApplicationEnvironmentAuthorizationDTO method buildDTOs.

public static List<ApplicationEnvironmentAuthorizationDTO> buildDTOs(List<Application> applicationsRelatedToEnvironment, List<Application> applicationsRelatedToEnvironmentType, List<ApplicationEnvironment> environments, List<Application> applications, List<String> environmentTypes) {
    Map<String, ApplicationEnvironmentAuthorizationDTO> aeaDTOsMap = Maps.newHashMap();
    if (!environments.isEmpty()) {
        applicationsRelatedToEnvironment.stream().forEach(application -> aeaDTOsMap.put(application.getId(), new ApplicationEnvironmentAuthorizationDTO(application, Lists.newArrayList(), Lists.newArrayList())));
        for (ApplicationEnvironment ae : environments) {
            ApplicationEnvironmentAuthorizationDTO dto = aeaDTOsMap.get(ae.getApplicationId());
            dto.getEnvironments().add(ae);
        }
    }
    if (!environmentTypes.isEmpty()) {
        for (Application application : applicationsRelatedToEnvironmentType) {
            if (aeaDTOsMap.get(application.getId()) != null) {
                aeaDTOsMap.get(application.getId()).getEnvironmentTypes().addAll(filterEnvType(application.getId(), environmentTypes));
            } else {
                aeaDTOsMap.put(application.getId(), new ApplicationEnvironmentAuthorizationDTO(application, Lists.newArrayList(), filterEnvType(application.getId(), environmentTypes)));
            }
        }
    }
    if (!applications.isEmpty()) {
        for (Application application : applications) {
            ApplicationEnvironmentAuthorizationDTO dto = aeaDTOsMap.get(application.getId());
            if (dto == null) {
                aeaDTOsMap.put(application.getId(), new ApplicationEnvironmentAuthorizationDTO(application, null, null));
            } else {
                // the application has detailed environment authorizations but the whole application authorization has precedence.
                dto.setEnvironments(null);
            }
        }
    }
    return Lists.newArrayList(aeaDTOsMap.values());
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application)

Example 98 with Application

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

the class AbstractLocationResourcesSecurityController method revokeApplicationAccess.

/**
 *****************************************************************************************************************************
 *
 * SECURITY ON APPLICATIONS
 *
 ******************************************************************************************************************************
 */
/**
 * Revoke the application's authorisation to access the location resource (including all related environments).
 *
 * @param locationId The id of the location.
 * @param applicationId The authorized application.
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Revoke the application's authorisation to access the location resource", notes = "Only user with ADMIN role can revoke access to the location.")
@RequestMapping(value = "/applications/{applicationId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<Void> revokeApplicationAccess(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String applicationId, @PathVariable String resourceId) {
    AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
    resourcePermissionService.revokePermission(resourceTemplate, (resource -> locationResourceService.saveResource((AbstractLocationResourceTemplate) resource)), Subject.APPLICATION, applicationId);
    // remove all environments related to this application
    ApplicationEnvironment[] aes = applicationEnvironmentService.getByApplicationId(applicationId);
    String[] envIds = Arrays.stream(aes).map(ae -> ae.getId()).toArray(String[]::new);
    resourcePermissionService.revokePermission(resourceTemplate, (resource -> locationResourceService.saveResource((AbstractLocationResourceTemplate) resource)), Subject.ENVIRONMENT, envIds);
    // remove all environment types
    Set<String> envTypeIds = Sets.newHashSet();
    for (String envType : safe(resourceTemplate.getEnvironmentTypePermissions()).keySet()) {
        if (envType.split(":")[0].equals(applicationId)) {
            envTypeIds.add(envType);
        }
    }
    resourcePermissionService.revokePermission(resourceTemplate, (resource -> locationResourceService.saveResource((AbstractLocationResourceTemplate) resource)), Subject.ENVIRONMENT_TYPE, envTypeIds.toArray(new String[envTypeIds.size()]));
    return RestResponseBuilder.<Void>builder().build();
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Lists(org.elasticsearch.common.collect.Lists) Arrays(java.util.Arrays) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) Subject(alien4cloud.security.Subject) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LocationService(alien4cloud.orchestrators.locations.services.LocationService) ResourcePermissionService(alien4cloud.authorization.ResourcePermissionService) ApplicationEnvironmentAuthorizationDTO(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) LocationSecurityService(alien4cloud.orchestrators.locations.services.LocationSecurityService) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) Audit(alien4cloud.audit.annotation.Audit) RestResponseBuilder(alien4cloud.rest.model.RestResponseBuilder) RestResponse(alien4cloud.rest.model.RestResponse) Application(alien4cloud.model.application.Application) ILocationResourceService(alien4cloud.orchestrators.locations.services.ILocationResourceService) MapUtils(org.apache.commons.collections4.MapUtils) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) MediaType(org.springframework.http.MediaType) Resource(javax.annotation.Resource) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IGenericSearchDAO(alien4cloud.dao.IGenericSearchDAO) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) GroupDTO(alien4cloud.rest.orchestrator.model.GroupDTO) UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) ApplicationEnvironmentAuthorizationUpdateRequest(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) 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 99 with Application

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

the class AbstractLocationResourcesSecurityController method getAuthorizedEnvironmentsAndEnvTypePerApplication.

/**
 * List all environments per application authorised to access the location resource.
 *
 * @return list of all environments per application.
 */
@ApiOperation(value = "List all applications,environments and environment types authorized to access the location resource", notes = "Only user with ADMIN role can list authorized applications,environments and environment types for the location.")
@RequestMapping(value = "/environmentsPerApplication", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<List<ApplicationEnvironmentAuthorizationDTO>> getAuthorizedEnvironmentsAndEnvTypePerApplication(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String resourceId) {
    AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
    List<Application> applicationsRelatedToEnvironment = Lists.newArrayList();
    List<Application> applicationsRelatedToEnvironmentType = Lists.newArrayList();
    List<ApplicationEnvironment> environments = Lists.newArrayList();
    List<String> environmentTypes = Lists.newArrayList();
    List<Application> applications = Lists.newArrayList();
    if (MapUtils.isNotEmpty(resourceTemplate.getEnvironmentPermissions())) {
        environments = alienDAO.findByIds(ApplicationEnvironment.class, resourceTemplate.getEnvironmentPermissions().keySet().toArray(new String[resourceTemplate.getEnvironmentPermissions().size()]));
        Set<String> environmentApplicationIds = environments.stream().map(ApplicationEnvironment::getApplicationId).collect(Collectors.toSet());
        applicationsRelatedToEnvironment = alienDAO.findByIds(Application.class, environmentApplicationIds.toArray(new String[environmentApplicationIds.size()]));
    }
    if (MapUtils.isNotEmpty(resourceTemplate.getEnvironmentTypePermissions())) {
        environmentTypes.addAll(resourceTemplate.getEnvironmentTypePermissions().keySet());
        Set<String> environmentTypeApplicationIds = Sets.newHashSet();
        for (String envType : safe(resourceTemplate.getEnvironmentTypePermissions()).keySet()) {
            environmentTypeApplicationIds.add(envType.split(":")[0]);
        }
        applicationsRelatedToEnvironmentType = alienDAO.findByIds(Application.class, environmentTypeApplicationIds.toArray(new String[environmentTypeApplicationIds.size()]));
    }
    if (resourceTemplate.getApplicationPermissions() != null && resourceTemplate.getApplicationPermissions().size() > 0) {
        applications = alienDAO.findByIds(Application.class, resourceTemplate.getApplicationPermissions().keySet().toArray(new String[resourceTemplate.getApplicationPermissions().size()]));
    }
    List<ApplicationEnvironmentAuthorizationDTO> result = ApplicationEnvironmentAuthorizationDTO.buildDTOs(applicationsRelatedToEnvironment, applicationsRelatedToEnvironmentType, environments, applications, environmentTypes);
    return RestResponseBuilder.<List<ApplicationEnvironmentAuthorizationDTO>>builder().data(result).build();
}
Also used : ApplicationEnvironmentAuthorizationDTO(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) List(java.util.List) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 100 with Application

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

the class RuntimeController method getNonNativesNodes.

@ApiOperation(value = "Get non-natives node template of a topology.", notes = "Returns An map of non-natives {@link NodeTemplate}. Application role required [ APPLICATION_MANAGER | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+?}/environment/{applicationEnvironmentId:.+?}/nonNatives", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<Map<String, NodeTemplate>> getNonNativesNodes(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    Application application = applicationService.getOrFail(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(environment.getId());
    DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
    Map<String, NodeTemplate> nonNativesNode = topologyTreeBuilderService.getNonNativesNodes(deploymentTopology);
    return RestResponseBuilder.<Map<String, NodeTemplate>>builder().data(nonNativesNode).build();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Map(java.util.Map) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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