Search in sources :

Example 1 with EntityNotFoundException

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

the class AbstractReadWriteDtoController method patch.

/**
 * Patch is not implemented yet
 *
 * @param backendId
 * @param nativeRequest
 * @return
 * @throws HttpMessageNotReadableException
 */
public ResponseEntity<?> patch(String backendId, HttpServletRequest nativeRequest) throws HttpMessageNotReadableException {
    DTO updateDto = getDto(backendId);
    if (updateDto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    // 
    ServletServerHttpRequest request = new ServletServerHttpRequest(nativeRequest);
    try {
        modelMapper.map(getMapper().readerForUpdating(updateDto).readValue(request.getBody()), updateDto);
    } catch (IOException ex) {
        throw new ResultCodeException(CoreResultCode.BAD_REQUEST, ex);
    }
    updateDto = patchDto(updateDto);
    return new ResponseEntity<>(toResource(updateDto), HttpStatus.OK);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IOException(java.io.IOException)

Example 2 with EntityNotFoundException

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

the class AbstractReadDtoController method get.

/**
 * Returns response DTO by given backendId
 *
 * @param backendId
 * @return
 */
@ApiOperation(value = "Read record", authorizations = { @Authorization(SwaggerConfig.AUTHENTICATION_BASIC), @Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public ResponseEntity<?> get(@ApiParam(value = "Record's uuid identifier or unique code, if record supports Codeable interface.", required = true) @PathVariable @NotNull String backendId) {
    DTO dto = getDto(backendId);
    if (dto == null) {
        throw new EntityNotFoundException(getService().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) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with EntityNotFoundException

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

the class IdmRoleRequestController method get.

@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_READ + "')")
@ApiOperation(value = "Role request detail. Returns request doesn't contains concepts (from version 9.7.0!).", nickname = "getRoleRequest", response = IdmRoleRequestDto.class, tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }) })
public ResponseEntity<?> get(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    // 
    IdmRoleRequestFilter filter = new IdmRoleRequestFilter();
    filter.setIncludeApprovers(true);
    IdmRoleRequestDto requestDto = getService().get(backendId, filter, IdmBasePermission.READ);
    if (requestDto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    ResourceSupport resource = toResource(requestDto);
    if (resource == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    return new ResponseEntity<>(resource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ResourceSupport(org.springframework.hateoas.ResourceSupport) 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 4 with EntityNotFoundException

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

the class IdmProfileController method twoFactorConfirm.

@ResponseBody
@ApiOperation(value = "Login - additional two factor authentication confirm", notes = "Additional two factor authentication with TOTP verification code.", response = IdmProfileDto.class, tags = { IdmProfileController.TAG })
@RequestMapping(path = "/{backendId}/two-factor/confirm", method = RequestMethod.PUT)
public ResponseEntity<?> twoFactorConfirm(@ApiParam(value = "Profile's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Verification secret and code.", required = true) @Valid @RequestBody(required = true) TwoFactorRegistrationConfirmDto registrationConfirm) {
    IdmProfileDto dto = getDto(backendId);
    if (dto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    // 
    twoFactorAuthenticationManager.confirm(dto.getIdentity(), registrationConfirm);
    // 
    return new ResponseEntity<>(toResource(getDto(dto)), HttpStatus.OK);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) ResponseEntity(org.springframework.http.ResponseEntity) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with EntityNotFoundException

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

the class SysRemoteServerController method getConnectorFrameworks.

/**
 * Return available connector frameworks with connectors on remote connector server.
 */
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/frameworks")
@PreAuthorize("hasAuthority('" + AccGroupPermission.REMOTESERVER_READ + "')")
@ApiOperation(value = "Get available connectors", nickname = "getAvailableConnectors", tags = { SysRemoteServerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }) }, notes = "Available connector frameworks with connectors on remote connector server.")
public ResponseEntity<Map<String, Set<IcConnectorInfo>>> getConnectorFrameworks(@ApiParam(value = "Remote server uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
    SysConnectorServerDto connectorServer = getDto(backendId);
    if (connectorServer == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    Map<String, Set<IcConnectorInfo>> infos = new HashMap<>();
    // 
    try {
        for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
            connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
            infos.put(config.getFramework(), config.getAvailableRemoteConnectors(connectorServer));
        }
    } catch (IcInvalidCredentialException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcServerNotFoundException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcCantConnectException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcRemoteServerException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    }
    // 
    return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ResponseEntity(org.springframework.http.ResponseEntity) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) 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