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();
}
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());
}
}
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);
}
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());
}
}
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;
}
Aggregations