Search in sources :

Example 26 with ServiceResource

use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.

the class ServiceSecurityController method grantAccessToUsers.

/**
 *****************************************************************************************************************************
 *
 * SECURITY ON USERS
 *
 ******************************************************************************************************************************
 */
/**
 * Grant access to the location to the user (deploy on the location)
 *
 * @param serviceId The location's id.
 * @param userNames The authorized users.
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Grant access to the service 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 serviceId, @RequestBody String[] userNames) {
    ServiceResource service = serviceResourceService.getOrFail(serviceId);
    resourcePermissionService.grantPermission(service, Subject.USER, userNames);
    List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(service));
    return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
Also used : UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) 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 27 with ServiceResource

use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.

the class ServiceSecurityController method revokeGroupAccess.

/**
 * Revoke the group's authorisation to access the location
 *
 * @param serviceId The id of the location.
 * @param groupId The authorized group.
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Revoke the group's authorisation to access the service resource", notes = "Only user with ADMIN role can revoke access to the location.")
@RequestMapping(value = "/groups/{groupId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<GroupDTO>> revokeGroupAccess(@PathVariable String serviceId, @PathVariable String groupId) {
    ServiceResource service = serviceResourceService.getOrFail(serviceId);
    resourcePermissionService.revokePermission(service, Subject.GROUP, groupId);
    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 28 with ServiceResource

use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.

the class ServiceSecurityController method revokeUserAccess.

/**
 * Revoke the user's authorisation to access the location
 *
 * @param serviceId The id of the location.
 * @param username The authorized user.
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Revoke the user's authorisation to access the service resource, send back the new authorised users list", notes = "Only user with ADMIN role can revoke access to the location.")
@RequestMapping(value = "/users/{username}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<UserDTO>> revokeUserAccess(@PathVariable String serviceId, @PathVariable String username) {
    ServiceResource service = serviceResourceService.getOrFail(serviceId);
    resourcePermissionService.revokePermission(service, Subject.USER, username);
    List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(service));
    return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
Also used : UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) 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 29 with ServiceResource

use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.

the class ServiceSecurityController method revokeApplicationAccess.

/**
 *****************************************************************************************************************************
 *
 * SECURITY ON APPLICATIONS
 *
 ******************************************************************************************************************************
 */
/**
 * Revoke the application's authorisation to access the location (including all related environments and environment types).
 *
 * @param serviceId The id of the location.
 * @param applicationId The authorized application.
 * @return A {@link Void} {@link RestResponse}.
 */
@ApiOperation(value = "Revoke the application's authorisation to access the service resource", notes = "Only user with ADMIN role can revoke access to the location.")
@RequestMapping(value = "/applications/{applicationId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<Void> revokeApplicationAccess(@PathVariable String serviceId, @PathVariable String applicationId) {
    ServiceResource service = serviceResourceService.getOrFail(serviceId);
    resourcePermissionService.revokePermission(service, Subject.APPLICATION, applicationId);
    // remove all environments related to this application
    ApplicationEnvironment[] aes = applicationEnvironmentService.getByApplicationId(applicationId);
    String[] envIds = Arrays.stream(aes).map(ae -> ae.getId()).toArray(String[]::new);
    resourcePermissionService.revokePermission(service, Subject.ENVIRONMENT, envIds);
    // remove all environments types related to this application
    Set<String> envTypeIds = Sets.newHashSet();
    for (String envType : safe(service.getEnvironmentTypePermissions()).keySet()) {
        if (envType.contains(applicationId)) {
            envTypeIds.add(envType);
        }
    }
    resourcePermissionService.revokePermission(service, Subject.ENVIRONMENT_TYPE, envTypeIds.toArray(new String[envTypeIds.size()]));
    return RestResponseBuilder.<Void>builder().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) ServiceResourceService(org.alien4cloud.alm.service.ServiceResourceService) ResourcePermissionService(alien4cloud.authorization.ResourcePermissionService) ApplicationEnvironmentAuthorizationDTO(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) 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) Api(io.swagger.annotations.Api) 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) RestController(org.springframework.web.bind.annotation.RestController) 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) ApplicationEnvironmentAuthorizationUpdateRequest(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest) ServiceResource(alien4cloud.model.service.ServiceResource) ServiceResource(alien4cloud.model.service.ServiceResource) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Audit(alien4cloud.audit.annotation.Audit) 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