Search in sources :

Example 1 with TrustAnchorResource

use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.

the class TrustAnchorControllerTest method should_fail_on_invalid_request.

@Test
public void should_fail_on_invalid_request() throws Exception {
    ResultActions result = mvc.perform(post("/api/trust-anchors").accept(Api.API_MIME_TYPE).contentType(Api.API_MIME_TYPE).content(objectMapper.writeValueAsString(ApiCommand.of(AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(TEST_CA_NAME).locations(Arrays.asList("invalid-location")).subjectPublicKeyInfo("public key info too short").build()))));
    result.andExpect(status().isBadRequest()).andExpect(content().contentType(Api.API_MIME_TYPE));
    ApiResponse<TrustAnchorResource> response = addTrustAnchorResponse(result);
    assertThat(response.getErrors()).isNotEmpty();
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) IntegrationTest(net.ripe.rpki.validator3.IntegrationTest)

Example 2 with TrustAnchorResource

use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.

the class TrustAnchorControllerTest method should_add_trust_anchor.

@Test
public void should_add_trust_anchor() throws Exception {
    ResultActions result = mvc.perform(post("/api/trust-anchors").accept(Api.API_MIME_TYPE).contentType(Api.API_MIME_TYPE).content(objectMapper.writeValueAsString(ApiCommand.of(AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(TEST_CA_NAME).locations(Arrays.asList("rsync://example.com/rpki")).subjectPublicKeyInfo("jdfakljkldf;adsfjkdsfkl;nasdjfnsldajfklsd;ajfk;ljdsakjfkla;sdhfkjdshfkljadsl;kjfdklfjdaksl;jdfkl;jafkldjsfkl;adjsfkl;adjsf;lkjkl;dj;adskjfdljadjbkfbkjblafkjdfbasfjlka").build()))));
    result.andExpect(status().isCreated()).andExpect(content().contentType(Api.API_MIME_TYPE));
    ApiResponse<TrustAnchorResource> response = addTrustAnchorResponse(result);
    assertThat(response.getData()).isNotNull();
    TrustAnchorResource resource = response.getData();
    Link selfRel = resource.getLinks().getLink("self");
    mvc.perform(get(selfRel.getHref()).accept(Api.API_MIME_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(Api.API_MIME_TYPE)).andExpect(jsonPath("$.data.name").value(TEST_CA_NAME));
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions) Link(org.springframework.hateoas.Link) Test(org.junit.Test) IntegrationTest(net.ripe.rpki.validator3.IntegrationTest)

Example 3 with TrustAnchorResource

use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.

the class TrustAnchorController method add.

@PostMapping(path = "/upload", consumes = "multipart/form-data")
public ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestParam("file") MultipartFile trustAnchorLocator, Locale locale) {
    try {
        TrustAnchorLocator locator = TrustAnchorLocator.fromMultipartFile(trustAnchorLocator);
        AddTrustAnchor command = AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(locator.getCaName()).locations(locator.getCertificateLocations().stream().map(URI::toASCIIString).collect(Collectors.toList())).subjectPublicKeyInfo(locator.getPublicKeyInfo()).rsyncPrefetchUri(locator.getPrefetchUris().stream().filter(uri -> "rsync".equalsIgnoreCase(uri.getScheme())).map(URI::toASCIIString).findFirst().orElse(null)).build();
        long id = trustAnchorService.execute(command);
        TrustAnchor trustAnchor = trustAnchorRepository.get(id);
        Link selfRel = linkTo(methodOn(TrustAnchorController.class).get(id, locale)).withSelfRel();
        return ResponseEntity.created(URI.create(selfRel.getHref())).body(trustAnchorResource(trustAnchor, locale));
    } catch (TrustAnchorExtractorException ex) {
        return ResponseEntity.badRequest().body(ApiResponse.error(ApiError.of(HttpStatus.BAD_REQUEST, "Invalid trust anchor locator: " + ex.getMessage())));
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) StringUtils(org.apache.commons.lang.StringUtils) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) Valid(javax.validation.Valid) Paging(net.ripe.rpki.validator3.api.Paging) RpkiRepositories(net.ripe.rpki.validator3.domain.RpkiRepositories) Api(net.ripe.rpki.validator3.api.Api) Locale(java.util.Locale) ValidationRunController(net.ripe.rpki.validator3.api.validationruns.ValidationRunController) TrustAnchorExtractorException(net.ripe.rpki.validator3.util.TrustAnchorExtractorException) URI(java.net.URI) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) TrustAnchorLocator(net.ripe.rpki.validator3.util.TrustAnchorLocator) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) PostMapping(org.springframework.web.bind.annotation.PostMapping) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) ValidationRun(net.ripe.rpki.validator3.domain.ValidationRun) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ValidationRuns(net.ripe.rpki.validator3.domain.ValidationRuns) Links(org.springframework.hateoas.Links) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Metadata(net.ripe.rpki.validator3.api.Metadata) ArrayList(java.util.ArrayList) Sorting(net.ripe.rpki.validator3.api.Sorting) RequestBody(org.springframework.web.bind.annotation.RequestBody) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) GetMapping(org.springframework.web.bind.annotation.GetMapping) TrustAnchorValidationRun(net.ripe.rpki.validator3.domain.TrustAnchorValidationRun) MessageSource(org.springframework.context.MessageSource) ValidationCheckResource(net.ripe.rpki.validator3.api.validationruns.ValidationCheckResource) Link(org.springframework.hateoas.Link) ApiError(net.ripe.rpki.validator3.api.ApiError) TrustAnchors(net.ripe.rpki.validator3.domain.TrustAnchors) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) HttpStatus(org.springframework.http.HttpStatus) ApiCommand(net.ripe.rpki.validator3.api.ApiCommand) ValidationRunResource(net.ripe.rpki.validator3.api.validationruns.ValidationRunResource) SearchTerm(net.ripe.rpki.validator3.api.SearchTerm) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) ApiResponse(net.ripe.rpki.validator3.api.ApiResponse) TrustAnchorExtractorException(net.ripe.rpki.validator3.util.TrustAnchorExtractorException) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) TrustAnchorLocator(net.ripe.rpki.validator3.util.TrustAnchorLocator) URI(java.net.URI) Link(org.springframework.hateoas.Link) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with TrustAnchorResource

