Search in sources :

Example 6 with CustomCertificateModel

use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.

the class DefaultCustomCertificateAccessor method createModel.

private CustomCertificateModel createModel(CustomCertificateEntity entity) {
    CustomCertificateModel customCertificateModel = new CustomCertificateModel(entity.getAlias(), entity.getCertificateContent(), DateUtils.formatDate(entity.getLastUpdated(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE));
    customCertificateModel.setId(entity.getId());
    return customCertificateModel;
}
Also used : CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel)

Example 7 with CustomCertificateModel

use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.

the class CertificateActions method updateWithoutChecks.

@Override
protected ActionResponse<CertificateModel> updateWithoutChecks(Long id, CertificateModel resource) {
    try {
        Optional<CustomCertificateModel> existingCertificate = certificateAccessor.getCertificate(id);
        String logableId = escapeUtil.replaceWithUnderscore(resource.getId());
        String loggableAlias = escapeUtil.replaceWithUnderscore(resource.getAlias());
        logger.info("Updating certificate with id: {} and alias: {}", logableId, loggableAlias);
        if (existingCertificate.isPresent()) {
            CertificateModel certificateModel = importCertificate(resource);
            return new ActionResponse<>(HttpStatus.NO_CONTENT, certificateModel);
        }
        logger.error("Certificate with id: {} missing.", logableId);
        return new ActionResponse<>(HttpStatus.NOT_FOUND, "Certificate not found.");
    } catch (AlertException ex) {
        logger.error("Error occurred updating certificate", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 8 with CustomCertificateModel

use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.

the class CertificateActions method deleteWithoutChecks.

@Override
protected ActionResponse<CertificateModel> deleteWithoutChecks(Long id) {
    try {
        Optional<CustomCertificateModel> certificate = certificateAccessor.getCertificate(id);
        if (certificate.isPresent()) {
            CustomCertificateModel certificateModel = certificate.get();
            logger.info("Delete certificate with id: {} and alias: {}", certificateModel.getNullableId(), certificateModel.getAlias());
            trustStoreService.removeCertificate(certificateModel);
            certificateAccessor.deleteCertificate(id);
        }
    } catch (AlertException ex) {
        logger.error("Error deleting certificate", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error deleting certificate: %s", ex.getMessage()));
    }
    return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Also used : CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 9 with CustomCertificateModel

use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.

the class DefaultCustomCertificateAccessorTest method deleteCertificateByIdTest.

@Test
public void deleteCertificateByIdTest() {
    CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(alias, content, testDate);
    DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository);
    List<CustomCertificateModel> customCertificateModelList = customCertificateAccessor.getCertificates();
    assertEquals(1, customCertificateModelList.size());
    CustomCertificateModel customCertificateModel = customCertificateModelList.get(0);
    testCustomCertificateModel(expectedCustomCertificateModel, customCertificateModel);
    customCertificateAccessor.deleteCertificate(0L);
    customCertificateModelList = customCertificateAccessor.getCertificates();
    assertTrue(customCertificateModelList.isEmpty());
}
Also used : CustomCertificateRepository(com.synopsys.integration.alert.database.certificates.CustomCertificateRepository) MockCustomCertificateRepository(com.synopsys.integration.alert.database.api.mock.MockCustomCertificateRepository) CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) MockCustomCertificateRepository(com.synopsys.integration.alert.database.api.mock.MockCustomCertificateRepository) Test(org.junit.jupiter.api.Test)

Example 10 with CustomCertificateModel

use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.

the class DefaultCustomCertificateAccessorTest method deleteCertificateByAliasTest.

@Test
public void deleteCertificateByAliasTest() {
    CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(alias, content, testDate);
    DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository);
    List<CustomCertificateModel> customCertificateModelList = customCertificateAccessor.getCertificates();
    assertEquals(1, customCertificateModelList.size());
    CustomCertificateModel customCertificateModel = customCertificateModelList.get(0);
    testCustomCertificateModel(expectedCustomCertificateModel, customCertificateModel);
    customCertificateAccessor.deleteCertificate(alias);
    customCertificateModelList = customCertificateAccessor.getCertificates();
    assertTrue(customCertificateModelList.isEmpty());
}
Also used : CustomCertificateRepository(com.synopsys.integration.alert.database.certificates.CustomCertificateRepository) MockCustomCertificateRepository(com.synopsys.integration.alert.database.api.mock.MockCustomCertificateRepository) CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) MockCustomCertificateRepository(com.synopsys.integration.alert.database.api.mock.MockCustomCertificateRepository) Test(org.junit.jupiter.api.Test)

Aggregations

CustomCertificateModel (com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel)11 MockCustomCertificateRepository (com.synopsys.integration.alert.database.api.mock.MockCustomCertificateRepository)6 CustomCertificateRepository (com.synopsys.integration.alert.database.certificates.CustomCertificateRepository)6 Test (org.junit.jupiter.api.Test)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)3 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AbstractResourceActions (com.synopsys.integration.alert.common.action.api.AbstractResourceActions)1 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)1 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)1 CustomCertificateAccessor (com.synopsys.integration.alert.common.persistence.accessor.CustomCertificateAccessor)1 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)1 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)1 AlertTrustStoreManager (com.synopsys.integration.alert.component.certificates.AlertTrustStoreManager)1 CertificatesDescriptor (com.synopsys.integration.alert.component.certificates.CertificatesDescriptor)1 CertificatesDescriptorKey (com.synopsys.integration.alert.component.certificates.CertificatesDescriptorKey)1 IntegrationEscapeUtil (com.synopsys.integration.util.IntegrationEscapeUtil)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1