Search in sources :

Example 21 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class IdmIdentityController method getProfilePermissions.

/**
 * Returns profile permissions
 *
 * @return
 * @since 9.0.0
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/profile/permissions", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PROFILE_READ + "')" + " or hasAuthority('" + CoreGroupPermission.PROFILE_AUTOCOMPLETE + "')")
@ApiOperation(value = "What logged identity can do with identity profile", nickname = "getPermissionsOnIdentityProfile", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_READ, description = ""), @AuthorizationScope(scope = CoreGroupPermission.PROFILE_AUTOCOMPLETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_READ, description = ""), @AuthorizationScope(scope = CoreGroupPermission.PROFILE_AUTOCOMPLETE, description = "") }) })
public Set<String> getProfilePermissions(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId) {
    IdmProfileDto profile = profileService.findOneByIdentity(backendId);
    if (profile == null) {
        IdmIdentityDto identity = (IdmIdentityDto) getLookupService().lookupDto(IdmIdentityDto.class, backendId);
        if (identity == null) {
            throw new EntityNotFoundException(IdmIdentity.class, backendId);
        }
        profile = new IdmProfileDto();
        profile.setIdentity(identity.getId());
    }
    // profile can be null (create)
    return profileController.getService().getPermissions(profile);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class IdmRoleRequestController method delete.

@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_DELETE + "')")
@ApiOperation(value = "Delete role request", nickname = "deleteRoleRequest", tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmRoleRequestDto dto = getDto(backendId);
    if (dto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    checkAccess(dto, IdmBasePermission.DELETE);
    IdmBulkActionDto deleteAction = getAvailableBulkActions().stream().filter(action -> {
        return RoleRequestDeleteBulkAction.NAME.equals(action.getName());
    }).findFirst().get();
    deleteAction.setIdentifiers(Set.of(dto.getId()));
    bulkAction(deleteAction);
    return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class DefaultLongRunningTaskManager method processCreated.

@Override
@Transactional
public LongRunningFutureTask<?> processCreated(UUID longRunningTaskId) {
    LOG.debug("Processing created task [{}] from long running task queue", longRunningTaskId);
    // 
    IdmLongRunningTaskDto task = service.get(longRunningTaskId);
    if (task == null) {
        throw new EntityNotFoundException(IdmLongRunningTask.class, longRunningTaskId);
    }
    // task cannot be started twice
    if (task.isRunning() || OperationState.RUNNING == task.getResultState()) {
        throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_RUNNING, ImmutableMap.of("taskId", task.getId()));
    }
    if (OperationState.CREATED != task.getResultState()) {
        throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_PROCESSED, ImmutableMap.of("taskId", task.getId()));
    }
    // 
    LongRunningTaskExecutor<?> taskExecutor = createTaskExecutor(task);
    if (taskExecutor == null) {
        return null;
    }
    return execute(taskExecutor);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class IdmIdentityProjectionController method get.

@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity projection detail", nickname = "getIdentityProjection", response = IdmIdentityProjectionDto.class, tags = { IdmIdentityProjectionController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> get(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId) {
    IdmIdentityProjectionDto dto = getDto(backendId);
    if (dto == null) {
        throw new EntityNotFoundException(identityService.getEntityClass(), backendId);
    }
    ResourceSupport resource = toResource(dto);
    if (resource == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    // 
    return new ResponseEntity<>(resource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ResourceSupport(org.springframework.hateoas.ResourceSupport) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class IdmLongRunningTaskController method downloadResult.

@ResponseBody
@RequestMapping(value = "/{backendId}/download/{attachmentId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.SCHEDULER_READ + "')")
@ApiOperation(value = "Download result from LRT", nickname = "downloadReslut", response = IdmLongRunningTaskDto.class, tags = { IdmLongRunningTaskController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }) })
public ResponseEntity<?> downloadResult(@ApiParam(value = "LRT's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Attachment's id.", required = true) @PathVariable @NotNull String attachmentId) {
    // check if user has permission for read the long running task
    IdmLongRunningTaskDto longRunningTaskDto = getDto(backendId);
    if (longRunningTaskDto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    // 
    IdmAttachmentDto attachment = longRunningTaskManager.getAttachment(longRunningTaskDto.getId(), DtoUtils.toUuid(attachmentId), IdmBasePermission.READ);
    InputStream is = attachmentManager.getAttachmentData(attachment.getId(), IdmBasePermission.READ);
    String attachmentName = attachment.getName();
    // 
    return ResponseEntity.ok().contentLength(attachment.getFilesize()).contentType(MediaType.parseMediaType(attachment.getMimetype())).header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"", attachmentName)).body(new InputStreamResource(is));
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) InputStream(java.io.InputStream) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)30 ApiOperation (io.swagger.annotations.ApiOperation)15 ResponseEntity (org.springframework.http.ResponseEntity)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 UUID (java.util.UUID)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 ResourceSupport (org.springframework.hateoas.ResourceSupport)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 Transactional (org.springframework.transaction.annotation.Transactional)5 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)4 IOException (java.io.IOException)4 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)3 IdmProfileDto (eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)3 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)3 IdmTokenDto (eu.bcvsolutions.idm.core.api.dto.IdmTokenDto)3 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)3 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)3