Search in sources :

Example 1 with BlockingConditionRetriever

use of org.wso2.carbon.apimgt.gateway.throttling.util.BlockingConditionRetriever in project carbon-apimgt by wso2.

the class GatewayStartupListener method retrieveBlockConditionsAndKeyTemplates.

private void retrieveBlockConditionsAndKeyTemplates() {
    if (throttleProperties.getBlockCondition().isEnabled()) {
        BlockingConditionRetriever webServiceThrottleDataRetriever = new BlockingConditionRetriever();
        webServiceThrottleDataRetriever.startWebServiceThrottleDataRetriever();
        KeyTemplateRetriever webServiceBlockConditionsRetriever = new KeyTemplateRetriever();
        webServiceBlockConditionsRetriever.startKeyTemplateDataRetriever();
        // Start web service based revoked JWT tokens retriever.
        // Advanced throttle properties & blocking conditions have to be enabled for JWT token
        // retrieval due to the throttle config dependency for this feature.
        RevokedJWTTokensRetriever webServiceRevokedJWTTokensRetriever = new RevokedJWTTokensRetriever();
        webServiceRevokedJWTTokensRetriever.startRevokedJWTTokensRetriever();
    }
}
Also used : RevokedJWTTokensRetriever(org.wso2.carbon.apimgt.gateway.jwt.RevokedJWTTokensRetriever) BlockingConditionRetriever(org.wso2.carbon.apimgt.gateway.throttling.util.BlockingConditionRetriever) KeyTemplateRetriever(org.wso2.carbon.apimgt.gateway.throttling.util.KeyTemplateRetriever)

Example 2 with BlockingConditionRetriever

use of org.wso2.carbon.apimgt.gateway.throttling.util.BlockingConditionRetriever in project carbon-apimgt by wso2.

the class BlockingConditionRetrieverTest method run.

@Test
public void run() throws Exception {
    String content = "{\"api\":[\"/pizzashack/1.0.0\"],\"application\":[\"admin:DefaultApplication\"]," + "\"ip\":[{\"fixedIp\":\"127.0.0.1\",\"invert\":false,\"type\":\"IP\",\"tenantDomain\":\"carbon" + ".super\"}],\"user\":[\"admin\"],\"custom\":[]}";
    PowerMockito.mockStatic(APIUtil.class);
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
    BasicHttpEntity httpEntity = new BasicHttpEntity();
    httpEntity.setContent(new ByteArrayInputStream(content.getBytes()));
    Mockito.when(httpResponse.getEntity()).thenReturn(httpEntity);
    StatusLine status = Mockito.mock(StatusLine.class);
    Mockito.when(status.getStatusCode()).thenReturn(200);
    Mockito.when(httpResponse.getStatusLine()).thenReturn(status);
    Mockito.when(httpClient.execute(Mockito.any(HttpGet.class))).thenReturn(httpResponse);
    BDDMockito.given(APIUtil.getHttpClient(Mockito.anyInt(), Mockito.anyString())).willReturn(httpClient);
    EventHubConfigurationDto eventHubConfigurationDto = new EventHubConfigurationDto();
    eventHubConfigurationDto.setUsername("admin");
    eventHubConfigurationDto.setPassword("admin".toCharArray());
    eventHubConfigurationDto.setEnabled(true);
    eventHubConfigurationDto.setServiceUrl("http://localhost:18083/internal/data/v1");
    ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
    BlockingConditionRetriever blockingConditionRetriever = new BlockingConditionRetrieverWrapper(eventHubConfigurationDto, throttleDataHolder);
    blockingConditionRetriever.run();
    Assert.assertTrue(throttleDataHolder.isRequestBlocked("/pizzashack/1.0.0", "admin:DefaultApplication", "admin", "127.0.0.1", "carbon.super", "/pizzashack/1.0.0:1.0.0:admin-DefaultApplication"));
}
Also used : StatusLine(org.apache.http.StatusLine) EventHubConfigurationDto(org.wso2.carbon.apimgt.impl.dto.EventHubConfigurationDto) ThrottleDataHolder(org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 HttpClient (org.apache.http.client.HttpClient)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 RevokedJWTTokensRetriever (org.wso2.carbon.apimgt.gateway.jwt.RevokedJWTTokensRetriever)1 ThrottleDataHolder (org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder)1 BlockingConditionRetriever (org.wso2.carbon.apimgt.gateway.throttling.util.BlockingConditionRetriever)1 KeyTemplateRetriever (org.wso2.carbon.apimgt.gateway.throttling.util.KeyTemplateRetriever)1 EventHubConfigurationDto (org.wso2.carbon.apimgt.impl.dto.EventHubConfigurationDto)1