Search in sources :

Example 1 with CertificateInformationDTO

use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.

the class CertificateMgtUtilTest method testGetCertificateInformation.

@Test
public void testGetCertificateInformation() throws CertificateManagementException {
    certificateMgtUtils.addCertificateToTrustStore(BASE64_ENCODED_CERT_STRING, ALIAS);
    CertificateInformationDTO certificateInformationDTO = certificateMgtUtils.getCertificateInformation(ALIAS);
    Assert.assertNotNull(certificateInformationDTO);
}
Also used : CertificateInformationDTO(org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO) Test(org.junit.Test)

Example 2 with CertificateInformationDTO

use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.

the class CertificateManagerImplTest method testGetCertificateInformation.

@Test
public void testGetCertificateInformation() throws APIManagementException {
    CertificateInformationDTO certificateInformation = generateCertificateInformationDTO();
    PowerMockito.stub(PowerMockito.method(CertificateMgtUtils.class, "getCertificateInformation", String.class)).toReturn(certificateInformation);
    CertificateInformationDTO certificateInformationDTO = certificateManager.getCertificateInformation(ALIAS);
    Assert.assertNotNull(certificateInformationDTO);
}
Also used : CertificateInformationDTO(org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with CertificateInformationDTO

use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.

the class CertificateManagerImplTest method generateCertificateInformationDTO.

private CertificateInformationDTO generateCertificateInformationDTO() {
    CertificateInformationDTO certificateInformationDTO = new CertificateInformationDTO();
    certificateInformationDTO.setStatus("ACTIVE");
    certificateInformationDTO.setVersion("V3");
    certificateInformationDTO.setFrom("");
    certificateInformationDTO.setTo("");
    certificateInformationDTO.setSubject("");
    return certificateInformationDTO;
}
Also used : CertificateInformationDTO(org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO)

Example 4 with CertificateInformationDTO

use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method getAPIClientCertificateByAlias.

@Override
public Response getAPIClientCertificateByAlias(String alias, String apiId, MessageContext messageContext) {
    String organization = null;
    CertificateMgtUtils certificateMgtUtils = CertificateMgtUtils.getInstance();
    try {
        organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        API api = apiProvider.getAPIbyUUID(apiId, organization);
        ClientCertificateDTO clientCertificateDTO = CertificateRestApiUtils.preValidateClientCertificate(alias, api.getId(), organization);
        CertificateInformationDTO certificateInformationDTO = certificateMgtUtils.getCertificateInfo(clientCertificateDTO.getCertificate());
        if (certificateInformationDTO != null) {
            CertificateInfoDTO certificateInfoDTO = CertificateMappingUtil.fromCertificateInformationToDTO(certificateInformationDTO);
            return Response.ok().entity(certificateInfoDTO).build();
        } else {
            RestApiUtil.handleResourceNotFoundError("Certificate is empty for alias " + alias, log);
        }
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving the client certificate with alias " + alias + " for the tenant " + organization, e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) CertificateInformationDTO(org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO) CertificateMgtUtils(org.wso2.carbon.apimgt.impl.utils.CertificateMgtUtils) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) CertificateInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateInfoDTO)

Example 5 with CertificateInformationDTO

use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.

the class EndpointCertificatesApiServiceImpl method getEndpointCertificateByAlias.

public Response getEndpointCertificateByAlias(String alias, MessageContext messageContext) {
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
    if (!StringUtils.isNotEmpty(alias)) {
        RestApiUtil.handleBadRequest("The alias cannot be empty", log);
    }
    if (log.isDebugEnabled()) {
        log.debug(String.format("Retrieving the common information of the certificate which is represented by the" + " alias : %s", alias));
    }
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        if (!apiProvider.isCertificatePresent(tenantId, alias)) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Could not find a certificate in truststore which belongs to tenant %d " + "and with alias %s. Hence the operation is terminated.", tenantId, alias));
            }
            String message = "Certificate for Alias '" + alias + "' is not found.";
            RestApiUtil.handleResourceNotFoundError(message, log);
        }
        CertificateInformationDTO certificateInformationDTO = apiProvider.getCertificateStatus(alias);
        CertificateValidityDTO certificateValidityDTO = new CertificateValidityDTO();
        certificateValidityDTO.setFrom(certificateInformationDTO.getFrom());
        certificateValidityDTO.setTo(certificateInformationDTO.getTo());
        CertificateInfoDTO certificateInfoDTO = new CertificateInfoDTO();
        certificateInfoDTO.setValidity(certificateValidityDTO);
        certificateInfoDTO.setStatus(certificateInformationDTO.getStatus());
        certificateInfoDTO.setSubject(certificateInformationDTO.getSubject());
        certificateInfoDTO.setVersion(certificateInformationDTO.getVersion());
        return Response.ok().entity(certificateInfoDTO).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving the certificate status.", e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) CertificateInformationDTO(org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) CertificateInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateInfoDTO) CertificateValidityDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateValidityDTO)

Aggregations

CertificateInformationDTO (org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO)8 CertificateInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateInfoDTO)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CertificateException (java.security.cert.CertificateException)2 X509Certificate (java.security.cert.X509Certificate)2 Test (org.junit.Test)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 CertificateValidityDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateValidityDTO)2 File (java.io.File)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Certificate (java.security.cert.Certificate)1 CertificateFactory (java.security.cert.CertificateFactory)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 ClientCertificateDTO (org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO)1