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