Search in sources :

Example 1 with UserDTO

use of alien4cloud.rest.orchestrator.model.UserDTO in project alien4cloud by alien4cloud.

the class ServiceSecurityController method getAuthorizedUsers.

/**
 * List all users authorised to access the location.
 *
 * @return list of all users.
 */
@ApiOperation(value = "List all users authorized to access the service resource", notes = "Only user with ADMIN role can list authorized users to the location.")
@RequestMapping(value = "/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<List<UserDTO>> getAuthorizedUsers(@PathVariable String serviceId) {
    ServiceResource service = serviceResourceService.getOrFail(serviceId);
    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) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserDTO

use of alien4cloud.rest.orchestrator.model.UserDTO in project alien4cloud by alien4cloud.

the class LocationSecurityController method grantAccessToUsers.

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

use of alien4cloud.rest.orchestrator.model.UserDTO 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();
}
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) LocationService(alien4cloud.orchestrators.locations.services.LocationService) ResourcePermissionService(alien4cloud.authorization.ResourcePermissionService) ApplicationEnvironmentAuthorizationDTO(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) LocationSecurityService(alien4cloud.orchestrators.locations.services.LocationSecurityService) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) 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) ILocationResourceService(alien4cloud.orchestrators.locations.services.ILocationResourceService) MapUtils(org.apache.commons.collections4.MapUtils) 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) 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) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) ApplicationEnvironmentAuthorizationUpdateRequest(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest) UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) List(java.util.List) Location(alien4cloud.model.orchestrators.locations.Location) 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 4 with UserDTO

use of alien4cloud.rest.orchestrator.model.UserDTO in project alien4cloud by alien4cloud.

the class LocationSecurityController method revokeUserAccess.

/**
 * Revoke the user's authorisation to access the location
 *
 * @param locationId 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 location, 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 orchestratorId, @PathVariable String locationId, @PathVariable String username) {
    Location location = locationService.getLocation(orchestratorId, locationId);
    resourcePermissionService.revokePermission(location, Subject.USER, username);
    List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(location));
    return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
Also used : UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) List(java.util.List) Location(alien4cloud.model.orchestrators.locations.Location) 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 UserDTO

use of alien4cloud.rest.orchestrator.model.UserDTO in project alien4cloud by alien4cloud.

the class LocationSecurityController method getAuthorizedUsers.

/**
 * List all users authorised to access the location.
 *
 * @return list of all users.
 */
@ApiOperation(value = "List all users authorized to access the location", notes = "Only user with ADMIN role can list authorized users to the location.")
@RequestMapping(value = "/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<List<UserDTO>> getAuthorizedUsers(@PathVariable String orchestratorId, @PathVariable String locationId) {
    Location location = locationService.getLocation(orchestratorId, locationId);
    List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(location));
    return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
Also used : UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) List(java.util.List) Location(alien4cloud.model.orchestrators.locations.Location) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)9 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 Location (alien4cloud.model.orchestrators.locations.Location)5 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)3 ServiceResource (alien4cloud.model.service.ServiceResource)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 Application (alien4cloud.model.application.Application)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 ILocationResourceService (alien4cloud.orchestrators.locations.services.ILocationResourceService)2 LocationSecurityService (alien4cloud.orchestrators.locations.services.LocationSecurityService)2 LocationService (alien4cloud.orchestrators.locations.services.LocationService)2 RestResponse (alien4cloud.rest.model.RestResponse)2 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)2 ApplicationEnvironmentAuthorizationDTO (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO)2