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);
}
}
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);
});
}
}
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();
}
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);
}
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 + ">");
}
Aggregations