Search in sources :

Example 1 with APIKey

use of org.wso2.carbon.apimgt.api.model.APIKey in project product-apim by wso2.

the class ApiClient method setApiKey.

/**
 * Helper method to configure the first api key found
 *
 * @param apiKey API key
 */
public void setApiKey(String apiKey) {
    for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof ApiKeyAuth) {
            ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization;
            keyAuth.setApiKey(apiKey);
            return;
        }
    }
    throw new RuntimeException("No API key authentication configured!");
}
Also used : RequestInterceptor(feign.RequestInterceptor) ApiKeyAuth(org.wso2.carbon.apimgt.rest.integration.tests.store.auth.ApiKeyAuth)

Example 2 with APIKey

use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultSiddhiAppForAPIThrottlePolicy.

public static String createDefaultSiddhiAppForAPIThrottlePolicy() {
    APIPolicy apiPolicy = createDefaultAPIPolicy();
    String siddhiApp = "\n@App:name('resource_" + apiPolicy.getPolicyName() + "_condition_0')" + "\n@App:description('ExecutionPlan for resource_" + apiPolicy.getPolicyName() + "_condition_0')\n" + "\n@source(type='inMemory', topic='apim', @map(type='passThrough'))" + "\ndefine stream RequestStream (messageID string, appKey string, appTier string, " + "subscriptionKey string," + " apiKey string, apiTier string, subscriptionTier string, resourceKey string," + " resourceTier string, userId string,  apiContext string, apiVersion string, " + "appTenant string, apiTenant " + "string, appId string, apiName string, propertiesMap string);\n" + "\n@sink(type='jms', @map(type='text')," + "\nfactory.initial='org.wso2.andes.jndi.PropertiesFileInitialContextFactory'," + " provider.url='tcp://localhost:5672', " + "destination='TEST.FOO', connection.factory.type='topic'," + "\nconnection.factory.jndi.name='TopicConnectionFactory')" + "\ndefine stream GlobalThrottleStream (throttleKey string, isThrottled bool," + " expiryTimeStamp long);\n" + "\nFROM RequestStream" + "\nSELECT messageID, (resourceTier == 'SampleAPIPolicy' AND (regex:find('Chrome'," + "cast(map:get(propertiesMap,'Browser')," + "'string'))) AND (regex:find('attributed'," + "cast(map:get(propertiesMap,'/path/path2'),'string'))) AND " + "(cast(map:get(propertiesMap,'Location'),'string')=='Colombo'))" + " AS isEligible, str:concat(resourceKey," + "'_condition_0') AS throttleKey, propertiesMap" + "\nINSERT INTO EligibilityStream;\n" + "\nFROM EligibilityStream[isEligible==true]#throttler:timeBatch(1 s, 0)" + "\nselect throttleKey, (count(messageID) >= 1000) as isThrottled," + " expiryTimeStamp group by throttleKey" + "\nINSERT ALL EVENTS into ResultStream;\n" + "\nfrom ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)" + "\nselect *" + "\ninsert into GlobalThrottleStream;\n";
    return siddhiApp;
}
Also used : APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy)

Example 3 with APIKey

use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultSiddhiAppforSubscriptionPolicy.

