Search in sources :

Example 11 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromConditionToDTO.

/**
 * Converts a Throttle Condition model object into a DTO
 *
 * @param condition Throttle condition model object
 * @return Derived DTO object from the model object
 * @throws UnsupportedThrottleConditionTypeException
 */
public static // .................
ThrottleConditionDTO fromConditionToDTO(// .................
Condition condition) throws UnsupportedThrottleConditionTypeException {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setInvertCondition(condition.isInvertCondition());
    if (condition instanceof IPCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.IPCONDITION);
        throttleConditionDTO.setIpCondition(fromIPConditionToDTO((IPCondition) condition));
    } else if (condition instanceof HeaderCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.HEADERCONDITION);
        throttleConditionDTO.setHeaderCondition(fromHeaderConditionToDTO((HeaderCondition) condition));
    } else if (condition instanceof QueryParameterCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.QUERYPARAMETERCONDITION);
        throttleConditionDTO.setQueryParameterCondition(fromQueryParameterConditionToDTO((QueryParameterCondition) condition));
    } else if (condition instanceof JWTClaimsCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.JWTCLAIMSCONDITION);
        throttleConditionDTO.setJwtClaimsCondition(fromJWTClaimsConditionToDTO((JWTClaimsCondition) condition));
    } else {
        String msg = "Throttle Condition type " + condition.getClass().getName() + " is not supported";
        throw new UnsupportedThrottleConditionTypeException(msg);
    }
    return throttleConditionDTO;
}
Also used : IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) UnsupportedThrottleConditionTypeException(org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)

Example 12 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromJWTClaimsConditionToDTO.

/**
 * Converts a JWT Claims Condition model object into a DTO
 *
 * @param condition JWT Claims Condition model object
 * @return DTO object that was derived from JWT Claims Condition model object
 */
public static ThrottleConditionDTO fromJWTClaimsConditionToDTO(JWTClaimsCondition condition) {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.JWT_CLAIMS_CONDITION_TYPE);
    throttleConditionDTO.setJwtClaimsCondition(new JWTClaimsConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(condition, throttleConditionDTO);
    throttleConditionDTO.getJwtClaimsCondition().setClaimUrl(condition.getClaimUrl());
    throttleConditionDTO.getJwtClaimsCondition().setAttribute(condition.getAttribute());
    return throttleConditionDTO;
}
Also used : JWTClaimsConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.JWTClaimsConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 13 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOToJWTClaimsCondition.

/**
 * Converts a JWT Claims Condition DTO object into a model object
 *
 * @param dto JWT Claims Condition DTO object
 * @return JWT Claims Condition model object derived from JWT Claims Condition DTO
 */
public static JWTClaimsCondition fromDTOToJWTClaimsCondition(ThrottleConditionDTO dto) {
    JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
    jwtClaimsCondition = updateFieldsFromDTOToCondition(dto, jwtClaimsCondition);
    jwtClaimsCondition.setAttribute(dto.getJwtClaimsCondition().getAttribute());
    jwtClaimsCondition.setClaimUrl(dto.getJwtClaimsCondition().getClaimUrl());
    return jwtClaimsCondition;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)

Example 14 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromIPConditionToDTO.

/**
 * Converts an IP Condition model object into a DTO
 *
 * @param ipCondition IP Condition model object
 * @return DTO object derived from model object
 */
public static ThrottleConditionDTO fromIPConditionToDTO(IPCondition ipCondition) throws UnsupportedThrottleConditionTypeException {
    String ipConditionType = mapIPConditionTypeFromModelToDTO(ipCondition.getType());
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    throttleConditionDTO.setIpCondition(new IPConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(ipCondition, throttleConditionDTO);
    throttleConditionDTO.getIpCondition().setIpConditionType(ipConditionType);
    throttleConditionDTO.getIpCondition().setSpecificIP(ipCondition.getSpecificIP());
    throttleConditionDTO.getIpCondition().setStartingIP(ipCondition.getStartingIP());
    throttleConditionDTO.getIpCondition().setEndingIP(ipCondition.getEndingIP());
    return throttleConditionDTO;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 15 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtilTestCase method fromJWTConditionDtoToJWTConditionModelTest.

@Test(description = "Convert JWT Condition DTO to JWTCondition Model object")
public void fromJWTConditionDtoToJWTConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.JWT_CLAIMS_CONDITION_TYPE);
    JWTClaimsConditionDTO jwtClaimsConditionDTO = new JWTClaimsConditionDTO();
    jwtClaimsConditionDTO.setAttribute("testAttribute");
    jwtClaimsConditionDTO.setClaimUrl("http://wso2.org/claims");
    throttleConditionDTO.setJwtClaimsCondition(jwtClaimsConditionDTO);
    JWTClaimsCondition condition = (JWTClaimsCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    assertEquals(condition.getAttribute(), "testAttribute");
    assertEquals(condition.getClaimUrl(), "http://wso2.org/claims");
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)5 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)5 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)3 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO)3 UnsupportedThrottleConditionTypeException (org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException)2 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)2 IPCondition (org.wso2.carbon.apimgt.api.model.policy.IPCondition)2 JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)2 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)2 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)2 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)2 QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)2 ArrayList (java.util.ArrayList)1 Condition (org.wso2.carbon.apimgt.api.model.policy.Condition)1 ConditionalGroupDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ConditionalGroupDTO)1 HeaderConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.HeaderConditionDTO)1 IPConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO)1 JWTClaimsConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.JWTClaimsConditionDTO)1 QueryParameterConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.QueryParameterConditionDTO)1 ConditionalGroupDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ConditionalGroupDTO)1