Search in sources :

Example 1 with ResourceNotFoundException

use of org.niis.xroad.restapi.openapi.ResourceNotFoundException in project X-Road by nordic-institute.

the class SecurityServersApiController method getSecurityServer.

@Override
@PreAuthorize("hasAuthority('INIT_CONFIG')")
public ResponseEntity<SecurityServer> getSecurityServer(String encodedSecurityServerId) {
    SecurityServerId securityServerId = securityServerConverter.convertId(encodedSecurityServerId);
    if (!globalConfService.securityServerExists(securityServerId)) {
        throw new ResourceNotFoundException("Security server " + encodedSecurityServerId + " not found");
    }
    SecurityServer securityServer = securityServerConverter.convert(securityServerId);
    return new ResponseEntity<>(securityServer, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SecurityServerId(ee.ria.xroad.common.identifier.SecurityServerId) SecurityServer(org.niis.xroad.securityserver.restapi.openapi.model.SecurityServer) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ResourceNotFoundException

use of org.niis.xroad.restapi.openapi.ResourceNotFoundException in project X-Road by nordic-institute.

the class ServiceDescriptionsApiController method disableServiceDescription.

@Override
@PreAuthorize("hasAuthority('ENABLE_DISABLE_WSDL')")
@AuditEventMethod(event = DISABLE_SERVICE_DESCRIPTION)
public ResponseEntity<Void> disableServiceDescription(String id, ServiceDescriptionDisabledNotice serviceDescriptionDisabledNotice) {
    String disabledNotice = null;
    if (serviceDescriptionDisabledNotice != null) {
        disabledNotice = serviceDescriptionDisabledNotice.getDisabledNotice();
    }
    Long serviceDescriptionId = FormatUtils.parseLongIdOrThrowNotFound(id);
    try {
        serviceDescriptionService.disableServices(serviceDescriptionId.longValue(), disabledNotice);
    } catch (ServiceDescriptionNotFoundException e) {
        throw new ResourceNotFoundException();
    }
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException) ServiceDescriptionNotFoundException(org.niis.xroad.securityserver.restapi.service.ServiceDescriptionNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AuditEventMethod(org.niis.xroad.restapi.config.audit.AuditEventMethod)

Example 3 with ResourceNotFoundException

use of org.niis.xroad.restapi.openapi.ResourceNotFoundException in project X-Road by nordic-institute.

the class ServiceDescriptionsApiController method refreshServiceDescription.

@Override
@PreAuthorize("hasAnyAuthority('REFRESH_WSDL', 'REFRESH_REST', 'REFRESH_OPENAPI3')")
@AuditEventMethod(event = REFRESH_SERVICE_DESCRIPTION)
public ResponseEntity<ServiceDescription> refreshServiceDescription(String id, IgnoreWarnings ignoreWarnings) {
    Long serviceDescriptionId = FormatUtils.parseLongIdOrThrowNotFound(id);
    ServiceDescription serviceDescription = null;
    try {
        serviceDescription = serviceDescriptionConverter.convert(serviceDescriptionService.refreshServiceDescription(serviceDescriptionId, ignoreWarnings.getIgnoreWarnings()));
    } catch (WsdlParser.WsdlNotFoundException | UnhandledWarningsException | InvalidUrlException | InvalidWsdlException | ServiceDescriptionService.WrongServiceDescriptionTypeException | OpenApiParser.ParsingException | InvalidServiceUrlException | UnsupportedOpenApiVersionException e) {
        throw new BadRequestException(e);
    } catch (ServiceDescriptionService.ServiceAlreadyExistsException | ServiceDescriptionService.WsdlUrlAlreadyExistsException e) {
        throw new ConflictException(e);
    } catch (ServiceDescriptionNotFoundException e) {
        throw new ResourceNotFoundException(e);
    } catch (InterruptedException e) {
        throw new InternalServerErrorException(new ErrorDeviation(ERROR_WSDL_VALIDATOR_INTERRUPTED));
    }
    return new ResponseEntity<>(serviceDescription, HttpStatus.OK);
}
Also used : ServiceDescription(org.niis.xroad.securityserver.restapi.openapi.model.ServiceDescription) InvalidUrlException(org.niis.xroad.securityserver.restapi.service.InvalidUrlException) ErrorDeviation(org.niis.xroad.restapi.exceptions.ErrorDeviation) InvalidServiceUrlException(org.niis.xroad.securityserver.restapi.service.InvalidServiceUrlException) ResponseEntity(org.springframework.http.ResponseEntity) UnhandledWarningsException(org.niis.xroad.restapi.service.UnhandledWarningsException) UnsupportedOpenApiVersionException(org.niis.xroad.securityserver.restapi.wsdl.UnsupportedOpenApiVersionException) BadRequestException(org.niis.xroad.restapi.openapi.BadRequestException) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException) InvalidWsdlException(org.niis.xroad.securityserver.restapi.wsdl.InvalidWsdlException) ServiceDescriptionNotFoundException(org.niis.xroad.securityserver.restapi.service.ServiceDescriptionNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AuditEventMethod(org.niis.xroad.restapi.config.audit.AuditEventMethod)

Example 4 with ResourceNotFoundException

use of org.niis.xroad.restapi.openapi.ResourceNotFoundException in project X-Road by nordic-institute.

the class ServicesApiController method getServiceType.

private ServiceType getServiceType(String id) {
    ClientId clientId = serviceConverter.parseClientId(id);
    String fullServiceCode = serviceConverter.parseFullServiceCode(id);
    try {
        return serviceService.getService(clientId, fullServiceCode);
    } catch (ServiceNotFoundException | ClientNotFoundException e) {
        throw new ResourceNotFoundException(e);
    }
}
Also used : ServiceClientNotFoundException(org.niis.xroad.securityserver.restapi.service.ServiceClientNotFoundException) ClientNotFoundException(org.niis.xroad.securityserver.restapi.service.ClientNotFoundException) ServiceNotFoundException(org.niis.xroad.securityserver.restapi.service.ServiceNotFoundException) ClientId(ee.ria.xroad.common.identifier.ClientId) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException)

Example 5 with ResourceNotFoundException

use of org.niis.xroad.restapi.openapi.ResourceNotFoundException in project X-Road by nordic-institute.

the class ServicesApiController method addServiceServiceClients.

@PreAuthorize("hasAuthority('EDIT_SERVICE_ACL')")
@Override
@AuditEventMethod(event = RestApiAuditEvent.ADD_SERVICE_ACCESS_RIGHTS)
public ResponseEntity<Set<ServiceClient>> addServiceServiceClients(String encodedServiceId, ServiceClients serviceClients) {
    ClientId clientId = serviceConverter.parseClientId(encodedServiceId);
    String fullServiceCode = serviceConverter.parseFullServiceCode(encodedServiceId);
    List<ServiceClientDto> serviceClientDtos;
    try {
        Set<XRoadId> xRoadIds = serviceClientHelper.processServiceClientXRoadIds(serviceClients);
        serviceClientDtos = accessRightService.addSoapServiceAccessRights(clientId, fullServiceCode, xRoadIds);
    } catch (ClientNotFoundException | ServiceNotFoundException e) {
        throw new ResourceNotFoundException(e);
    } catch (ServiceClientNotFoundException e) {
        throw new BadRequestException(e);
    } catch (AccessRightService.DuplicateAccessRightException e) {
        throw new ConflictException(e);
    } catch (ServiceClientIdentifierConverter.BadServiceClientIdentifierException e) {
        throw serviceClientHelper.wrapInBadRequestException(e);
    }
    Set<ServiceClient> serviceClientsResult = serviceClientConverter.convertServiceClientDtos(serviceClientDtos);
    return new ResponseEntity<>(serviceClientsResult, HttpStatus.OK);
}
Also used : ServiceClientDto(org.niis.xroad.securityserver.restapi.dto.ServiceClientDto) ServiceClientNotFoundException(org.niis.xroad.securityserver.restapi.service.ServiceClientNotFoundException) ClientNotFoundException(org.niis.xroad.securityserver.restapi.service.ClientNotFoundException) XRoadId(ee.ria.xroad.common.identifier.XRoadId) ServiceClientIdentifierConverter(org.niis.xroad.securityserver.restapi.converter.ServiceClientIdentifierConverter) ResponseEntity(org.springframework.http.ResponseEntity) ServiceNotFoundException(org.niis.xroad.securityserver.restapi.service.ServiceNotFoundException) ServiceClient(org.niis.xroad.securityserver.restapi.openapi.model.ServiceClient) ServiceClientNotFoundException(org.niis.xroad.securityserver.restapi.service.ServiceClientNotFoundException) AccessRightService(org.niis.xroad.securityserver.restapi.service.AccessRightService) ClientId(ee.ria.xroad.common.identifier.ClientId) BadRequestException(org.niis.xroad.restapi.openapi.BadRequestException) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AuditEventMethod(org.niis.xroad.restapi.config.audit.AuditEventMethod)

Aggregations

ResourceNotFoundException (org.niis.xroad.restapi.openapi.ResourceNotFoundException)53 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)37 ResponseEntity (org.springframework.http.ResponseEntity)30 ClientNotFoundException (org.niis.xroad.securityserver.restapi.service.ClientNotFoundException)24 ClientId (ee.ria.xroad.common.identifier.ClientId)22 AuditEventMethod (org.niis.xroad.restapi.config.audit.AuditEventMethod)22 BadRequestException (org.niis.xroad.restapi.openapi.BadRequestException)20 ServiceClientNotFoundException (org.niis.xroad.securityserver.restapi.service.ServiceClientNotFoundException)20 Test (org.junit.Test)12 WithMockUser (org.springframework.security.test.context.support.WithMockUser)12 ServiceClient (org.niis.xroad.securityserver.restapi.openapi.model.ServiceClient)11 XRoadId (ee.ria.xroad.common.identifier.XRoadId)8 ServiceClientIdentifierConverter (org.niis.xroad.securityserver.restapi.converter.ServiceClientIdentifierConverter)8 ActionNotPossibleException (org.niis.xroad.securityserver.restapi.service.ActionNotPossibleException)8 ServiceNotFoundException (org.niis.xroad.securityserver.restapi.service.ServiceNotFoundException)7 WsdlValidatorTest (org.niis.xroad.securityserver.restapi.wsdl.WsdlValidatorTest)6 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)5 ErrorDeviation (org.niis.xroad.restapi.exceptions.ErrorDeviation)5 ServiceClientDto (org.niis.xroad.securityserver.restapi.dto.ServiceClientDto)5 ServiceDescription (org.niis.xroad.securityserver.restapi.openapi.model.ServiceDescription)5