use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImpl method deleteBlockConditionByUUID.
@Override
public boolean deleteBlockConditionByUUID(String uuid) throws APIManagementException {
boolean deleteState = false;
BlockConditionsDTO blockCondition = apiMgtDAO.getBlockConditionByUUID(uuid);
if (blockCondition != null) {
deleteState = apiMgtDAO.deleteBlockCondition(blockCondition.getConditionId());
if (deleteState) {
unpublishBlockCondition(blockCondition);
}
}
return deleteState;
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImpl method updateBlockConditionByUUID.
@Override
public boolean updateBlockConditionByUUID(String uuid, String state) throws APIManagementException {
boolean updateState = apiMgtDAO.updateBlockConditionStateByUUID(uuid, state);
BlockConditionsDTO blockConditionsDTO = apiMgtDAO.getBlockConditionByUUID(uuid);
if (updateState && blockConditionsDTO != null) {
publishBlockingEventUpdate(blockConditionsDTO);
}
return updateState;
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class APIProviderImpl method publishBlockingEvent.
/**
* Publishes the changes on blocking conditions.
* @param blockConditionsDTO Blockcondition Dto event
*/
private void publishBlockingEvent(BlockConditionsDTO blockConditionsDTO, String state) {
String conditionType = blockConditionsDTO.getConditionType();
String conditionValue = blockConditionsDTO.getConditionValue();
if (APIConstants.BLOCKING_CONDITIONS_IP.equals(conditionType) || APIConstants.BLOCK_CONDITION_IP_RANGE.equals(conditionType)) {
conditionValue = StringEscapeUtils.escapeJava(conditionValue);
}
Object[] objects = new Object[] { blockConditionsDTO.getConditionId(), blockConditionsDTO.getConditionType(), conditionValue, state, tenantDomain };
Event blockingMessage = new Event(APIConstants.BLOCKING_CONDITIONS_STREAM_ID, System.currentTimeMillis(), null, null, objects);
EventPublisherEvent blockingEvent = new EventPublisherEvent(APIConstants.BLOCKING_CONDITIONS_STREAM_ID, System.currentTimeMillis(), objects, blockingMessage.toString());
APIUtil.publishEvent(EventPublisherType.BLOCKING_EVENT, blockingEvent, blockingMessage.toString());
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingDenyPolicyConditionIdDelete.
/**
* Delete a block condition specified by the condition Id
*
* @param conditionId Id of the block condition
* @return 200 OK response if successfully deleted the block condition
*/
@Override
public Response throttlingDenyPolicyConditionIdDelete(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 existingCondition = apiProvider.getBlockConditionByUUID(conditionId);
if (!RestApiAdminUtils.isBlockConditionAccessibleToUser(username, existingCondition)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, log);
}
apiProvider.deleteBlockConditionByUUID(conditionId);
return Response.ok().build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, e, log);
} else {
String errorMessage = "Error while deleting Block Condition. Id : " + conditionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.internal.service.dto.BlockConditionsDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingDenyPolicyConditionIdPatch.
/**
* Updates an existing condition status of a blocking condition
*
* @param conditionId Id of the block condition
* @param body content to update
* @param contentType Content-Type header
* @return 200 response if successful
*/
@Override
public Response throttlingDenyPolicyConditionIdPatch(String conditionId, String contentType, BlockingConditionStatusDTO body, 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 existingCondition = apiProvider.getBlockConditionByUUID(conditionId);
if (!RestApiAdminUtils.isBlockConditionAccessibleToUser(username, existingCondition)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, log);
}
// update the status
apiProvider.updateBlockConditionByUUID(conditionId, String.valueOf(body.isConditionStatus()));
// retrieve the new blocking condition and send back as the response
BlockConditionsDTO newBlockingCondition = apiProvider.getBlockConditionByUUID(conditionId);
BlockingConditionDTO dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(newBlockingCondition);
return Response.ok().entity(dto).build();
} catch (APIManagementException | ParseException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, e, log);
} else {
String errorMessage = "Error while updating Block Condition Status. Id : " + conditionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
Aggregations