use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class BlockingConditionMappingUtil method fromBlockingConditionToDTO.
/**
* Converts a single Block Condition model object into REST API DTO object.
*
* @param blockCondition Block condition model object
* @return Block condition DTO object derived from block condition model object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static BlockingConditionDTO fromBlockingConditionToDTO(BlockConditions blockCondition) throws UnsupportedThrottleLimitTypeException {
if (blockCondition.getUuid() == null) {
return null;
}
BlockingConditionDTO dto = new BlockingConditionDTO();
dto.setConditionId(blockCondition.getUuid());
dto.setConditionType(blockCondition.getConditionType());
dto.setStatus(blockCondition.isEnabled());
if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE.equals(blockCondition.getConditionType())) {
dto.setIpCondition(fromBlockConditionToIpConditionDTO(blockCondition));
}
String conditionValue = blockCondition.getConditionValue();
dto.setConditionValue(conditionValue);
return dto;
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToHeaderCondition.
/**
* Converts a Header Condition DTO object into a model object
*
* @param dto Header Condition DTO object
* @return Header Condition model object derived from Header Condition DTO
*/
public static HeaderCondition fromDTOToHeaderCondition(ThrottleConditionDTO dto) {
HeaderCondition headerCondition = new HeaderCondition();
headerCondition = updateFieldsFromDTOToCondition(dto, headerCondition);
headerCondition.setHeader(dto.getHeaderCondition().getHeaderName());
headerCondition.setValue(dto.getHeaderCondition().getHeaderValue());
return headerCondition;
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromHeaderConditionToDTO.
/**
* Converts a Header Condition model object into a DTO
*
* @param headerCondition Header Condition model object
* @return DTO object that was derived from Header Condition model object
*/
public static ThrottleConditionDTO fromHeaderConditionToDTO(HeaderCondition headerCondition) {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.HEADER_CONDITION_TYPE);
throttleConditionDTO.setHeaderCondition(new HeaderConditionDTO());
throttleConditionDTO = updateFieldsFromConditionToDTO(headerCondition, throttleConditionDTO);
throttleConditionDTO.getHeaderCondition().setHeaderName(headerCondition.getHeaderName());
throttleConditionDTO.getHeaderCondition().setHeaderValue(headerCondition.getValue());
return throttleConditionDTO;
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class BlacklistApiServiceImpl method blacklistConditionIdDelete.
/**
* Delete blacklist condition using ID
*
* @param conditionId condition ID of the block condition
* @param ifMatch IF-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Response Object
* @throws NotFoundException Iif an error occurred when particular resource does not exits in the system.
*/
@Override
public Response blacklistConditionIdDelete(String conditionId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Blacklist Condition DELETE request with id: " + conditionId);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
apiMgtAdminService.deleteBlockConditionByUuid(conditionId);
return Response.ok().build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while deleting blacklist condition with UUID " + conditionId;
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition 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.setId(0);
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(REQUEST_COUNT_TYPE);
quotaPolicy2.setLimit(requestCountLimit);
Pipeline pipeline2 = new Pipeline();
pipeline2.setId(1);
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;
}
Aggregations