Search in sources :

Example 36 with ThreatProtectionPolicy

use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesPolicyIdGet.

/**
 * Get a specific threat protection policy
 *
 * @param policyId ID of the policy to be retrieved
 * @param request
 * @return Threat protection policy
 * @throws NotFoundException
 */
@Override
public Response threatProtectionPoliciesPolicyIdGet(String policyId, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        ThreatProtectionPolicy policy = apiPublisher.getThreatProtectionPolicy(policyId);
        if (policy == null) {
            return Response.status(404).entity("Requested policy was not found.").build();
        }
        return Response.ok().entity(MappingUtil.toThreatProtectionPolicyDTO(policy)).build();
    } catch (APIManagementException e) {
        log.error(e.getMessage(), e);
    }
    return Response.status(500).entity("Internal Server Error.").build();
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher)

Example 37 with ThreatProtectionPolicy

use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.

the class MappingUtil method toThreatProtectionPolicyDTO.

public static ThreatProtectionPolicyDTO toThreatProtectionPolicyDTO(ThreatProtectionPolicy policy) {
    ThreatProtectionPolicyDTO dto = new ThreatProtectionPolicyDTO();
    dto.setUuid(policy.getUuid());
    dto.setType(policy.getType());
    dto.setName(policy.getName());
    dto.setPolicy(policy.getPolicy());
    return dto;
}
Also used : ThreatProtectionPolicyDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO)

Aggregations

ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)27 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)12 Test (org.testng.annotations.Test)10 ThreatProtectionDAO (org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO)9 ArrayList (java.util.ArrayList)7 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)6 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)3 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)3 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)3 ThreatProtectionEvent (org.wso2.carbon.apimgt.core.models.events.ThreatProtectionEvent)3 ResultSet (java.sql.ResultSet)2 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)2 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ThreatProtectionPolicyDTO)2