use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method deleteThreatProtectionPolicy.
/**
* {@inheritDoc}
*/
@Override
public void deleteThreatProtectionPolicy(ThreatProtectionPolicy policy) throws GatewayException {
ThreatProtectionEvent event = new ThreatProtectionEvent(APIMgtConstants.GatewayEventTypes.THREAT_PROTECTION_POLICY_DELETE);
event.setPolicy(policy);
publishToThreatProtectionTopic(event);
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addThreatProtectionPolicy.
/**
* {@inheritDoc}
*/
@Override
public void addThreatProtectionPolicy(ThreatProtectionPolicy policy) throws GatewayException {
ThreatProtectionEvent event = new ThreatProtectionEvent(APIMgtConstants.GatewayEventTypes.THREAT_PROTECTION_POLICY_ADD);
event.setPolicy(policy);
publishToThreatProtectionTopic(event);
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImpl method addPolicy.
/**
* Add a threat protection policy to database
* @param policy Threat protection policy
* @param connection SQL Connection
* @throws APIMgtDAOException If failed to add policy
*/
private void addPolicy(ThreatProtectionPolicy policy, Connection connection) throws APIMgtDAOException {
final String sqlQuery = "INSERT INTO " + THREAT_PROTECTION_TABLE + " (UUID, NAME, TYPE, POLICY) " + " VALUES (?, ?, ?, ?)";
try (PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
preparedStatement.setString(1, policy.getUuid());
preparedStatement.setString(2, policy.getName());
preparedStatement.setString(3, policy.getType());
preparedStatement.setBytes(4, policy.getPolicy().getBytes("UTF-8"));
preparedStatement.executeUpdate();
} catch (SQLException e) {
String errorMsg = "Error adding Threat Protection policy";
throw new APIMgtDAOException(errorMsg, e);
} catch (UnsupportedEncodingException e) {
String errorMsg = "Charset error in threat protection policy";
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImpl method getPolicy.
/**
* Get a single threat protection policy
* @param policyId Threat protection policy id
* @param connection SQL Connection
* @return The threat protection policy with policy id. null if not found.
* @throws APIMgtDAOException If failed to retrieve the policy
*/
private ThreatProtectionPolicy getPolicy(String policyId, Connection connection) throws APIMgtDAOException {
final String sqlQuery = "SELECT UUID, NAME, TYPE, POLICY " + " FROM " + THREAT_PROTECTION_TABLE + " WHERE UUID = ?";
try (PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
preparedStatement.setString(1, policyId);
try (ResultSet rs = preparedStatement.executeQuery()) {
ThreatProtectionPolicy policy = null;
if (rs.next()) {
policy = new ThreatProtectionPolicy();
policy.setUuid(rs.getString(F_UUID));
policy.setName(rs.getString(F_NAME));
policy.setType(rs.getString(F_TYPE));
policy.setPolicy(new String(rs.getBytes(F_POLICY), "UTF-8"));
} else {
log.warn("No Threat Protection Policy found for PolicyId: " + policyId);
}
return policy;
} catch (UnsupportedEncodingException e) {
String errorMsg = "Charset error in threat protection policy";
throw new APIMgtDAOException(errorMsg, e);
}
} catch (SQLException e) {
String errorMsg = "Error getting threat protection policy";
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImpl method getPolicies.
/**
* Get a list of all threat protection policies
* @param connection SQL Connection
* @return List of threat protection policies
* @throws APIMgtDAOException if failed to retrieve the list of policies
*/
private List<ThreatProtectionPolicy> getPolicies(Connection connection) throws APIMgtDAOException {
final String sqlQuery = "SELECT UUID, NAME, TYPE, POLICY " + " FROM " + THREAT_PROTECTION_TABLE;
try (PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
try (ResultSet rs = preparedStatement.executeQuery()) {
List<ThreatProtectionPolicy> list = new ArrayList<>();
while (rs.next()) {
ThreatProtectionPolicy policy = new ThreatProtectionPolicy();
policy.setUuid(rs.getString(F_UUID));
policy.setName(rs.getString(F_NAME));
policy.setType(rs.getString(F_TYPE));
policy.setPolicy(new String(rs.getBytes(F_POLICY), "UTF-8"));
list.add(policy);
}
return list;
} catch (UnsupportedEncodingException e) {
String errorMsg = "Charset error in threat protection policy";
throw new APIMgtDAOException(errorMsg, e);
}
} catch (SQLException e) {
String errorMsg = "Error getting threat protection policies";
throw new APIMgtDAOException(errorMsg, e);
}
}
Aggregations