use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIUtil method updateAPIProductDependencies.
/**
* This method used to retrieve the api resource dependencies
*
* @param api api object
* @param registry registry
* @throws APIManagementException
*/
public static void updateAPIProductDependencies(API api, Registry registry) throws APIManagementException {
for (URITemplate uriTemplate : api.getUriTemplates()) {
Set<APIProductIdentifier> usedByProducts = uriTemplate.retrieveUsedByProducts();
for (APIProductIdentifier usedByProduct : usedByProducts) {
// TODO : removed registry call until find a proper fix
String apiProductPath = APIUtil.getAPIProductPath(usedByProduct);
usedByProduct.setUUID(apiProductPath);
}
}
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIConfigContext method setApiProductVelocityContext.
private void setApiProductVelocityContext(APIProduct apiProduct, VelocityContext context) {
APIProductIdentifier id = apiProduct.getId();
// set the api name version and context
context.put("apiName", PRODUCT_PREFIX + "--" + id.getName());
context.put("apiVersion", "1.0.0");
// We set the context pattern now to support plugable version strategy
// context.put("apiContext", api.getContext());
context.put("apiContext", apiProduct.getContext());
// the api object will be passed on to the template so it properties can be used to
// customise how the synapse config is generated.
context.put("apiObj", apiProduct);
context.put("apiIsBlocked", Boolean.FALSE);
String apiSecurity = apiProduct.getApiSecurity();
// if API is secured with ouath2
if (apiSecurity == null || apiSecurity.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) {
context.put("apiIsOauthProtected", Boolean.TRUE);
} else {
context.put("apiIsOauthProtected", Boolean.FALSE);
}
// if API is secured with api_Key
if (apiSecurity.contains(APIConstants.API_SECURITY_API_KEY)) {
context.put("apiIsApiKeyProtected", Boolean.TRUE);
} else {
context.put("apiIsApiKeyProtected", Boolean.FALSE);
}
// if API is secured with basic_auth
if (apiSecurity.contains(APIConstants.API_SECURITY_BASIC_AUTH)) {
context.put("apiIsBasicAuthProtected", Boolean.TRUE);
} else {
context.put("apiIsBasicAuthProtected", Boolean.FALSE);
}
if (apiProduct.isEnabledSchemaValidation()) {
context.put("enableSchemaValidation", Boolean.TRUE);
} else {
context.put("enableSchemaValidation", Boolean.FALSE);
}
if (apiProduct.isEnableStore()) {
context.put("enableStore", Boolean.TRUE);
} else {
context.put("enableStore", Boolean.FALSE);
}
// API test key
context.put("testKey", apiProduct.getTestKey());
context.put("apiType", apiProduct.getType());
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIMappingUtil method fromDTOtoAPIProduct.
public static APIProduct fromDTOtoAPIProduct(APIProductDTO dto, String provider) throws APIManagementException {
APIProduct product = new APIProduct();
APIProductIdentifier id = new APIProductIdentifier(APIUtil.replaceEmailDomain(provider), dto.getName(), // todo: replace this with dto.getVersion
APIConstants.API_PRODUCT_VERSION);
product.setID(id);
product.setUuid(dto.getId());
product.setDescription(dto.getDescription());
String context = dto.getContext();
if (context.endsWith("/" + RestApiConstants.API_VERSION_PARAM)) {
context = context.replace("/" + RestApiConstants.API_VERSION_PARAM, "");
}
context = context.startsWith("/") ? context : ("/" + context);
String providerDomain = MultitenantUtils.getTenantDomain(provider);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(providerDomain) && dto.getId() == null) {
// Create tenant aware context for API
context = "/t/" + providerDomain + context;
}
product.setType(APIConstants.API_PRODUCT_IDENTIFIER_TYPE.replaceAll("\\s", ""));
product.setContext(context);
context = checkAndSetVersionParam(context);
product.setContextTemplate(context);
List<String> apiProductTags = dto.getTags();
Set<String> tagsToReturn = new HashSet<>(apiProductTags);
product.addTags(tagsToReturn);
if (dto.isEnableSchemaValidation() != null) {
product.setEnableSchemaValidation(dto.isEnableSchemaValidation());
}
product.setEnableStore(true);
if (dto.isResponseCachingEnabled() != null && dto.isResponseCachingEnabled()) {
product.setResponseCache(APIConstants.ENABLED);
} else {
product.setResponseCache(APIConstants.DISABLED);
}
if (dto.getCacheTimeout() != null) {
product.setCacheTimeout(dto.getCacheTimeout());
} else {
product.setCacheTimeout(APIConstants.API_RESPONSE_CACHE_TIMEOUT);
}
if (dto.getBusinessInformation() != null) {
product.setBusinessOwner(dto.getBusinessInformation().getBusinessOwner());
product.setBusinessOwnerEmail(dto.getBusinessInformation().getBusinessOwnerEmail());
product.setTechnicalOwner(dto.getBusinessInformation().getTechnicalOwner());
product.setTechnicalOwnerEmail(dto.getBusinessInformation().getTechnicalOwnerEmail());
}
Set<Tier> apiTiers = new HashSet<>();
List<String> tiersFromDTO = dto.getPolicies();
if (dto.getVisibility() != null) {
product.setVisibility(mapVisibilityFromDTOtoAPIProduct(dto.getVisibility()));
}
if (dto.getVisibleRoles() != null) {
String visibleRoles = StringUtils.join(dto.getVisibleRoles(), ',');
product.setVisibleRoles(visibleRoles);
}
if (dto.getVisibleTenants() != null) {
String visibleTenants = StringUtils.join(dto.getVisibleTenants(), ',');
product.setVisibleTenants(visibleTenants);
}
List<String> accessControlRoles = dto.getAccessControlRoles();
if (accessControlRoles == null || accessControlRoles.isEmpty()) {
product.setAccessControl(APIConstants.NO_ACCESS_CONTROL);
product.setAccessControlRoles("null");
} else {
product.setAccessControlRoles(StringUtils.join(accessControlRoles, ',').toLowerCase());
product.setAccessControl(APIConstants.API_RESTRICTED_VISIBILITY);
}
for (String tier : tiersFromDTO) {
apiTiers.add(new Tier(tier));
}
product.setAvailableTiers(apiTiers);
product.setProductLevelPolicy(dto.getApiThrottlingPolicy());
product.setGatewayVendor(dto.getGatewayVendor());
if (dto.getSubscriptionAvailability() != null) {
product.setSubscriptionAvailability(mapSubscriptionAvailabilityFromDTOtoAPIProduct(dto.getSubscriptionAvailability()));
}
List<APIInfoAdditionalPropertiesDTO> additionalProperties = dto.getAdditionalProperties();
if (additionalProperties != null) {
for (APIInfoAdditionalPropertiesDTO property : additionalProperties) {
if (property.isDisplay()) {
product.addProperty(property.getName() + APIConstants.API_RELATED_CUSTOM_PROPERTIES_SURFIX, property.getValue());
} else {
product.addProperty(property.getName(), property.getValue());
}
}
}
if (dto.getSubscriptionAvailableTenants() != null) {
product.setSubscriptionAvailableTenants(StringUtils.join(dto.getSubscriptionAvailableTenants(), ","));
}
String transports = StringUtils.join(dto.getTransport(), ',');
product.setTransports(transports);
List<APIProductResource> productResources = new ArrayList<APIProductResource>();
Set<String> verbResourceCombo = new HashSet<>();
for (ProductAPIDTO res : dto.getApis()) {
List<APIOperationsDTO> productAPIOperationsDTO = res.getOperations();
for (APIOperationsDTO resourceItem : productAPIOperationsDTO) {
if (!verbResourceCombo.add(resourceItem.getVerb() + resourceItem.getTarget())) {
throw new APIManagementException("API Product resource: " + resourceItem.getTarget() + ", with verb: " + resourceItem.getVerb() + " , is duplicated for id " + id, ExceptionCodes.from(ExceptionCodes.API_PRODUCT_DUPLICATE_RESOURCE, resourceItem.getTarget(), resourceItem.getVerb()));
}
URITemplate template = new URITemplate();
template.setHTTPVerb(resourceItem.getVerb());
template.setHttpVerbs(resourceItem.getVerb());
template.setResourceURI(resourceItem.getTarget());
template.setUriTemplate(resourceItem.getTarget());
template.setOperationPolicies(OperationPolicyMappingUtil.fromDTOToAPIOperationPoliciesList(resourceItem.getOperationPolicies()));
APIProductResource resource = new APIProductResource();
resource.setApiId(res.getApiId());
resource.setUriTemplate(template);
productResources.add(resource);
}
}
Set<Scope> scopes = getScopes(dto);
product.setScopes(scopes);
APICorsConfigurationDTO apiCorsConfigurationDTO = dto.getCorsConfiguration();
CORSConfiguration corsConfiguration;
if (apiCorsConfigurationDTO != null) {
corsConfiguration = new CORSConfiguration(apiCorsConfigurationDTO.isCorsConfigurationEnabled(), apiCorsConfigurationDTO.getAccessControlAllowOrigins(), apiCorsConfigurationDTO.isAccessControlAllowCredentials(), apiCorsConfigurationDTO.getAccessControlAllowHeaders(), apiCorsConfigurationDTO.getAccessControlAllowMethods());
} else {
corsConfiguration = APIUtil.getDefaultCorsConfiguration();
}
product.setCorsConfiguration(corsConfiguration);
product.setProductResources(productResources);
product.setApiSecurity(getSecurityScheme(dto.getSecurityScheme()));
product.setAuthorizationHeader(dto.getAuthorizationHeader());
// attach api categories to API model
setAPICategoriesToModel(dto, product, provider);
return product;
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIMappingUtil method getAPIProductIdentifierFromUUID.
/**
* Returns the APIProductIdentifier given the uuid.
*
* @param productId API Product uuid
* @param requestedTenantDomain tenant domain of the API
* @return APIProductIdentifier which represents the given id
* @throws APIManagementException
*/
public static APIProductIdentifier getAPIProductIdentifierFromUUID(String productId, String requestedTenantDomain) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
APIProduct product = apiProvider.getAPIProductbyUUID(productId, requestedTenantDomain);
return product.getId();
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class ExportUtils method addClientCertificatesToArchive.
/**
* Retrieve Mutual SSL related certificates and store those in the archive directory.
*
* @param archivePath Folder path to export client certificates
* @param identifier Identifier
* @param tenantId Tenant id of the user
* @param provider Api Provider
* @param exportFormat Export format of file
* @param organization Organization
* @throws APIImportExportException If an error occurs when writing to file or retrieving certificate metadata
*/
public static void addClientCertificatesToArchive(String archivePath, Identifier identifier, int tenantId, APIProvider provider, ExportFormat exportFormat, String organization) throws APIImportExportException {
List<ClientCertificateDTO> certificateMetadataDTOs;
try {
if (identifier instanceof APIProductIdentifier) {
certificateMetadataDTOs = provider.searchClientCertificates(tenantId, null, (APIProductIdentifier) identifier, organization);
} else {
certificateMetadataDTOs = provider.searchClientCertificates(tenantId, null, (APIIdentifier) identifier, organization);
}
if (!certificateMetadataDTOs.isEmpty()) {
String clientCertsDirectoryPath = archivePath + File.separator + ImportExportConstants.CLIENT_CERTIFICATES_DIRECTORY;
CommonUtil.createDirectory(clientCertsDirectoryPath);
JsonArray certificateList = getClientCertificateContentAndMetaData(certificateMetadataDTOs, clientCertsDirectoryPath);
if (certificateList.size() > 0) {
CommonUtil.writeDtoToFile(clientCertsDirectoryPath + ImportExportConstants.CLIENT_CERTIFICATE_FILE, exportFormat, ImportExportConstants.TYPE_CLIENT_CERTIFICATES, certificateList);
}
}
} catch (IOException e) {
throw new APIImportExportException("Error while saving as YAML or JSON", e);
} catch (APIManagementException e) {
throw new APIImportExportException("Error retrieving certificate meta data. tenantId [" + tenantId + "] api [" + tenantId + "]", e);
}
}
Aggregations