Search in sources :

Example 76 with Transactional

use of javax.transaction.Transactional in project rpki-validator-3 by RIPE-NCC.

the class CertificateTreeValidationService method validate.

@Transactional(Transactional.TxType.REQUIRED)
public void validate(long trustAnchorId) {
    Map<URI, RpkiRepository> registeredRepositories = new HashMap<>();
    entityManager.setFlushMode(FlushModeType.COMMIT);
    TrustAnchor trustAnchor = trustAnchors.get(trustAnchorId);
    log.info("starting tree validation for {}", trustAnchor);
    CertificateTreeValidationRun validationRun = new CertificateTreeValidationRun(trustAnchor);
    validationRuns.add(validationRun);
    String trustAnchorLocation = trustAnchor.getLocations().get(0);
    ValidationResult validationResult = ValidationResult.withLocation(trustAnchorLocation);
    try {
        X509ResourceCertificate certificate = trustAnchor.getCertificate();
        validationResult.rejectIfNull(certificate, VALIDATOR_TRUST_ANCHOR_CERTIFICATE_AVAILABLE);
        if (certificate == null) {
            return;
        }
        CertificateRepositoryObjectValidationContext context = new CertificateRepositoryObjectValidationContext(URI.create(trustAnchorLocation), certificate);
        certificate.validate(trustAnchorLocation, context, null, null, VALIDATION_OPTIONS, validationResult);
        if (validationResult.hasFailureForCurrentLocation()) {
            return;
        }
        URI locationUri = Objects.firstNonNull(certificate.getRrdpNotifyUri(), certificate.getRepositoryUri());
        validationResult.warnIfNull(locationUri, VALIDATOR_TRUST_ANCHOR_CERTIFICATE_RRDP_NOTIFY_URI_OR_REPOSITORY_URI_PRESENT);
        if (locationUri == null) {
            return;
        }
        validationRun.getValidatedObjects().addAll(validateCertificateAuthority(trustAnchor, registeredRepositories, context, validationResult));
        entityManager.setFlushMode(FlushModeType.AUTO);
        if (isValidationRunCompleted(validationResult)) {
            trustAnchor.markInitialCertificateTreeValidationRunCompleted();
            if (!settings.isInitialValidationRunCompleted() && trustAnchors.allInitialCertificateTreeValidationRunsCompleted()) {
                settings.markInitialValidationRunCompleted();
                log.info("All trust anchors have completed their initial certificate tree validation run, validator is now ready");
            }
        }
        validatedRpkiObjects.update(trustAnchor, validationRun.getValidatedObjects());
    } finally {
        validationRun.completeWith(validationResult);
        log.info("tree validation {} for {}", validationRun.getStatus(), trustAnchor);
    }
}
Also used : CertificateRepositoryObjectValidationContext(net.ripe.rpki.commons.validation.objectvalidators.CertificateRepositoryObjectValidationContext) RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CertificateTreeValidationRun(net.ripe.rpki.validator3.domain.CertificateTreeValidationRun) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) ValidationString(net.ripe.rpki.commons.validation.ValidationString) X509ResourceCertificate(net.ripe.rpki.commons.crypto.x509cert.X509ResourceCertificate) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult) URI(java.net.URI) Transactional(javax.transaction.Transactional)

Example 77 with Transactional

use of javax.transaction.Transactional in project rpki-validator-3 by RIPE-NCC.

the class SlurmService method process.

@Transactional(Transactional.TxType.REQUIRED)
public void process(final Slurm slurm) {
    if (slurm.getLocallyAddedAssertions() != null && slurm.getLocallyAddedAssertions().getPrefixAssertions() != null) {
        roaPrefixAssertionsService.clear();
        slurm.getLocallyAddedAssertions().getPrefixAssertions().forEach(prefixAsertion -> {
            final AddRoaPrefixAssertion add = AddRoaPrefixAssertion.builder().asn(prefixAsertion.getAsn() == null ? null : prefixAsertion.getAsn().toString()).prefix(prefixAsertion.getPrefix()).maximumLength(prefixAsertion.getMaxPrefixLength()).comment(prefixAsertion.getComment()).build();
            roaPrefixAssertionsService.execute(add);
        });
    }
    if (slurm.getValidationOutputFilters() != null && slurm.getValidationOutputFilters().getPrefixFilters() != null) {
        ignoreFilterService.clear();
        slurm.getValidationOutputFilters().getPrefixFilters().forEach(prefixFilter -> {
            final AddIgnoreFilter addIgnoreFilter = AddIgnoreFilter.builder().asn(prefixFilter.getAsn() == null ? null : prefixFilter.getAsn().toString()).prefix(prefixFilter.getPrefix()).comment(prefixFilter.getComment()).build();
            ignoreFilterService.execute(addIgnoreFilter);
        });
    }
    if (slurm.getLocallyAddedAssertions() != null && slurm.getLocallyAddedAssertions().getBgpsecAssertions() != null) {
        bgpSecAssertionsService.clear();
        slurm.getLocallyAddedAssertions().getBgpsecAssertions().forEach(bgpSecAssertion -> {
            AddBgpSecAssertion add = AddBgpSecAssertion.builder().asn(bgpSecAssertion.getAsn() == null ? null : bgpSecAssertion.getAsn().toString()).publicKey(bgpSecAssertion.getPublicKey()).ski(bgpSecAssertion.getSki()).comment(bgpSecAssertion.getComment()).build();
            bgpSecAssertionsService.execute(add);
        });
    }
    if (slurm.getValidationOutputFilters() != null && slurm.getValidationOutputFilters().getBgpsecFilters() != null) {
        bgpSecFilterService.clear();
        slurm.getValidationOutputFilters().getBgpsecFilters().forEach(bgpSecFilter -> {
            AddBgpSecFilter add = AddBgpSecFilter.builder().asn(bgpSecFilter.getAsn() == null ? null : bgpSecFilter.getAsn().toString()).routerSki(bgpSecFilter.getRouterSKI()).comment(bgpSecFilter.getComment()).build();
            bgpSecFilterService.execute(add);
        });
    }
}
Also used : AddBgpSecFilter(net.ripe.rpki.validator3.api.bgpsec.AddBgpSecFilter) AddRoaPrefixAssertion(net.ripe.rpki.validator3.api.roaprefixassertions.AddRoaPrefixAssertion) AddIgnoreFilter(net.ripe.rpki.validator3.api.ignorefilters.AddIgnoreFilter) AddBgpSecAssertion(net.ripe.rpki.validator3.api.bgpsec.AddBgpSecAssertion) Transactional(javax.transaction.Transactional)

