Search in sources :

Example 1 with BotDetectionData

use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.

the class AlertSubscriptionsApiServiceImpl method getBotDetectionAlertSubscriptions.

/**
 * Retrieve a list of bot detection alert subscriptions
 *
 * @param messageContext CXF Message Context
 * @return list of bot detection alert subscriptions
 * @throws APIManagementException if an error occurs when retrieving bot detection alert subscriptions
 */
@Override
public Response getBotDetectionAlertSubscriptions(MessageContext messageContext) throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    List<BotDetectionData> botDetectionDataList = apiAdmin.getBotDetectionAlertSubscriptions();
    BotDetectionAlertSubscriptionListDTO listDTO = BotDetectionMappingUtil.fromAlertSubscriptionListToListDTO(botDetectionDataList);
    return Response.ok().entity(listDTO).build();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) BotDetectionAlertSubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionListDTO)

Example 2 with BotDetectionData

use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.

the class AlertSubscriptionsApiServiceImpl method subscribeForBotDetectionAlerts.

/**
 * Subscribe for bot detection alerts
 *
 * @param body           email to be registered for the subscription
 * @param messageContext CXF Message Context
 * @return alert subscription DTO containing the uuid of the subscription and the registered email
 * @throws APIManagementException if an error occurs when subscribing for bot detection alerts
 */
@Override
public Response subscribeForBotDetectionAlerts(BotDetectionAlertSubscriptionDTO body, MessageContext messageContext) throws APIManagementException {
    String email = body.getEmail();
    if (StringUtils.isBlank(email)) {
        String propertyName = AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD;
        throw new APIManagementException(propertyName + " property value of payload cannot be blank", ExceptionCodes.from(ExceptionCodes.BLANK_PROPERTY_VALUE, propertyName));
    }
    APIAdmin apiAdmin = new APIAdminImpl();
    BotDetectionData alertSubscription = apiAdmin.getBotDetectionAlertSubscription(AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD, email);
    if (alertSubscription != null) {
        RestApiUtil.handleResourceAlreadyExistsError("Email: " + email + " has already been subscribed for bot detection alerts", log);
    }
    apiAdmin.addBotDetectionAlertSubscription(email);
    BotDetectionData newAlertSubscription = apiAdmin.getBotDetectionAlertSubscription(AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD, email);
    BotDetectionAlertSubscriptionDTO alertSubscriptionDTO = BotDetectionMappingUtil.fromAlertSubscriptionToDTO(newAlertSubscription);
    return Response.ok(alertSubscriptionDTO).build();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) BotDetectionAlertSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO)

Example 3 with BotDetectionData

use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.

the class AlertSubscriptionsApiServiceImpl method unsubscribeFromBotDetectionAlerts.

/**
 * Unsubscribe from bot detection alerts
 *
 * @param uuid           uuid of the subscription
 * @param messageContext CXF Message Context
 * @return 200 OK response if the subscription is deleted successfully
 * @throws APIManagementException if an error occurs when un-subscribing from bot detection alerts
 */
@Override
public Response unsubscribeFromBotDetectionAlerts(String uuid, MessageContext messageContext) throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    BotDetectionData alertSubscription = apiAdmin.getBotDetectionAlertSubscription("uuid", uuid);
    if (alertSubscription == null) {
        RestApiUtil.handleResourceNotFoundError("Bot detection alert subscription with uuid: " + uuid + " does not exist.", log);
    }
    apiAdmin.deleteBotDetectionAlertSubscription(uuid);
    return Response.ok().build();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 4 with BotDetectionData

use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.

the class BotDetectionDataApiServiceImpl method getBotDetectionData.

/**
 * Get all bot detected data
 *
 * @param messageContext CXF Message Context
 * @return list of all bot detected data
 * @throws APIManagementException if an error occurs when retrieving bot detection data
 */
public Response getBotDetectionData(MessageContext messageContext) throws APIManagementException {
    if (APIUtil.isAnalyticsEnabled()) {
        APIAdmin apiAdmin = new APIAdminImpl();
        List<BotDetectionData> botDetectionDataList = apiAdmin.retrieveBotDetectionData();
        BotDetectionDataListDTO listDTO = BotDetectionMappingUtil.fromBotDetectionModelToDTO(botDetectionDataList);
        return Response.ok().entity(listDTO).build();
    } else {
        throw new APIManagementException("Analytics Not Enabled", ExceptionCodes.from(ExceptionCodes.ANALYTICS_NOT_ENABLED, "Bot Detection Data is", "Bot Detection Data"));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) BotDetectionDataListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataListDTO) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 5 with BotDetectionData

use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.

the class ApiMgtDAO method getBotDetectionAlertSubscriptions.

/**
 * Retrieve all bot detection alert subscriptions
 *
 * @throws APIManagementException if an error occurs when retrieving bot detection alert subscriptions
 */
public List<BotDetectionData> getBotDetectionAlertSubscriptions() throws APIManagementException {
    List<BotDetectionData> list = new ArrayList<>();
    String query = SQLConstants.BotDataConstants.GET_SAVED_ALERT_EMAILS;
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement ps = connection.prepareStatement(query)) {
        ResultSet resultSet = ps.executeQuery();
        while (resultSet.next()) {
            BotDetectionData botDetectedData = new BotDetectionData();
            botDetectedData.setUuid(resultSet.getString("UUID"));
            botDetectedData.setEmail(resultSet.getString("SUBSCRIBER_ADDRESS"));
            list.add(botDetectedData);
        }
    } catch (SQLException e) {
        handleException("Error while retrieving bot detection alert subscriptions", e);
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) PreparedStatement(java.sql.PreparedStatement)

Aggregations

BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)9 ArrayList (java.util.ArrayList)4 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)4 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)4 BotDetectionAlertSubscriptionDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 BotDetectionAlertSubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionListDTO)2 BotDetectionDataDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataDTO)2 BotDetectionDataListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataListDTO)2 JsonObject (com.google.gson.JsonObject)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1