Search in sources :

Example 6 with AbstractLocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate in project alien4cloud by alien4cloud.

the class AbstractLocationResourcesSecurityController method grantAccessToGroups.

/**
 *****************************************************************************************************************************
 *
 * SECURITY ON GROUPS
 *
 ******************************************************************************************************************************
 */
/**
 * Grant access to the location resource to the groups
 *
 * @param locationId The location's id.
 * @param groupIds The authorized groups.
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Grant access to the location to the groups", notes = "Only user with ADMIN role can grant access to a group.")
@RequestMapping(value = "/groups", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<GroupDTO>> grantAccessToGroups(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String resourceId, @RequestBody String[] groupIds) {
    Location location = locationService.getLocation(orchestratorId, locationId);
    locationSecurityService.grantAuthorizationOnLocationIfNecessary(location, Subject.GROUP, groupIds);
    AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
    resourcePermissionService.grantPermission(resourceTemplate, (resource -> locationResourceService.saveResource(location, (AbstractLocationResourceTemplate) resource)), Subject.GROUP, groupIds);
    List<GroupDTO> groups = GroupDTO.convert(resourcePermissionService.getAuthorizedGroups(resourceTemplate));
    return RestResponseBuilder.<List<GroupDTO>>builder().data(groups).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) GroupDTO(alien4cloud.rest.orchestrator.model.GroupDTO) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) List(java.util.List) Location(alien4cloud.model.orchestrators.locations.Location) 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 7 with AbstractLocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate in project alien4cloud by alien4cloud.

the class LocationResourceService method fillLocationResourceTypes.

private void fillLocationResourceTypes(Collection<? extends AbstractLocationResourceTemplate> resourceTemplates, IResourceTypeFiller resourceTypeFiller) {
    Map<String, Set<String>> resourceTypesByLocationId = Maps.newHashMap();
    for (AbstractLocationResourceTemplate resourceTemplate : resourceTemplates) {
        if (!resourceTemplate.isService()) {
            Set<String> locationResourceTypesSet = resourceTypesByLocationId.computeIfAbsent(resourceTemplate.getLocationId(), k -> Sets.newHashSet());
            locationResourceTypesSet.add(resourceTemplate.getTemplate().getType());
        }
    }
    for (Map.Entry<String, Set<String>> resourceTypeByLocationIdEntry : resourceTypesByLocationId.entrySet()) {
        String locationId = resourceTypeByLocationIdEntry.getKey();
        Set<String> exposedTypes = resourceTypeByLocationIdEntry.getValue();
        Location location = locationService.getOrFail(locationId);
        resourceTypeFiller.process(exposedTypes, location.getDependencies());
    }
}
Also used : Set(java.util.Set) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) Map(java.util.Map) HashMap(java.util.HashMap) Location(alien4cloud.model.orchestrators.locations.Location)

Example 8 with AbstractLocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate in project alien4cloud by alien4cloud.

the class LocationResourceService method setTemplateProperty.

/*
     * (non-Javadoc)
     * 
     * @see alien4cloud.orchestrators.locations.services.ILocationResourceService#setTemplateProperty(java.lang.String, java.lang.String,
     * java.lang.Object)
     */
@Override
public void setTemplateProperty(String resourceId, String propertyName, Object propertyValue) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
    AbstractLocationResourceTemplate resourceTemplate = getOrFail(resourceId);
    Location location = locationService.getOrFail(resourceTemplate.getLocationId());
    AbstractInheritableToscaType resourceType = (AbstractInheritableToscaType) csarRepoSearchService.getRequiredElementInDependencies(AbstractToscaType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
    if (!safe(resourceType.getProperties()).containsKey(propertyName)) {
        throw new NotFoundException("Property [" + propertyName + "] is not found in type [" + resourceType.getElementId() + "]");
    }
    propertyService.setPropertyValue(location.getDependencies(), resourceTemplate.getTemplate(), resourceType.getProperties().get(propertyName), propertyName, propertyValue);
    saveResource(resourceTemplate);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NotFoundException(alien4cloud.exception.NotFoundException) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) Location(alien4cloud.model.orchestrators.locations.Location)

Example 9 with AbstractLocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method checkSubstitutions.

private void checkSubstitutions(List<SubstitutionSetting> expectedSubstitutionSettings, ITemplateSubstitutionInfoAccessor substitutionsAccessor) throws IOException {
    DeploymentTopologyDTO dto = getDTOAndassertNotNull();
    Map<String, String> substitutions = substitutionsAccessor.getSubstitutions(dto);
    Map<String, ? extends AbstractLocationResourceTemplate> resources = substitutionsAccessor.getSubstitutionTemplates(dto);
    assertTrue(MapUtils.isNotEmpty(substitutions));
    assertTrue(MapUtils.isNotEmpty(resources));
    for (SubstitutionSetting substitutionSetting : expectedSubstitutionSettings) {
        String substituteId = substitutions.get(substitutionSetting.getTemplateNme());
        assertNotNull(substituteId);
        AbstractLocationResourceTemplate substitute = resources.get(substituteId);
        assertNotNull(substitute);
        assertEquals(substitutionSetting.getResourceName(), substitute.getName());
        assertEquals(substitutionSetting.getResourceType(), substitute.getTemplate().getType());
    }
}
Also used : AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO)

Example 10 with AbstractLocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate in project alien4cloud by alien4cloud.

the class AbstractLocationResourceSteps method resourceFoundInLocation.

private boolean resourceFoundInLocation(String resourceName, String resourceType, IResourceAccessor resourceAccessor) throws IOException {
    String restResponse = Context.getInstance().getRestResponse();
    RestResponse<LocationDTO> response = JsonUtil.read(restResponse, LocationDTO.class, Context.getJsonMapper());
    LocationDTO locationDTO = response.getData();
    boolean found = false;
    final List<? extends AbstractLocationResourceTemplate> templates = resourceAccessor.getResources(locationDTO.getResources());
    for (AbstractLocationResourceTemplate lrt : templates) {
        if (lrt.getName().equals(resourceName) && lrt.getTypes().contains(resourceType)) {
            found = true;
            break;
        }
    }
    return found;
}
Also used : AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationDTO(alien4cloud.rest.orchestrator.model.LocationDTO)

Aggregations

AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)18 Location (alien4cloud.model.orchestrators.locations.Location)12 ApiOperation (io.swagger.annotations.ApiOperation)12 List (java.util.List)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)10 Set (java.util.Set)10 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)9 Audit (alien4cloud.audit.annotation.Audit)9 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)9 ILocationResourceService (alien4cloud.orchestrators.locations.services.ILocationResourceService)9 LocationSecurityService (alien4cloud.orchestrators.locations.services.LocationSecurityService)9 LocationService (alien4cloud.orchestrators.locations.services.LocationService)9 RestResponse (alien4cloud.rest.model.RestResponse)9 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)9 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)9 Subject (alien4cloud.security.Subject)9 Sets (com.google.common.collect.Sets)9 Arrays (java.util.Arrays)9