use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPIClientCertificateContentByAlias.
@Override
public Response getAPIClientCertificateContentByAlias(String apiId, String alias, MessageContext messageContext) {
String organization = null;
String certFileName = alias + ".crt";
try {
organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
API api = apiProvider.getAPIbyUUID(apiId, organization);
ClientCertificateDTO clientCertificateDTO = CertificateRestApiUtils.preValidateClientCertificate(alias, api.getId(), organization);
if (clientCertificateDTO != null) {
Object certificate = CertificateRestApiUtils.getDecodedCertificate(clientCertificateDTO.getCertificate());
Response.ResponseBuilder responseBuilder = Response.ok().entity(certificate);
responseBuilder.header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=\"" + certFileName + "\"");
responseBuilder.header(RestApiConstants.HEADER_CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM);
return responseBuilder.build();
}
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving the client certificate with alias " + alias + " for the tenant " + organization, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getGeneratedMockScriptsOfAPI.
/**
* Gets generated scripts
*
* @param apiId API Id
* @param ifNoneMatch If-None-Match header value
* @param messageContext message context
* @return list of policies of generated sample payload
* @throws APIManagementException
*/
@Override
public Response getGeneratedMockScriptsOfAPI(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
API originalAPI = apiProvider.getAPIbyUUID(apiId, organization);
APIIdentifier apiIdentifier = originalAPI.getId();
String apiDefinition = apiProvider.getOpenAPIDefinition(apiIdentifier, organization);
Map<String, Object> examples = OASParserUtil.generateExamples(apiDefinition);
List<APIResourceMediationPolicy> policies = (List<APIResourceMediationPolicy>) examples.get(APIConstants.MOCK_GEN_POLICY_LIST);
return Response.ok().entity(APIMappingUtil.fromMockPayloadsToListDTO(policies)).build();
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method deleteAPIClientCertificateByAlias.
@Override
public Response deleteAPIClientCertificateByAlias(String alias, String apiId, MessageContext messageContext) {
String organization = null;
try {
organization = RestApiUtil.getValidatedOrganization(messageContext);
// validate if api exists
validateAPIExistence(apiId);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
API api = apiProvider.getAPIbyUUID(apiId, organization);
api.setOrganization(organization);
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(api.getStatus());
ClientCertificateDTO clientCertificateDTO = CertificateRestApiUtils.preValidateClientCertificate(alias, api.getId(), organization);
int responseCode = apiProvider.deleteClientCertificate(RestApiCommonUtil.getLoggedInUsername(), clientCertificateDTO.getApiIdentifier(), alias);
if (responseCode == ResponseCode.SUCCESS.getResponseCode()) {
// 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);
}
if (log.isDebugEnabled()) {
log.debug(String.format("The client certificate which belongs to tenant : %s represented by the " + "alias : %s is deleted successfully", organization, alias));
}
return Response.ok().entity("The certificate for alias '" + alias + "' deleted successfully.").build();
} else {
if (log.isDebugEnabled()) {
log.debug(String.format("Failed to delete the client certificate which belongs to tenant : %s " + "represented by the alias : %s.", organization, alias));
}
RestApiUtil.handleInternalServerError("Error while deleting the client certificate for alias '" + alias + "'.", log);
}
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while deleting the client certificate with alias " + alias + " for the tenant " + organization, 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.api.APIProvider in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAllCommentsOfAPI.
@Override
public Response getAllCommentsOfAPI(String apiId, String xWSO2Tenant, Integer limit, Integer offset, Boolean includeCommenterInfo, MessageContext messageContext) throws APIManagementException {
String requestedTenantDomain = RestApiUtil.getRequestedTenantDomain(xWSO2Tenant);
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
ApiTypeWrapper apiTypeWrapper = apiProvider.getAPIorAPIProductByUUID(apiId, requestedTenantDomain);
String parentCommentID = null;
CommentList comments = apiProvider.getComments(apiTypeWrapper, parentCommentID, limit, offset);
CommentListDTO commentDTO = CommentMappingUtil.fromCommentListToDTO(comments, includeCommenterInfo);
String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS;
URI uri = new URI(uriString);
return Response.ok(uri).entity(commentDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Failed to get comments of API " + apiId, e, log);
}
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving comments content location for API " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getRepliesOfComment.
@Override
public Response getRepliesOfComment(String commentId, String apiId, String xWSO2Tenant, Integer limit, Integer offset, String ifNoneMatch, Boolean includeCommenterInfo, MessageContext messageContext) throws APIManagementException {
String requestedTenantDomain = RestApiUtil.getRequestedTenantDomain(xWSO2Tenant);
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
ApiTypeWrapper apiTypeWrapper = apiProvider.getAPIorAPIProductByUUID(apiId, requestedTenantDomain);
CommentList comments = apiProvider.getComments(apiTypeWrapper, commentId, limit, offset);
CommentListDTO commentDTO = CommentMappingUtil.fromCommentListToDTO(comments, includeCommenterInfo);
String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS;
URI uri = new URI(uriString);
return Response.ok(uri).entity(commentDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Failed to get comments of API " + apiId, e, log);
}
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving comments content location for API " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations