use of org.wso2.carbon.apimgt.api.model.CORSConfiguration in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createAlternativeAPI.
public static API.APIBuilder createAlternativeAPI() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
Set<String> tags = new HashSet<>();
tags.add(TAG_FOOD);
tags.add(TAG_BEVERAGE);
Set<Policy> policies = new HashSet<>();
policies.add(silverSubscriptionPolicy);
policies.add(bronzeSubscriptionPolicy);
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner(NAME_BUSINESS_OWNER_1);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_1);
businessInformation.setTechnicalOwner(NAME_BUSINESS_OWNER_2);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_2);
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList(APIMgtConstants.FunctionsConstants.GET, APIMgtConstants.FunctionsConstants.POST, APIMgtConstants.FunctionsConstants.DELETE));
corsConfiguration.setAllowHeaders(Arrays.asList(ALLOWED_HEADER_AUTHORIZATION, ALLOWED_HEADER_CUSTOM));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Arrays.asList("*"));
String permissionJson = "[{\"groupId\" : \"developer\", \"permission\" : " + "[\"READ\",\"UPDATE\"]},{\"groupId\" : \"admin\", \"permission\" : [\"READ\",\"UPDATE\"," + "\"DELETE\", \"MANAGE_SUBSCRIPTION\"]}]";
Map permissionMap = new HashMap();
permissionMap.put(DEVELOPER_ROLE_ID, 6);
permissionMap.put(ADMIN_ROLE_ID, 15);
List<String> defaultLabels = getDefaultLabels();
API.APIBuilder apiBuilder = new API.APIBuilder(ADMIN, "restaurantAPI", "0.9").id(UUID.randomUUID().toString()).context("weather").description("Get Food & Beverage Info").lifeCycleStatus(APIStatus.CREATED.getStatus()).endpoint(Collections.emptyMap()).isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(goldApiPolicy).transport(transport).tags(tags).labels(defaultLabels).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList(CUSTOMER_ROLE, MANAGER_ROLE, EMPLOYEE_ROLE))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).apiPermission(permissionJson).permissionMap(permissionMap).createdTime(LocalDateTime.now()).createdBy(API_CREATOR).apiDefinition(apiDefinition).lastUpdatedTime(LocalDateTime.now()).securityScheme(3).threatProtectionPolicies(threatProtectionPolicies);
return apiBuilder;
}
use of org.wso2.carbon.apimgt.api.model.CORSConfiguration in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultAPIWithApiLevelEndpoint.
public static API.APIBuilder createDefaultAPIWithApiLevelEndpoint() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
transport.add(HTTPS);
Set<String> tags = new HashSet<>();
tags.add(TAG_CLIMATE);
Set<Policy> policies = new HashSet<>();
policies.add(new SubscriptionPolicy(GOLD_TIER));
policies.add(new SubscriptionPolicy(SILVER_TIER));
policies.add(new SubscriptionPolicy(BRONZE_TIER));
BusinessInformation businessInformation = new BusinessInformation();
CorsConfiguration corsConfiguration = new CorsConfiguration();
String permissionJson = "[{\"groupId\" : \"developer\", \"permission\" : " + "[\"READ\",\"UPDATE\"]},{\"groupId\" : \"admin\", \"permission\" : [\"READ\",\"UPDATE\"," + "\"DELETE\", \"MANAGE_SUBSCRIPTION\"]}]";
Map<String, Endpoint> endpointMap = new HashMap<>();
endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, new Endpoint.Builder().id(endpointId).name("api1-production--endpint").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build());
API.APIBuilder apiBuilder = new API.APIBuilder(ADMIN, "WeatherAPI", API_VERSION).id(UUID.randomUUID().toString()).context("weather").description("Get Weather Info").lifeCycleStatus(APIStatus.CREATED.getStatus()).lifecycleInstanceId(UUID.randomUUID().toString()).endpoint(endpointMap).wsdlUri("http://localhost:9443/echo?wsdl").isResponseCachingEnabled(false).cacheTimeout(60).isDefaultVersion(false).apiPolicy(APIUtils.getDefaultAPIPolicy()).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.PUBLIC).visibleRoles(new HashSet<>()).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy(ADMIN).updatedBy(ADMIN).lastUpdatedTime(LocalDateTime.now()).apiPermission(permissionJson).uriTemplates(getMockUriTemplates()).apiDefinition(apiDefinition);
Map map = new HashMap();
map.put(DEVELOPER_ROLE_ID, 6);
map.put(ADMIN_ROLE_ID, 15);
apiBuilder.permissionMap(map);
return apiBuilder;
}
use of org.wso2.carbon.apimgt.api.model.CORSConfiguration in project carbon-apimgt by wso2.
the class TestUtil method createApi.
protected static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
Set<String> transport = new HashSet<>();
transport.add("http");
Set<Policy> policies = new HashSet<>();
policies.add(new SubscriptionPolicy("Silver"));
policies.add(new SubscriptionPolicy("Bronze"));
Set<String> tags = new HashSet<>();
tags.add("food");
tags.add("beverage");
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner("John Doe");
businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
businessInformation.setTechnicalOwner("Jane Doe");
businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition("swagger definition").wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
apiBuilder.uriTemplates(Collections.emptyMap());
return apiBuilder;
}
use of org.wso2.carbon.apimgt.api.model.CORSConfiguration in project carbon-apimgt by wso2.
the class APIMappingUtilTestCase method createApi.
private static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
Set<String> transport = new HashSet<>();
transport.add("http");
Set<Policy> policies = new HashSet<>();
policies.add(new SubscriptionPolicy("Silver"));
policies.add(new SubscriptionPolicy("Bronze"));
Set<String> tags = new HashSet<>();
tags.add("food");
tags.add("beverage");
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner("John Doe");
businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
businessInformation.setTechnicalOwner("Jane Doe");
businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition("").wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
apiBuilder.uriTemplates(Collections.emptyMap());
return apiBuilder;
}
use of org.wso2.carbon.apimgt.api.model.CORSConfiguration in project carbon-apimgt by wso2.
the class ApiDAOImpl method addAPIRelatedInformation.
/**
* Method for adding API related information
*
* @param connection DB Connection
* @param statement PreparedStatement
* @param api API object
* @throws SQLException if error occurs while accessing data layer
*/
private void addAPIRelatedInformation(Connection connection, PreparedStatement statement, final API api) throws SQLException, org.wso2.carbon.apimgt.core.exception.APIMgtDAOException {
String apiPrimaryKey = api.getId();
statement.setString(1, api.getProvider());
statement.setString(2, api.getName());
statement.setString(3, api.getContext());
statement.setString(4, api.getVersion());
statement.setBoolean(5, api.isDefaultVersion());
statement.setString(6, api.getDescription());
statement.setString(7, api.getVisibility().toString());
statement.setBoolean(8, api.isResponseCachingEnabled());
statement.setBoolean(9, api.hasOwnGateway());
statement.setInt(10, api.getCacheTimeout());
statement.setString(11, apiPrimaryKey);
BusinessInformation businessInformation = api.getBusinessInformation();
statement.setString(12, businessInformation.getTechnicalOwner());
statement.setString(13, businessInformation.getTechnicalOwnerEmail());
statement.setString(14, businessInformation.getBusinessOwner());
statement.setString(15, businessInformation.getBusinessOwnerEmail());
statement.setString(16, api.getLifecycleInstanceId());
statement.setString(17, api.getLifeCycleStatus());
CorsConfiguration corsConfiguration = api.getCorsConfiguration();
statement.setBoolean(18, corsConfiguration.isEnabled());
statement.setString(19, String.join(",", corsConfiguration.getAllowOrigins()));
statement.setBoolean(20, corsConfiguration.isAllowCredentials());
statement.setString(21, String.join(",", corsConfiguration.getAllowHeaders()));
statement.setString(22, String.join(",", corsConfiguration.getAllowMethods()));
statement.setInt(23, getApiTypeId(connection, ApiType.STANDARD));
statement.setString(24, api.getCreatedBy());
statement.setTimestamp(25, Timestamp.valueOf(LocalDateTime.now()));
statement.setTimestamp(26, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(27, api.getCopiedFromApiId());
statement.setString(28, api.getUpdatedBy());
statement.setString(29, APILCWorkflowStatus.APPROVED.toString());
statement.setInt(30, api.getSecurityScheme());
statement.execute();
if (API.Visibility.RESTRICTED == api.getVisibility()) {
addVisibleRole(connection, apiPrimaryKey, api.getVisibleRoles());
}
addTagsMapping(connection, apiPrimaryKey, api.getTags());
addLabelMapping(connection, apiPrimaryKey, api.getLabels());
addGatewayConfig(connection, apiPrimaryKey, api.getGatewayConfig(), api.getCreatedBy());
addTransports(connection, apiPrimaryKey, api.getTransport());
addUrlMappings(connection, api.getUriTemplates().values(), apiPrimaryKey);
addSubscriptionPolicies(connection, api.getPolicies(), apiPrimaryKey);
addEndPointsForApi(connection, apiPrimaryKey, api.getEndpoint());
addAPIDefinition(connection, apiPrimaryKey, api.getApiDefinition(), api.getCreatedBy());
addAPIPermission(connection, api.getPermissionMap(), apiPrimaryKey);
if (api.getThreatProtectionPolicies() != null) {
addThreatProtectionPolicies(connection, apiPrimaryKey, api.getThreatProtectionPolicies());
}
if (api.getApiPolicy() != null) {
addApiPolicy(connection, api.getApiPolicy().getUuid(), apiPrimaryKey);
}
}
Aggregations