use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class AbstractLocationResourcesSecurityController method grantAccessToUsers.
/**
*****************************************************************************************************************************
*
* SECURITY ON USERS
*
******************************************************************************************************************************
*/
/**
* Grant access to the location resoure to the user (deploy on the location)
*
* @param locationId The location's id.
* @param resourceId The location resource's id.
* @param userNames The authorized users.
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Grant access to the location's resource to the users, send back the new authorised users list", notes = "Only user with ADMIN role can grant access to another users.")
@RequestMapping(value = "/users", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<UserDTO>> grantAccessToUsers(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String resourceId, @RequestBody String[] userNames) {
Location location = locationService.getLocation(orchestratorId, locationId);
locationSecurityService.grantAuthorizationOnLocationIfNecessary(location, Subject.USER, userNames);
AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
// prefer using locationResourceService.saveResource so that the location update date is update.
// This will then trigger a deployment topology update
resourcePermissionService.grantPermission(resourceTemplate, (resource -> locationResourceService.saveResource(location, (AbstractLocationResourceTemplate) resource)), Subject.USER, userNames);
List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(resourceTemplate));
return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
use of alien4cloud.model.orchestrators.locations.Location 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.Location in project alien4cloud by alien4cloud.
the class LocationMetaPropertiesController method upsertMetaProperty.
/**
* Update or create a property for an orchestrator
*
* @param orchestratorId id of the orchestrator the location belongs to.
* @param locationId id of the location to update
* @param propertyRequest property request
* @return information on the constraint
*/
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public RestResponse<ConstraintInformation> upsertMetaProperty(@ApiParam(value = "Id of the orchestrator for which the location is defined.") @PathVariable String orchestratorId, @ApiParam(value = "Id of the location to get", required = true) @PathVariable String locationId, @ApiParam(value = "Id of the location to get", required = true) @RequestBody PropertyRequest propertyRequest) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
AuthorizationUtil.hasOneRoleIn(Role.ADMIN);
Location location = locationService.getOrFail(locationId);
try {
metaPropertiesService.upsertMetaProperty(location, propertyRequest.getDefinitionId(), propertyRequest.getValue());
} catch (ConstraintViolationException e) {
log.error("Constraint violation error for property <" + propertyRequest.getDefinitionId() + "> with value <" + propertyRequest.getValue() + ">", e);
return RestResponseBuilder.<ConstraintInformation>builder().data(e.getConstraintInformation()).error(RestErrorBuilder.builder(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR).message(e.getMessage()).build()).build();
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
log.error("Constraint value violation error for property <" + e.getConstraintInformation().getName() + "> with value <" + e.getConstraintInformation().getValue() + "> and type <" + e.getConstraintInformation().getType() + ">", e);
return RestResponseBuilder.<ConstraintInformation>builder().data(e.getConstraintInformation()).error(RestErrorBuilder.builder(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR).message(e.getMessage()).build()).build();
}
return RestResponseBuilder.<ConstraintInformation>builder().data(null).error(null).build();
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class DeploymentController method getRelatedLocationsSummaries.
private Map<String, Location> getRelatedLocationsSummaries(Deployment[] deployments) {
Set<String> locationIds = Sets.newHashSet();
for (Deployment deployment : deployments) {
if (ArrayUtils.isNotEmpty(deployment.getLocationIds())) {
locationIds.addAll(Sets.newHashSet(deployment.getLocationIds()));
}
}
Map<String, Location> locations = null;
if (!locationIds.isEmpty()) {
locations = locationService.findByIds(FetchContext.SUMMARY, locationIds.toArray(new String[locationIds.size()]));
}
return locations != null ? locations : Maps.newHashMap();
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class DeploymentController method buildDeploymentsDTOS.
private List<DeploymentDTO> buildDeploymentsDTOS(boolean includeSourceSummary, Deployment... deployments) {
List<DeploymentDTO> dtos = Lists.newArrayList();
if (ArrayUtils.isEmpty(deployments)) {
return dtos;
}
Map<String, ? extends IDeploymentSource> sources = Maps.newHashMap();
// get the app summaries if true
if (includeSourceSummary) {
DeploymentSourceType sourceType = deployments[0].getSourceType();
String[] sourceIds = getSourceIdsFromDeployments(deployments);
if (sourceIds[0] != null) {
// can have no application deployed
switch(sourceType) {
case APPLICATION:
Map<String, ? extends IDeploymentSource> appSources = applicationService.findByIdsIfAuthorized(FetchContext.SUMMARY, sourceIds);
if (appSources != null) {
sources = appSources;
}
}
}
}
Map<String, Location> locationsSummariesMap = getRelatedLocationsSummaries(deployments);
for (Object object : deployments) {
Deployment deployment = (Deployment) object;
IDeploymentSource source = sources.get(deployment.getSourceId());
if (source == null) {
source = new DeploymentSourceDTO(deployment.getSourceId(), deployment.getSourceName());
}
List<Location> locationsSummaries = getLocations(deployment.getLocationIds(), locationsSummariesMap);
DeploymentDTO dto = new DeploymentDTO(deployment, source, locationsSummaries);
dtos.add(dto);
}
return dtos;
}
Aggregations