use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO in project carbon-apimgt by wso2.
the class APIControllerUtil method handleMutualSslCertificates.
/**
* This method will be used to generate ClientCertificates and meta information related to client certs.
*
* @param envParams Env params object with required parameters
* @param importedApiDto Imported API DTO (this will be null for API Products)
* @param importedApiProductDto Imported API Product DTO (this will be null for APIs)
* @param identifier API Identifier/API Product Identifier of the imported API/API Product
* @param pathToArchive String of the archive project
* @throws APIManagementException If an error while generating client certificate information
*/
private static void handleMutualSslCertificates(JsonObject envParams, APIDTO importedApiDto, APIProductDTO importedApiProductDto, Identifier identifier, String pathToArchive) throws APIManagementException {
JsonElement clientCertificates = envParams.get(ImportExportConstants.MUTUAL_SSL_CERTIFICATES_FIELD);
if (clientCertificates != null) {
try {
List<String> apiSecurity = (importedApiDto != null) ? importedApiDto.getSecurityScheme() : importedApiProductDto.getSecurityScheme();
if (!apiSecurity.isEmpty()) {
if (!apiSecurity.contains(ImportExportConstants.MUTUAL_SSL_ENABLED)) {
// if the apiSecurity field does not have mutualssl type, append it
apiSecurity.add(ImportExportConstants.MUTUAL_SSL_ENABLED);
}
} else {
// if the apiSecurity field is empty, assign the value as "mutualssl"
apiSecurity.add(ImportExportConstants.MUTUAL_SSL_ENABLED);
}
if (importedApiDto != null) {
importedApiDto.securityScheme(apiSecurity);
} else {
importedApiProductDto.securityScheme(apiSecurity);
}
String jsonString = clientCertificates.toString();
handleClientCertificates(new JsonParser().parse(jsonString).getAsJsonArray(), identifier, pathToArchive);
} catch (IOException e) {
// Error is logged and when generating certificate details and certs in the archive
String errorMessage = "Error while generating meta information of client certificates from path.";
throw new APIManagementException(errorMessage, e, ExceptionCodes.ERROR_READING_PARAMS_FILE);
}
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method createAPIProduct.
@Override
public Response createAPIProduct(APIProductDTO body, MessageContext messageContext) throws APIManagementException {
String provider = body.getProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
try {
APIProduct createdProduct = PublisherCommonUtils.addAPIProductWithGeneratedSwaggerDefinition(body, RestApiCommonUtil.getLoggedInUsername(), organization);
APIProductDTO createdApiProductDTO = APIMappingUtil.fromAPIProducttoDTO(createdProduct);
URI createdApiProductUri = new URI(RestApiConstants.RESOURCE_PATH_API_PRODUCTS + "/" + createdApiProductDTO.getId());
return Response.created(createdApiProductUri).entity(createdApiProductDTO).build();
} catch (APIManagementException | FaultGatewaysException e) {
String errorMessage = "Error while adding new API Product : " + provider + "-" + body.getName() + " - " + e.getMessage();
RestApiUtil.handleInternalServerError(errorMessage, e, log);
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving API Product location : " + provider + "-" + body.getName();
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method updateAPIProduct.
@Override
public Response updateAPIProduct(String apiProductId, APIProductDTO body, String ifMatch, MessageContext messageContext) {
try {
String username = RestApiCommonUtil.getLoggedInUsername();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
APIProvider apiProvider = RestApiCommonUtil.getProvider(username);
APIProduct retrievedProduct = apiProvider.getAPIProductbyUUID(apiProductId, tenantDomain);
if (retrievedProduct == null) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, log);
}
APIProduct updatedProduct = PublisherCommonUtils.updateApiProduct(retrievedProduct, body, apiProvider, username, tenantDomain);
APIProductDTO updatedProductDTO = getAPIProductByID(apiProductId, apiProvider);
return Response.ok().entity(updatedProductDTO).build();
} catch (APIManagementException | FaultGatewaysException e) {
if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("User is not authorized to access the API", e, log);
} else {
String errorMessage = "Error while updating API Product : " + apiProductId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method getAPIProduct.
@Override
public Response getAPIProduct(String apiProductId, String accept, String ifNoneMatch, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String username = RestApiCommonUtil.getLoggedInUsername();
String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(username));
if (log.isDebugEnabled()) {
log.debug("API Product request: Id " + apiProductId + " by " + username);
}
APIProduct apiProduct = apiProvider.getAPIProductbyUUID(apiProductId, tenantDomain);
if (apiProduct == null) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, log);
}
APIProductDTO createdApiProductDTO = getAPIProductByID(apiProductId, apiProvider);
return Response.ok().entity(createdApiProductDTO).build();
} catch (APIManagementException e) {
if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("User is not authorized to access the API", e, log);
} else {
String errorMessage = "Error while retrieving API Product from Id : " + apiProductId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method restoreAPIProductRevision.
@Override
public Response restoreAPIProductRevision(String apiProductId, String revisionId, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
apiProvider.restoreAPIProductRevision(apiProductId, revisionId, organization);
APIProductDTO apiToReturn = getAPIProductByID(apiProductId, apiProvider);
Response.Status status = Response.Status.CREATED;
return Response.status(status).entity(apiToReturn).build();
}
Aggregations