use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ServiceResourceServiceTest method testGetByNodeTypes.
@Test
public void testGetByNodeTypes() {
ServiceResource serviceResource = new ServiceResource();
serviceResource.setId("service1");
serviceResource.setNodeInstance(new NodeInstance());
serviceResource.getNodeInstance().setTypeVersion("1.0.0-SNAPSHOT");
serviceResource.getNodeInstance().setNodeTemplate(new NodeTemplate());
serviceResource.getNodeInstance().getNodeTemplate().setType("org.alien4cloud.nodes.MyType");
alienDao.save(serviceResource);
ServiceResource[] services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.MyType", "1.0.0-SNAPSHOT");
Assert.assertNotNull(services);
Assert.assertEquals(1, services.length);
services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.UnusedType", "1.0.0-SNAPSHOT");
Assert.assertNotNull(services);
Assert.assertEquals(0, services.length);
services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.MyType", "1.0.0");
Assert.assertNotNull(services);
Assert.assertEquals(0, services.length);
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ServiceResourceServiceTest method testHandleLocationDeleted.
@Test
public void testHandleLocationDeleted() {
ServiceResource serviceResource = new ServiceResource();
serviceResource.setId("service1");
serviceResource.setLocationIds(new String[] { "location1", "location2" });
alienDao.save(serviceResource);
serviceResourceService.handleLocationDeleted(new AfterLocationDeleted(this, "location3"));
serviceResource = serviceResourceService.getOrFail("service1");
Assert.assertArrayEquals(new String[] { "location1", "location2" }, serviceResource.getLocationIds());
serviceResourceService.handleLocationDeleted(new AfterLocationDeleted(this, "location1"));
serviceResource = serviceResourceService.getOrFail("service1");
Assert.assertArrayEquals(new String[] { "location2" }, serviceResource.getLocationIds());
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ServiceSecurityController method getAuthorizedGroups.
/**
* List all groups authorised to access the location.
*
* @return list of all authorised groups.
*/
@ApiOperation(value = "List all groups authorized to access the service resource", notes = "Only user with ADMIN role can list authorized groups to the location.")
@RequestMapping(value = "/groups", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<List<GroupDTO>> getAuthorizedGroups(@PathVariable String serviceId) {
ServiceResource service = serviceResourceService.getOrFail(serviceId);
List<GroupDTO> groups = GroupDTO.convert(resourcePermissionService.getAuthorizedGroups(service));
return RestResponseBuilder.<List<GroupDTO>>builder().data(groups).build();
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ServiceSecurityController method grantAccessToGroups.
/**
*****************************************************************************************************************************
*
* SECURITY ON GROUPS
*
******************************************************************************************************************************
*/
/**
* Grant access to the service resource to the groups (deploy on the location)
*
* @param serviceId The location's id.
* @param groupIds The authorized groups.
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Grant access to the service resource 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 serviceId, @RequestBody String[] groupIds) {
ServiceResource service = serviceResourceService.getOrFail(serviceId);
resourcePermissionService.grantPermission(service, Subject.GROUP, groupIds);
List<GroupDTO> groups = GroupDTO.convert(resourcePermissionService.getAuthorizedGroups(service));
return RestResponseBuilder.<List<GroupDTO>>builder().data(groups).build();
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ServiceSecurityController method updateAuthorizedEnvironmentsPerApplication.
/**
* Update applications, environments and environment types authorized to access the location.
*/
@ApiOperation(value = "Update applications, environments and environment types authorized to access the service resource", notes = "Only user with ADMIN role can update authorized applications, environments and environment types for the location.")
@RequestMapping(value = "/environmentsPerApplication", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public synchronized RestResponse<Void> updateAuthorizedEnvironmentsPerApplication(@PathVariable String serviceId, @RequestBody ApplicationEnvironmentAuthorizationUpdateRequest request) {
ServiceResource service = serviceResourceService.getOrFail(serviceId);
resourcePermissionService.revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication(service, request.getApplicationsToDelete(), request.getEnvironmentsToDelete(), request.getEnvironmentTypesToDelete());
resourcePermissionService.grantAuthorizedEnvironmentsAndEnvTypesPerApplication(service, request.getApplicationsToAdd(), request.getEnvironmentsToAdd(), request.getEnvironmentTypesToAdd());
return RestResponseBuilder.<Void>builder().build();
}
Aggregations