use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.

the class ObjectController method list.

@GetMapping(path = "/validated")
public ResponseEntity<ApiResponse<ValidatedObjects>> list(Locale locale) {
    final Map<Long, TrustAnchorResource> trustAnchorsById = trustAnchors.findAll().stream().collect(Collectors.toMap(TrustAnchor::getId, ta -> TrustAnchorResource.of(ta, locale)));
    final Map<Long, Links> trustAnchorLinks = trustAnchorsById.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> new Links(entry.getValue().getLinks().getLink("self").withRel(TrustAnchor.TYPE))));
    final Stream<RoaPrefix> validatedPrefixes = validatedRpkiObjects.findCurrentlyValidatedRoaPrefixes(null, null, null).getObjects().filter(new IgnoreFiltersPredicate(ignoreFilters.all()).negate()).map(prefix -> {
        Links links = trustAnchorLinks.get(prefix.getTrustAnchor().getId());
        return new RoaPrefix(String.valueOf(prefix.getAsn()), prefix.getPrefix().toString(), prefix.getEffectiveLength(), links);
    });
    final Stream<RoaPrefix> assertions = roaPrefixAssertions.all().map(assertion -> new RoaPrefix(new Asn(assertion.getAsn()).toString(), IpRange.parse(assertion.getPrefix()).toString(), assertion.getMaximumLength() != null ? assertion.getMaximumLength() : IpRange.parse(assertion.getPrefix()).getPrefixLength(), null));
    final Stream<RoaPrefix> combinedPrefixes = Stream.concat(validatedPrefixes, assertions).distinct();
    final Stream<ValidatedRpkiObjects.RouterCertificate> certificates = validatedRpkiObjects.findCurrentlyValidatedRouterCertificates().getObjects();
    final Stream<RouterCertificate> filteredRouterCertificates = bgpSecFilterService.filterCertificates(certificates).map(o -> new RouterCertificate(o.getAsn(), o.getSubjectKeyIdentifier(), o.getSubjectPublicKeyInfo()));
    final Stream<RouterCertificate> bgpSecAssertions = this.bgpSecAssertions.all().map(b -> {
        final List<String> asns = Collections.singletonList(String.valueOf(b.getAsn()));
        return new RouterCertificate(asns, b.getSki(), b.getPublicKey());
    });
    final Stream<RouterCertificate> combinedAssertions = Stream.concat(filteredRouterCertificates, bgpSecAssertions).distinct();
    return ResponseEntity.ok(ApiResponse.<ValidatedObjects>builder().data(new ValidatedObjects(settings.isInitialValidationRunCompleted(), trustAnchorsById.values(), combinedPrefixes, combinedAssertions)).build());
}
Also used : Links(org.springframework.hateoas.Links) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) BgpSecFilterService(net.ripe.rpki.validator3.api.bgpsec.BgpSecFilterService) Value(lombok.Value) Asn(net.ripe.ipresource.Asn) TrustAnchorResource(net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource) Api(net.ripe.rpki.validator3.api.Api) RpkiObjects(net.ripe.rpki.validator3.domain.RpkiObjects) Locale(java.util.Locale) Map(java.util.Map) RoaPrefixAssertions(net.ripe.rpki.validator3.domain.RoaPrefixAssertions) GetMapping(org.springframework.web.bind.annotation.GetMapping) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) ValidatedRpkiObjects(net.ripe.rpki.validator3.domain.ValidatedRpkiObjects) IpRange(net.ripe.ipresource.IpRange) TrustAnchors(net.ripe.rpki.validator3.domain.TrustAnchors) Collection(java.util.Collection) IgnoreFilters(net.ripe.rpki.validator3.domain.IgnoreFilters) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) BgpSecAssertions(net.ripe.rpki.validator3.domain.BgpSecAssertions) IgnoreFiltersPredicate(net.ripe.rpki.validator3.domain.IgnoreFiltersPredicate) Settings(net.ripe.rpki.validator3.domain.Settings) ResponseEntity(org.springframework.http.ResponseEntity) ApiResponse(net.ripe.rpki.validator3.api.ApiResponse) Collections(java.util.Collections) ApiModelProperty(io.swagger.annotations.ApiModelProperty) IgnoreFiltersPredicate(net.ripe.rpki.validator3.domain.IgnoreFiltersPredicate) Links(org.springframework.hateoas.Links) Asn(net.ripe.ipresource.Asn) TrustAnchorResource(net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with TrustAnchorResource

use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.

the class TrustAnchorController method add.

@PostMapping(consumes = { Api.API_MIME_TYPE, "application/json" })
public ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestBody @Valid ApiCommand<AddTrustAnchor> command, Locale locale) {
    long id = trustAnchorService.execute(command.getData());
    TrustAnchor trustAnchor = trustAnchorRepository.get(id);
    Link selfRel = linkTo(methodOn(TrustAnchorController.class).get(id, locale)).withSelfRel();
    return ResponseEntity.created(URI.create(selfRel.getHref())).body(trustAnchorResource(trustAnchor, locale));
}
Also used : TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) Link(org.springframework.hateoas.Link) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

TrustAnchor (net.ripe.rpki.validator3.domain.TrustAnchor)3 Link (org.springframework.hateoas.Link)3 List (java.util.List)2 Locale (java.util.Locale)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Slf4j (lombok.extern.slf4j.Slf4j)2 IntegrationTest (net.ripe.rpki.validator3.IntegrationTest)2 Api (net.ripe.rpki.validator3.api.Api)2 ApiResponse (net.ripe.rpki.validator3.api.ApiResponse)2 TrustAnchors (net.ripe.rpki.validator3.domain.TrustAnchors)2 Test (org.junit.Test)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Links (org.springframework.hateoas.Links)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 ApiModelProperty (io.swagger.annotations.ApiModelProperty)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1