use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingDenyPolicyConditionIdGet.
/**
* Get a specific Block condition by its id
*
* @param conditionId Id of the block condition
* @return Matched block condition for the given Id
*/
@Override
public Response throttlingDenyPolicyConditionIdGet(String conditionId, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String username = RestApiCommonUtil.getLoggedInUsername();
// This will give BlockConditionNotFoundException if there's no block condition exists with UUID
BlockConditionsDTO blockCondition = apiProvider.getBlockConditionByUUID(conditionId);
if (!RestApiAdminUtils.isBlockConditionAccessibleToUser(username, blockCondition)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, log);
}
BlockingConditionDTO dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(blockCondition);
return Response.ok().entity(dto).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, e, log);
} else {
String errorMessage = "Error while retrieving Block Condition. Id : " + conditionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
} catch (ParseException e) {
String errorMessage = "Error while retrieving Blocking Conditions";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingDenyPoliciesGet.
/**
* Retrieves all Block Conditions
*
* @param accept Accept header value
* @return All matched block conditions to the given request
*/
@Override
public Response throttlingDenyPoliciesGet(String accept, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
List<BlockConditionsDTO> blockConditions = apiProvider.getBlockConditions();
BlockingConditionListDTO listDTO = BlockingConditionMappingUtil.fromBlockConditionListToListDTO(blockConditions);
return Response.ok().entity(listDTO).build();
} catch (APIManagementException | ParseException e) {
String errorMessage = "Error while retrieving Block Conditions";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.BlockConditionsDTO 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
*/
public static BlockingConditionDTO fromBlockingConditionToDTO(BlockConditionsDTO blockCondition) throws ParseException {
BlockingConditionDTO dto = new BlockingConditionDTO();
dto.setConditionId(blockCondition.getUUID());
dto.setConditionType(BlockingConditionDTO.ConditionTypeEnum.fromValue(blockCondition.getConditionType()));
if (APIConstants.BLOCKING_CONDITIONS_API.equals(blockCondition.getConditionType()) || APIConstants.BLOCKING_CONDITIONS_APPLICATION.equals(blockCondition.getConditionType()) || APIConstants.BLOCKING_CONDITIONS_USER.equals(blockCondition.getConditionType())) {
dto.setConditionValue(blockCondition.getConditionValue());
} else if (APIConstants.BLOCKING_CONDITIONS_IP.equals(blockCondition.getConditionType()) || APIConstants.BLOCK_CONDITION_IP_RANGE.equalsIgnoreCase(blockCondition.getConditionType())) {
Object parse = new JSONParser().parse(blockCondition.getConditionValue());
dto.setConditionValue(parse);
}
dto.setConditionStatus(blockCondition.isEnabled());
return dto;
}
Aggregations