Search in sources :

Example 6 with IPCondition

use of org.wso2.carbon.apimgt.core.models.policy.IPCondition in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createNewIPRangePipeline.

/**
 * Creates a new {@link Pipeline} instance
 *
 * @return created Pipeline instance
 */
public static Pipeline createNewIPRangePipeline() {
    IPCondition ipCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
    ipCondition.setStartingIP("10.100.0.105");
    ipCondition.setEndingIP("10.100.0.115");
    Pipeline pipeline = new Pipeline();
    RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType(REQUEST_COUNT_TYPE);
    quotaPolicy.setLimit(requestCountLimit);
    pipeline.setQuotaPolicy(quotaPolicy);
    pipeline.setConditions(Arrays.asList(ipCondition));
    return pipeline;
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline)

Example 7 with IPCondition

use of org.wso2.carbon.apimgt.core.models.policy.IPCondition in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultPipelines.

/**
 * create default pipeline for api policy
 *
 * @return list of Pipeline objects is returned
 */
public static List<Pipeline> createDefaultPipelines() {
    // Pipeline 1
    IPCondition ipCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
    ipCondition.setStartingIP("192.168.12.3");
    ipCondition.setEndingIP("192.168.88.19");
    IPCondition ipConditionSpecific = new IPCondition(PolicyConstants.IP_SPECIFIC_TYPE);
    ipConditionSpecific.setSpecificIP("123.42.14.56");
    // adding above conditions to condition list of pipeline 1
    // contains conditions for each pipeline
    List<Condition> conditionsList = new ArrayList<>();
    conditionsList.add(ipCondition);
    conditionsList.add(ipConditionSpecific);
    // set quota policy with bandwidth limit
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_MONTH, 1, 1000, PolicyConstants.MB);
    QuotaPolicy quotaPolicy1 = new QuotaPolicy();
    quotaPolicy1.setType(PolicyConstants.BANDWIDTH_TYPE);
    quotaPolicy1.setLimit(bandwidthLimit);
    Pipeline pipeline1 = new Pipeline();
    pipeline1.setConditions(conditionsList);
    pipeline1.setQuotaPolicy(quotaPolicy1);
    // End of pipeline 1 -> Beginning of pipeline 2
    HeaderCondition headerCondition = new HeaderCondition();
    headerCondition.setHeader("Browser");
    headerCondition.setValue("Chrome");
    JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
    jwtClaimsCondition.setClaimUrl("/path/path2");
    jwtClaimsCondition.setAttribute("attributed");
    QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
    queryParameterCondition.setParameter("Location");
    queryParameterCondition.setValue("Colombo");
    // adding conditions to condition list of pipeline2
    conditionsList = new ArrayList<>();
    conditionsList.add(headerCondition);
    conditionsList.add(jwtClaimsCondition);
    conditionsList.add(queryParameterCondition);
    // pipeline 2 with request count as quota policy
    RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
    QuotaPolicy quotaPolicy2 = new QuotaPolicy();
    quotaPolicy2.setType(PolicyConstants.REQUEST_COUNT_TYPE);
    quotaPolicy2.setLimit(requestCountLimit);
    Pipeline pipeline2 = new Pipeline();
    pipeline2.setConditions(conditionsList);
    pipeline2.setQuotaPolicy(quotaPolicy2);
    // adding pipelines
    // contains all the default pipelines
    List<Pipeline> pipelineList = new ArrayList<>();
    pipelineList.add(pipeline1);
    pipelineList.add(pipeline2);
    return pipelineList;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) Condition(org.wso2.carbon.apimgt.core.models.policy.Condition) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) ArrayList(java.util.ArrayList) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline) IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 8 with IPCondition

use of org.wso2.carbon.apimgt.core.models.policy.IPCondition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromIPConditionToDTO.

/**
 * Converts an IP Condition model object into a DTO
 *
 * @param ipCondition IP Condition model object
 * @return DTO object derived from model object
 */
public static ThrottleConditionDTO fromIPConditionToDTO(IPCondition ipCondition) throws UnsupportedThrottleConditionTypeException {
    String ipConditionType = mapIPConditionTypeFromModelToDTO(ipCondition.getType());
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    throttleConditionDTO.setIpCondition(new IPConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(ipCondition, throttleConditionDTO);
    throttleConditionDTO.getIpCondition().setIpConditionType(ipConditionType);
    throttleConditionDTO.getIpCondition().setSpecificIP(ipCondition.getSpecificIP());
    throttleConditionDTO.getIpCondition().setStartingIP(ipCondition.getStartingIP());
    throttleConditionDTO.getIpCondition().setEndingIP(ipCondition.getEndingIP());
    return throttleConditionDTO;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 9 with IPCondition

use of org.wso2.carbon.apimgt.core.models.policy.IPCondition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtilTestCase method fromSpecificIPConditionDtoToIPConditionModelTest.

@Test(description = "Convert IP specific IPCondition DTO to IPCondition Model object")
public void fromSpecificIPConditionDtoToIPConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    IPConditionDTO ipConditionDTO = new IPConditionDTO();
    ipConditionDTO.setIpConditionType(PolicyConstants.IP_SPECIFIC_TYPE);
    ipConditionDTO.setSpecificIP("10.100.0.168");
    throttleConditionDTO.setIpCondition(ipConditionDTO);
    IPCondition condition = (IPCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    Assert.assertNotNull(condition.getCondition());
    assertEquals(condition.getSpecificIP(), "10.100.0.168");
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) Test(org.testng.annotations.Test)

Aggregations

IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)7 Test (org.testng.annotations.Test)3 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)3 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)3 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)3 ArrayList (java.util.ArrayList)2 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)2 Condition (org.wso2.carbon.apimgt.core.models.policy.Condition)2 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)2 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)2 QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)2 IPConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)1 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)1 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)1