use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.
the class TestMappingUtilTestCase method testSecuritySchemeListToIntMapping.
@Test
void testSecuritySchemeListToIntMapping() {
List<String> testList = new ArrayList<String>();
testList.add("Oauth");
testList.add("apikey");
int securityScheme = MappingUtil.mapSecuritySchemeListToInt(testList);
assertEquals(securityScheme, 3);
}
use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.
the class AbstractAPIManager method getApplicationByUUID.
/**
* Returns the corresponding application given the uuid with keys for a specific tenant.
*
* @param uuid uuid of the Application.
* @param tenantDomain domain of the accessed store.
* @return it will return Application corresponds to the uuid provided.
* @throws APIManagementException
*/
public Application getApplicationByUUID(String uuid, String tenantDomain) throws APIManagementException {
Application application = apiMgtDAO.getApplicationByUUID(uuid);
if (application != null) {
Set<APIKey> keys = getApplicationKeys(application.getId(), tenantDomain);
for (APIKey key : keys) {
if (APIConstants.JWT.equals(application.getTokenType())) {
key.setAccessToken("");
}
application.addKey(key);
}
int subscriptionCount = apiMgtDAO.getSubscriptionCountByApplicationId(application, tenantDomain);
application.setSubscriptionCount(subscriptionCount);
}
return application;
}
use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.
the class PersistenceHelper method getSampleAPIArtifactForTenant.
public static GenericArtifact getSampleAPIArtifactForTenant() throws GovernanceException {
GenericArtifact artifact = new GenericArtifactImpl(new QName("", "PizzaShackAPI", ""), "application/vnd.wso2-api+xml");
artifact.setAttribute("overview_endpointSecured", "false");
artifact.setAttribute("overview_transports", "http,https");
artifact.setAttribute("URITemplate_authType3", "Application & Application User");
artifact.setAttribute("overview_wadl", null);
artifact.setAttribute("URITemplate_authType4", "Application & Application User");
artifact.setAttribute("overview_authorizationHeader", "Authorization");
artifact.setAttribute("URITemplate_authType1", "Application & Application User");
artifact.setAttribute("overview_visibleTenants", null);
artifact.setAttribute("URITemplate_authType2", "Application & Application User");
artifact.setAttribute("overview_wsdl", null);
artifact.setAttribute("overview_apiSecurity", "oauth2,oauth_basic_auth_api_key_mandatory");
artifact.setAttribute("URITemplate_authType0", "Application & Application User");
artifact.setAttribute("overview_keyManagers", "[\"all\"]");
artifact.setAttribute("overview_environments", "Default");
artifact.setAttribute("overview_context", "/t/wso2.com/pizzashack/1.0.0");
artifact.setAttribute("overview_visibility", "restricted");
artifact.setAttribute("overview_isLatest", "true");
artifact.setAttribute("overview_outSequence", "log_out_message");
artifact.setAttribute("overview_provider", "admin-AT-wso2.com");
artifact.setAttribute("apiCategories_categoryName", "testcategory");
artifact.setAttribute("overview_thumbnail", "/t/wso2.com/t/wso2.com/registry/resource/_system/governance/apimgt/applicationdata/provider/admin-AT-wso2.com/PizzaShackAPI/1.0.0/icon");
artifact.setAttribute("overview_contextTemplate", "/t/wso2.com/pizzashack/{version}");
artifact.setAttribute("overview_description", "This is a simple API for Pizza Shack online pizza delivery store.");
artifact.setAttribute("overview_technicalOwner", "John Doe");
artifact.setAttribute("overview_type", "HTTP");
artifact.setAttribute("overview_technicalOwnerEmail", "architecture@pizzashack.com");
artifact.setAttribute("URITemplate_httpVerb4", "DELETE");
artifact.setAttribute("overview_inSequence", "log_in_message");
artifact.setAttribute("URITemplate_httpVerb2", "GET");
artifact.setAttribute("URITemplate_httpVerb3", "PUT");
artifact.setAttribute("URITemplate_httpVerb0", "POST");
artifact.setAttribute("URITemplate_httpVerb1", "GET");
artifact.setAttribute("labels_labelName", "gwlable");
artifact.setAttribute("overview_businessOwner", "Jane Roe");
artifact.setAttribute("overview_version", "1.0.0");
artifact.setAttribute("overview_endpointConfig", "{\"endpoint_type\":\"http\",\"sandbox_endpoints\":{\"url\":\"https://localhost:9443/am/sample/pizzashack/v1/api/\"}," + "\"endpoint_security\":{\"production\":{\"password\":\"admin\",\"tokenUrl\":null,\"clientId\":null," + "\"clientSecret\":null,\"customParameters\":\"{}\",\"additionalProperties\":{},\"type\":\"BASIC\"," + "\"grantType\":null,\"enabled\":true,\"uniqueIdentifier\":null,\"username\":\"admin\"}," + "\"sandbox\":{\"password\":null,\"tokenUrl\":null,\"clientId\":null,\"clientSecret\":null," + "\"customParameters\":\"{}\",\"additionalProperties\":{},\"type\":null,\"grantType\":null,\"enabled\":false," + "\"uniqueIdentifier\":null,\"username\":null}},\"production_endpoints\":" + "{\"url\":\"https://localhost:9443/am/sample/pizzashack/v1/api/\"}}");
artifact.setAttribute("overview_tier", "Bronze||Silver||Gold||Unlimited");
artifact.setAttribute("overview_sandboxTps", "1000");
artifact.setAttribute("overview_apiOwner", "admin@wso2.com");
artifact.setAttribute("overview_businessOwnerEmail", "marketing@pizzashack.com");
artifact.setAttribute("isMonetizationEnabled", "false");
artifact.setAttribute("overview_implementation", "ENDPOINT");
artifact.setAttribute("overview_deployments", "null");
artifact.setAttribute("overview_redirectURL", null);
artifact.setAttribute("monetizationProperties", "{}");
artifact.setAttribute("overview_name", "PizzaShackAPI");
artifact.setAttribute("overview_subscriptionAvailability", "current_tenant");
artifact.setAttribute("overview_productionTps", "1000");
artifact.setAttribute("overview_cacheTimeout", "300");
artifact.setAttribute("overview_visibleRoles", "admin,internal/subscriber");
artifact.setAttribute("overview_testKey", null);
artifact.setAttribute("overview_corsConfiguration", "{\"corsConfigurationEnabled\":true,\"accessControlAllowOrigins\":[\"*\"]," + "\"accessControlAllowCredentials\":false,\"accessControlAllowHeaders\":[\"authorization\"," + "\"Access-Control-Allow-Origin\",\"Content-Type\",\"SOAPAction\",\"apikey\",\"testKey\"]," + "\"accessControlAllowMethods\":[\"GET\",\"PUT\",\"POST\",\"DELETE\",\"PATCH\",\"OPTIONS\"]}");
artifact.setAttribute("overview_advertiseOnly", "false");
artifact.setAttribute("overview_versionType", "context");
artifact.setAttribute("overview_status", "PUBLISHED");
artifact.setAttribute("overview_endpointPpassword", null);
artifact.setAttribute("overview_tenants", null);
artifact.setAttribute("overview_endpointAuthDigest", "false");
artifact.setAttribute("overview_faultSequence", "json_fault");
artifact.setAttribute("overview_responseCaching", "Enabled");
artifact.setAttribute("URITemplate_urlPattern4", "/order/{orderId}");
artifact.setAttribute("overview_isDefaultVersion", "true");
artifact.setAttribute("URITemplate_urlPattern2", "/order/{orderId}");
artifact.setAttribute("URITemplate_urlPattern3", "/order/{orderId}");
artifact.setAttribute("URITemplate_urlPattern0", "/order");
artifact.setAttribute("URITemplate_urlPattern1", "/menu");
artifact.setAttribute("overview_enableStore", "true");
artifact.setAttribute("overview_enableSchemaValidation", "true");
artifact.setAttribute("overview_endpointUsername", null);
artifact.setAttribute("overview_status", "PUBLISHED");
artifact.setId("88e758b7-6924-4e9f-8882-431070b6492b");
return artifact;
}
use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.
the class PersistenceHelper method getSampleAPIProductArtifact.
public static GenericArtifact getSampleAPIProductArtifact() throws GovernanceException {
GenericArtifact artifact = new GenericArtifactImpl(new QName("", "APIProductTest", ""), "application/vnd.wso2-api+xml");
artifact.setAttribute("overview_transports", "http,https");
artifact.setAttribute("monetizationProperties", "{}");
artifact.setAttribute("overview_authorizationHeader", "Authorization");
artifact.setAttribute("overview_visibleTenants", null);
artifact.setAttribute("overview_name", "APIProductTest");
artifact.setAttribute("overview_apiSecurity", "oauth2,oauth_basic_auth_api_key_mandatory,basic_auth,api_key");
artifact.setAttribute("overview_environments", "Default");
artifact.setAttribute("overview_subscriptionAvailability", "all_tenants");
artifact.setAttribute("overview_context", "/prodcontext");
artifact.setAttribute("overview_visibility", "restricted");
artifact.setAttribute("overview_cacheTimeout", "300");
artifact.setAttribute("overview_provider", "admin");
artifact.setAttribute("overview_visibleRoles", "admin");
artifact.setAttribute("apiCategories_categoryName", "testcategory");
artifact.setAttribute("overview_contextTemplate", "/prodcontext/{version}");
artifact.setAttribute("overview_thumbnail", null);
artifact.setAttribute("overview_description", "sample product");
artifact.setAttribute("overview_technicalOwner", null);
artifact.setAttribute("overview_type", "APIProduct");
artifact.setAttribute("overview_technicalOwnerEmail", null);
artifact.setAttribute("overview_corsConfiguration", "{\"corsConfigurationEnabled\":false," + "\"accessControlAllowOrigins\":[\"*\"],\"accessControlAllowCredentials\":false," + "\"accessControlAllowHeaders\":[\"authorization\",\"Access-Control-Allow-Origin\",\"Content-Type\"," + "\"SOAPAction\",\"apikey\",\"testKey\"],\"accessControlAllowMethods\":[\"GET\",\"PUT\",\"POST\"," + "\"DELETE\",\"PATCH\",\"OPTIONS\"]}");
artifact.setAttribute("overview_versionType", "context");
artifact.setAttribute("overview_status", "PUBLISHED");
artifact.setAttribute("overview_businessOwner", "productOwner");
artifact.setAttribute("overview_version", "1.0.0");
artifact.setAttribute("overview_tenants", null);
artifact.setAttribute("overview_responseCaching", "Disabled");
artifact.setAttribute("overview_tier", "Bronze||Gold");
artifact.setAttribute("overview_businessOwnerEmail", "owner@test.com");
artifact.setAttribute("isMonetizationEnabled", "false");
artifact.setAttribute("overview_enableStore", "true");
artifact.setAttribute("overview_enableSchemaValidation", "false");
artifact.setId("88e758b7-6924-4e9f-8882-431070b6492b");
return artifact;
}
use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.
the class APIKeyValidatorTestCase method testGetKeyValidationInfo.
/*
* Test method fpr getKeyValidationInfo()
* */
@Test
public void testGetKeyValidationInfo() throws Exception {
String context = "/";
String apiKey = "abc";
String apiVersion = "1.0";
String authenticationScheme = "";
String clientDomain = "abc.com";
String matchingResource = "/menu";
String httpVerb = "get";
boolean defaultVersionInvoked = true;
APIKeyValidator apiKeyValidator = createAPIKeyValidator(false, getDefaultURITemplates("/menu", "GET"), getDefaultVerbInfoDTO());
APIKeyValidationInfoDTO apiKeyValidationInfoDTO = new APIKeyValidationInfoDTO();
apiKeyValidationInfoDTO.setApiName(apiKey);
PowerMockito.mockStatic(CacheProvider.class);
PowerMockito.mockStatic(Cache.class);
Cache cache = Mockito.mock(Cache.class);
PowerMockito.mockStatic(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
PowerMockito.mockStatic(APIManagerConfigurationService.class);
PowerMockito.mockStatic(CacheProvider.class);
org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder MockServiceReferenceHolder = Mockito.mock(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
final APIManagerConfiguration MockApiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.getInstance()).thenReturn(MockServiceReferenceHolder);
APIManagerConfigurationService MockApiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
PowerMockito.when(MockServiceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(MockApiManagerConfigurationService);
PowerMockito.when(MockApiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(MockApiManagerConfiguration);
PowerMockito.when(CacheProvider.getDefaultCacheTimeout()).thenReturn((long) 900);
Mockito.when(CacheProvider.getGatewayKeyCache()).thenReturn(cache);
Mockito.when(CacheProvider.getResourceCache()).thenReturn(cache);
Mockito.when(CacheProvider.getGatewayTokenCache()).thenReturn(cache);
Mockito.when(CacheProvider.getInvalidTokenCache()).thenReturn(cache);
Assert.assertEquals(apiKeyValidationInfoDTO.getApiName(), apiKeyValidator.getKeyValidationInfo(context, apiKey, apiVersion, authenticationScheme, matchingResource, httpVerb, defaultVersionInvoked, new ArrayList<>()).getApiName());
// Test for token cache is found in token cache
AxisConfiguration axisConfig = Mockito.mock(AxisConfiguration.class);
APIKeyValidator newApiKeyValidator = new APIKeyValidator() {
@Override
protected String getTenantDomain() {
return "zyx";
}
@Override
protected APIManagerConfiguration getApiManagerConfiguration() {
APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(configuration.getFirstProperty(APIConstants.TOKEN_CACHE_EXPIRY)).thenReturn("900");
Mockito.when(configuration.getFirstProperty(APIConstants.GATEWAY_TOKEN_CACHE_ENABLED)).thenReturn("true");
return configuration;
}
@Override
protected Cache getCache(String cacheManagerName, String cacheName, long modifiedExp, long accessExp) {
return Mockito.mock(Cache.class);
}
@Override
protected APIKeyValidationInfoDTO doGetKeyValidationInfo(String context, String apiVersion, String apiKey, String authenticationScheme, String matchingResource, String httpVerb, String tenantDomain, List<String> keyManagers) throws APISecurityException {
APIKeyValidationInfoDTO apiKeyValidationInfoDTO = Mockito.mock(APIKeyValidationInfoDTO.class);
Mockito.when(apiKeyValidationInfoDTO.getApiName()).thenReturn(apiKey);
return apiKeyValidationInfoDTO;
}
};
Assert.assertEquals(apiKeyValidationInfoDTO.getApiName(), newApiKeyValidator.getKeyValidationInfo(context, apiKey, apiVersion, authenticationScheme, matchingResource, httpVerb, defaultVersionInvoked, new ArrayList<>()).getApiName());
}
Aggregations