Search in sources :

Example 41 with Event

use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method addThreatProtectionPolicy.

/**
 * {@inheritDoc}
 */
@Override
public void addThreatProtectionPolicy(ThreatProtectionPolicy policy) throws GatewayException {
    ThreatProtectionEvent event = new ThreatProtectionEvent(APIMgtConstants.GatewayEventTypes.THREAT_PROTECTION_POLICY_ADD);
    event.setPolicy(policy);
    publishToThreatProtectionTopic(event);
}
Also used : ThreatProtectionEvent(org.wso2.carbon.apimgt.core.models.events.ThreatProtectionEvent)

Example 42 with Event

use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.

the class ConfigureJsonAnalyzer method execute.

@Override
public BValue[] execute(Context context) {
    String event = getStringArgument(context, 0);
    // configure json analyzer
    BStruct jsonInfo = ((BStruct) getRefArgument(context, 0));
    if (jsonInfo != null) {
        String jsonPolicyId = jsonInfo.getStringField(0);
        switch(event) {
            case THREAT_PROTECTION_POLICY_ADD:
            case THREAT_PROTECTION_POLICY_UPDATE:
                String name = jsonInfo.getStringField(1);
                int propertyCount = (int) jsonInfo.getIntField(0);
                int stringLength = (int) jsonInfo.getIntField(1);
                int arrayElementCount = (int) jsonInfo.getIntField(2);
                int keyLength = (int) jsonInfo.getIntField(3);
                int maxJSONDepth = (int) jsonInfo.getIntField(4);
                JSONConfig jsonConfig = new JSONConfig();
                jsonConfig.setName(name);
                jsonConfig.setMaxPropertyCount(propertyCount);
                jsonConfig.setMaxStringLength(stringLength);
                jsonConfig.setMaxArrayElementCount(arrayElementCount);
                jsonConfig.setMaxKeyLength(keyLength);
                jsonConfig.setMaxJsonDepth(maxJSONDepth);
                // put into ConfigurationHolder
                ConfigurationHolder.addJsonConfig(jsonPolicyId, jsonConfig);
                break;
            case THREAT_PROTECTION_POLICY_DELETE:
                ConfigurationHolder.removeJsonConfig(jsonPolicyId);
                break;
            default:
                log.warn("Unknown event type for Threat Protection Policy. Event: " + event);
                break;
        }
    }
    return getBValues(new BBoolean(true));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BBoolean(org.ballerinalang.model.values.BBoolean) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig)

Example 43 with Event

use of org.wso2.siddhi.core.event.Event in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testObserverEventListener.

@Test(description = "Event Observers for event listening")
public void testObserverEventListener() throws APIManagementException {
    EventLogger observer = Mockito.mock(EventLogger.class);
    APIStoreImpl apiStore = getApiStoreImpl();
    apiStore.registerObserver(observer);
    Event event = Event.APP_CREATION;
    String username = USER_NAME;
    Map<String, String> metaData = new HashMap<>();
    ZonedDateTime eventTime = ZonedDateTime.now(ZoneOffset.UTC);
    apiStore.notifyObservers(event, username, eventTime, metaData);
    Mockito.verify(observer, Mockito.times(1)).captureEvent(event, username, eventTime, metaData);
}
Also used : HashMap(java.util.HashMap) ZonedDateTime(java.time.ZonedDateTime) Event(org.wso2.carbon.apimgt.core.models.Event) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 Event (org.wso2.carbon.apimgt.core.models.Event)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 Test (org.testng.annotations.Test)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 Function (org.wso2.carbon.apimgt.core.models.Function)4 ZonedDateTime (java.time.ZonedDateTime)3 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)3 API (org.wso2.carbon.apimgt.core.models.API)3 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)3 ApplicationEvent (org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)3 PolicyEvent (org.wso2.carbon.apimgt.core.models.events.PolicyEvent)3 ThreatProtectionEvent (org.wso2.carbon.apimgt.core.models.events.ThreatProtectionEvent)3 Gson (com.google.gson.Gson)2 URI (java.net.URI)2