Search in sources :

Example 1 with ServiceResource

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);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ServiceResource(alien4cloud.model.service.ServiceResource) NodeInstance(org.alien4cloud.tosca.model.instances.NodeInstance) Test(org.junit.Test)

Example 2 with ServiceResource

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());
}
Also used : ServiceResource(alien4cloud.model.service.ServiceResource) AfterLocationDeleted(alien4cloud.orchestrators.locations.events.AfterLocationDeleted) Test(org.junit.Test)

Example 3 with ServiceResource

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();
}
Also used : GroupDTO(alien4cloud.rest.orchestrator.model.GroupDTO) ServiceResource(alien4cloud.model.service.ServiceResource) List(java.util.List) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ServiceResource

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();
}
Also used : GroupDTO(alien4cloud.rest.orchestrator.model.GroupDTO) ServiceResource(alien4cloud.model.service.ServiceResource) List(java.util.List) 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 5 with ServiceResource

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();
}
Also used : ServiceResource(alien4cloud.model.service.ServiceResource) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ServiceResource (alien4cloud.model.service.ServiceResource)29 ApiOperation (io.swagger.annotations.ApiOperation)9 List (java.util.List)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Audit (alien4cloud.audit.annotation.Audit)6 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)5 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)5 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)4 Application (alien4cloud.model.application.Application)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 EventListener (org.springframework.context.event.EventListener)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 Usage (alien4cloud.model.common.Usage)2 Deployment (alien4cloud.model.deployment.Deployment)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2