use of org.wso2.carbon.apimgt.impl.certificatemgt.ResponseCode in project carbon-apimgt by wso2.
the class CertificateMgtUtilTest method testDeleteCertificateFromTrustStore.
@Test
public void testDeleteCertificateFromTrustStore() {
certificateMgtUtils.addCertificateToTrustStore(ALIAS, BASE64_ENCODED_CERT_STRING);
ResponseCode responseCode = certificateMgtUtils.removeCertificateFromTrustStore(ALIAS);
Assert.assertEquals(responseCode, ResponseCode.SUCCESS);
}
use of org.wso2.carbon.apimgt.impl.certificatemgt.ResponseCode in project carbon-apimgt by wso2.
the class CertificateMgtUtilTest method testAddExpiredCertificate.
@Test
public void testAddExpiredCertificate() {
ResponseCode responseCode = certificateMgtUtils.addCertificateToTrustStore(EXPIRED_CERTIFICATE, ALIAS_EXPIRED);
Assert.assertEquals(responseCode, ResponseCode.CERTIFICATE_EXPIRED);
}
use of org.wso2.carbon.apimgt.impl.certificatemgt.ResponseCode in project carbon-apimgt by wso2.
the class CertificateMgtUtilTest method testAddExistingCertificate.
@Test
public void testAddExistingCertificate() {
ResponseCode result = certificateMgtUtils.addCertificateToTrustStore(BASE64_ENCODED_CERT_STRING, ALIAS);
Assert.assertEquals(result, ResponseCode.ALIAS_EXISTS_IN_TRUST_STORE);
}
use of org.wso2.carbon.apimgt.impl.certificatemgt.ResponseCode in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method updateAPIClientCertificateByAlias.
@Override
public Response updateAPIClientCertificateByAlias(String alias, String apiId, InputStream certificateInputStream, Attachment certificateDetail, String tier, MessageContext messageContext) {
try {
// validate if api exists
validateAPIExistence(apiId);
ContentDisposition contentDisposition;
String fileName;
String base64EncodedCert = null;
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
API api = apiProvider.getAPIbyUUID(apiId, organization);
api.setOrganization(organization);
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(api.getStatus());
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getInternalOrganizationId(organization);
ClientCertificateDTO clientCertificateDTO = CertificateRestApiUtils.preValidateClientCertificate(alias, api.getId(), organization);
if (certificateDetail != null) {
contentDisposition = certificateDetail.getContentDisposition();
fileName = contentDisposition.getParameter(RestApiConstants.CONTENT_DISPOSITION_FILENAME);
if (StringUtils.isNotBlank(fileName)) {
base64EncodedCert = CertificateRestApiUtils.generateEncodedCertificate(certificateInputStream);
}
}
if (StringUtils.isEmpty(base64EncodedCert) && StringUtils.isEmpty(tier)) {
return Response.ok().entity("Client Certificate is not updated for alias " + alias).build();
}
int responseCode = apiProvider.updateClientCertificate(base64EncodedCert, alias, clientCertificateDTO.getApiIdentifier(), tier, tenantId, organization);
if (ResponseCode.SUCCESS.getResponseCode() == responseCode) {
// Handle api product case.
if (API_PRODUCT_TYPE.equals(api.getType())) {
APIIdentifier apiIdentifier = api.getId();
APIProductIdentifier apiProductIdentifier = new APIProductIdentifier(apiIdentifier.getProviderName(), apiIdentifier.getApiName(), apiIdentifier.getVersion());
APIProduct apiProduct = apiProvider.getAPIProduct(apiProductIdentifier);
apiProduct.setOrganization(organization);
apiProvider.updateAPIProduct(apiProduct);
} else {
apiProvider.updateAPI(api);
}
ClientCertMetadataDTO clientCertMetadataDTO = new ClientCertMetadataDTO();
clientCertMetadataDTO.setAlias(alias);
clientCertMetadataDTO.setApiId(api.getUUID());
clientCertMetadataDTO.setTier(clientCertificateDTO.getTierName());
URI updatedCertUri = new URI(RestApiConstants.CLIENT_CERTS_BASE_PATH + "?alias=" + alias);
return Response.ok(updatedCertUri).entity(clientCertMetadataDTO).build();
} else if (ResponseCode.INTERNAL_SERVER_ERROR.getResponseCode() == responseCode) {
RestApiUtil.handleInternalServerError("Error while updating the client certificate for the alias " + alias + " due to an internal " + "server error", log);
} else if (ResponseCode.CERTIFICATE_NOT_FOUND.getResponseCode() == responseCode) {
RestApiUtil.handleResourceNotFoundError("", log);
} else if (ResponseCode.CERTIFICATE_EXPIRED.getResponseCode() == responseCode) {
RestApiUtil.handleBadRequest("Error while updating the client certificate for the alias " + alias + " Certificate Expired.", log);
}
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while updating the client certificate for the alias " + alias + " due to an internal " + "server error", e, log);
} catch (IOException e) {
RestApiUtil.handleInternalServerError("Error while encoding client certificate for the alias " + alias, e, log);
} catch (URISyntaxException e) {
RestApiUtil.handleInternalServerError("Error while generating the resource location URI for alias '" + alias + "'", e, log);
} catch (FaultGatewaysException e) {
RestApiUtil.handleInternalServerError("Error while publishing the certificate change to gateways for the alias " + alias, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.impl.certificatemgt.ResponseCode in project carbon-apimgt by wso2.
the class EndpointCertificatesApiServiceImpl method deleteEndpointCertificateByAlias.
public Response deleteEndpointCertificateByAlias(String alias, MessageContext messageContext) {
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
String userName = RestApiCommonUtil.getLoggedInUsername();
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
if (!apiProvider.isCertificatePresent(tenantId, alias)) {
String message = "Certificate for alias '" + alias + "' is not found.";
RestApiUtil.handleResourceNotFoundError(message, log);
}
int responseCode = apiProvider.deleteCertificate(userName, alias, null);
if (responseCode == ResponseCode.SUCCESS.getResponseCode()) {
if (log.isDebugEnabled()) {
log.debug(String.format("The certificate which belongs to tenant : %d represented by the alias : " + "%s is deleted successfully", tenantId, alias));
}
return Response.ok().build();
} else {
if (log.isDebugEnabled()) {
log.debug(String.format("Failed to delete the certificate which belongs to tenant : %d " + "represented by the alias : %s.", tenantId, alias));
}
RestApiUtil.handleInternalServerError("Error while deleting the certificate for alias '" + alias + "'.", log);
}
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while deleting the certificate for alias '" + alias + "'.", e, log);
}
return null;
}
Aggregations