Search in sources :

Example 1 with CertificateValidityDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateValidityDTO 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)

Example 2 with CertificateValidityDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateValidityDTO in project carbon-apimgt by wso2.

the class CertificateMappingUtil method fromCertificateInformationToDTO.

/**
 * To convert Instance of {@link CertificateInformationDTO} to {@link CertificateInfoDTO};
 *
 * @param certificateInformationDTO Instance of {@link CertificateInformationDTO}
 * @return converted instance of {@link CertificateInfoDTO}.
 */
public static CertificateInfoDTO fromCertificateInformationToDTO(CertificateInformationDTO certificateInformationDTO) {
    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 certificateInfoDTO;
}
Also used : CertificateInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateInfoDTO) CertificateValidityDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateValidityDTO)

Aggregations

CertificateInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateInfoDTO)2 CertificateValidityDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CertificateValidityDTO)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 CertificateInformationDTO (org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO)1