public static String createDefaultSiddhiAppforSubscriptionPolicy() {
    SubscriptionPolicy policy = createDefaultSubscriptionPolicy();
    RequestCountLimit limit = (RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit();
    String siddhiApp = "@App:name('subscription_" + policy.getPolicyName() + "')\n" + "\n@App:description('ExecutionPlan for subscription_" + policy.getPolicyName() + "')\n" + "\n@source(type='inMemory', topic='apim', @map(type='passThrough'))\n" + "define stream RequestStream (messageID string, appKey string, appTier string," + " subscriptionKey string," + " apiKey string, apiTier string, subscriptionTier string, resourceKey string, resourceTier string," + " userId string,  apiContext string, apiVersion string, appTenant string, apiTenant string, " + "appId string, apiName string, propertiesMap string);\n" + "\n@sink(type='jms', @map(type='text'),\n" + "factory.initial='org.wso2.andes.jndi.PropertiesFileInitialContextFactory'," + " provider.url='tcp://localhost:5672', destination='TEST.FOO', connection.factory." + "type='topic',\n" + "connection.factory.jndi.name='TopicConnectionFactory')\n" + "define stream GlobalThrottleStream (throttleKey string, isThrottled bool" + ", expiryTimeStamp long);\n" + "\nFROM RequestStream\n" + "SELECT messageID, (subscriptionTier == '" + policy.getPolicyName() + "')" + " AS isEligible, subscriptionKey AS throttleKey, propertiesMap\n" + "INSERT INTO EligibilityStream;\n" + "\nFROM EligibilityStream[isEligible==true]#throttler:timeBatch(" + policy.getDefaultQuotaPolicy().getLimit().getUnitTime() + " " + policy.getDefaultQuotaPolicy().getLimit().getTimeUnit() + ", 0)\n" + "select throttleKey, (count(messageID) >= " + limit.getRequestCount() + ")" + " as isThrottled, expiryTimeStamp group by throttleKey\n" + "INSERT ALL EVENTS into ResultStream;\n" + "\nfrom ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)" + " select * " + "insert into GlobalThrottleStream;\n";
    return siddhiApp;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)

Example 4 with APIKey

use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultCustomPolicySiddhiApp.

public static String createDefaultCustomPolicySiddhiApp() {
    CustomPolicy policy = createDefaultCustomPolicy();
    String siddhiApp = "@App:name('custom_" + policy.getPolicyName() + "')" + "\n@App:description('ExecutionPlan for custom_" + policy.getPolicyName() + "')\n" + "\n@source(type='inMemory', topic='apim', @map(type='passThrough'))\n" + "define stream RequestStream (messageID string, appKey string, appTier string, " + "subscriptionKey string, apiKey string, apiTier string, subscriptionTier string," + " resourceKey string, resourceTier string, userId string,  apiContext string, " + "apiVersion string, appTenant string, apiTenant string, appId string, apiName string, " + "propertiesMap string);\n" + "\n@sink(type='jms', @map(type='text'),\n" + "factory.initial='org.wso2.andes.jndi.PropertiesFileInitialContextFactory'," + " provider.url='tcp://localhost:5672', destination='TEST.FOO'," + " connection.factory.type='topic',\n" + "connection.factory.jndi.name='TopicConnectionFactory')\n" + "define stream GlobalThrottleStream (throttleKey string, isThrottled bool, " + "expiryTimeStamp long);\n" + "\n" + policy.getSiddhiQuery() + "\n" + "\nfrom ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)" + "\nselect *\n" + "insert into GlobalThrottleStream;\n";
    return siddhiApp;
}
Also used : CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)

Example 5 with APIKey

use of org.wso2.carbon.apimgt.api.model.APIKey in project carbon-apimgt by wso2.

the class TestMappingUtilTestCase method testSecuritySchemeIntToListMapping.

@Test
void testSecuritySchemeIntToListMapping() {
    int securityScheme = 3;
    List<String> securitySchemeList = MappingUtil.mapSecuritySchemeIntToList(securityScheme);
    List<String> testList = new ArrayList<String>();
    testList.add("Oauth");
    testList.add("apikey");
    assertEquals(securitySchemeList, testList);
}
Also used : ArrayList(java.util.ArrayList) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Aggregations

APIKey (org.wso2.carbon.apimgt.api.model.APIKey)22 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)14 APIKeyValidationInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO)14 Test (org.junit.Test)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 ArrayList (java.util.ArrayList)12 Application (org.wso2.carbon.apimgt.api.model.Application)10 Cache (javax.cache.Cache)9 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)9 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)9 HashSet (java.util.HashSet)7 APIKeyDataStore (org.wso2.carbon.apimgt.gateway.handlers.security.keys.APIKeyDataStore)7 WSAPIKeyDataStore (org.wso2.carbon.apimgt.gateway.handlers.security.keys.WSAPIKeyDataStore)7 ApplicationKeyDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO)6 ExportedApplication (org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedApplication)5 IOException (java.io.IOException)4 LinkedHashSet (java.util.LinkedHashSet)4 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)4 APISecurityException (org.wso2.carbon.apimgt.gateway.handlers.security.APISecurityException)4 Connection (java.sql.Connection)3