Example 78 with Transactional

use of javax.transaction.Transactional in project neubbs by nuitcoder.

the class FileControllerTest method testUploadUserAvatarException.

/**
 * 测试 /api/file/avatar
 *      - 测试上传用户头像异常
 *          - no permission
 *              - [✔] no login
 *              - [✔] the account not activated
 *          - [✔] upload file format incorrect (no norm)
 */
@Test
@Transactional
public void testUploadUserAvatarException() throws Exception {
    // no login
    util.testApiThrowNoPermissionException("/api/file/avatar", RequestMethod.POST, null);
    // the account not activated
    util.testApiThrowNoPermissionException("/api/file/avatar", RequestMethod.POST, util.getNoActivatedUserDO());
    // upload file format incorrect
    String htmlInputName = "avatarImageFile";
    String fileName = "testAvatarFile.jpg";
    String fileType = "image/jpg";
    byte[] fileBytes = new byte[1024 * 1024 * 1];
    MockMultipartFile[] files = { new MockMultipartFile(htmlInputName, fileName, fileType, new byte[0]), new MockMultipartFile(htmlInputName, "exceptionImage.ps", "image/ps", fileBytes), new MockMultipartFile(htmlInputName, "exceptionImage.jpg", "jpg", fileBytes), new MockMultipartFile(htmlInputName, "exceptionImage.avi", "avi", fileBytes), new MockMultipartFile(htmlInputName, fileName, fileType, new byte[1024 * 1024 * 6]) };
    for (MockMultipartFile file : files) {
        try {
            mockMvc.perform(MockMvcRequestBuilders.fileUpload("/api/file/avatar").file(file).cookie(util.getAlreadyLoginUserCookie()).contentType(MediaType.MULTIPART_FORM_DATA_VALUE).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(false)).andExpect(MockMvcResultMatchers.jsonPath("$.message").exists()).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists());
        } catch (NestedServletException ne) {
            Assert.assertThat(ne.getRootCause(), CoreMatchers.instanceOf(ParamsErrorException.class));
        }
    }
    util.printSuccessMessage();
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) NestedServletException(org.springframework.web.util.NestedServletException) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 79 with Transactional

use of javax.transaction.Transactional in project neubbs by nuitcoder.

the class MessageDAOTest method testGetMessage.

/**
 * 测试获取消息信息
 */
@Test
@Transactional
public void testGetMessage() {
    MessageDO message = this.saveTestMessageDOToDatabase();
    System.out.println("get message information: " + message);
}
Also used : MessageDO(org.neusoft.neubbs.entity.MessageDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 80 with Transactional

use of javax.transaction.Transactional in project neubbs by nuitcoder.

the class MessageDAOTest method testUpdateMessageReceiveTime.

/**
 * 测试更新接收时间
 */
@Test
@Transactional
public void testUpdateMessageReceiveTime() {
    MessageDO message = this.saveTestMessageDOToDatabase();
    int messageId = message.getId();
    Assert.assertEquals(1, messageDAO.updateMessageReceiveTime(messageId));
    MessageDO afterMessage = messageDAO.getMessage(messageId);
    Date afterReceiveTime = afterMessage.getReceiveTime();
    Assert.assertNotNull(afterMessage);
    System.out.println("update id=" + messageId + " message receive time=<" + afterReceiveTime + ">");
}
Also used : Date(java.util.Date) MessageDO(org.neusoft.neubbs.entity.MessageDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)299 Test (org.junit.Test)99 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)24 UserDO (org.neusoft.neubbs.entity.UserDO)21 Timestamp (java.sql.Timestamp)18 TopicDO (org.neusoft.neubbs.entity.TopicDO)18 Initiative (org.collectiveone.modules.initiatives.Initiative)16 GetResult (org.collectiveone.common.dto.GetResult)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)13 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)13 HashMap (java.util.HashMap)12 Date (java.util.Date)11 AppUser (org.collectiveone.modules.users.AppUser)11 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 IOException (java.io.IOException)9 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)9