Search in sources :

Example 16 with JWTClaimsCondition

use of org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition in project carbon-apimgt by wso2.

the class ApiMgtDAO method createConditionGroupDTO.

/**
 * Converts an {@code Pipeline} object into a {@code ConditionGroupDTO}.{@code ConditionGroupDTO} class tries to
 * contain the same information held by  {@code Pipeline}, but in a much lightweight fashion.
 *
 * @param conditionGroup Id of the condition group ({@code Pipeline}) to be converted
 * @return An object of {@code ConditionGroupDTO} type.
 * @throws APIManagementException
 */
public ConditionGroupDTO createConditionGroupDTO(int conditionGroup) throws APIManagementException {
    List<Condition> conditions = getConditions(conditionGroup);
    ArrayList<ConditionDTO> conditionDTOs = new ArrayList<ConditionDTO>(conditions.size());
    for (Condition condition : conditions) {
        ConditionDTO conditionDTO = new ConditionDTO();
        conditionDTO.setConditionType(condition.getType());
        conditionDTO.isInverted(condition.isInvertCondition());
        if (PolicyConstants.IP_RANGE_TYPE.equals(condition.getType())) {
            IPCondition ipRangeCondition = (IPCondition) condition;
            conditionDTO.setConditionName(ipRangeCondition.getStartingIP());
            conditionDTO.setConditionValue(ipRangeCondition.getEndingIP());
        } else if (PolicyConstants.IP_SPECIFIC_TYPE.equals(condition.getType())) {
            IPCondition ipCondition = (IPCondition) condition;
            conditionDTO.setConditionName(PolicyConstants.IP_SPECIFIC_TYPE);
            conditionDTO.setConditionValue(ipCondition.getSpecificIP());
        } else if (PolicyConstants.HEADER_TYPE.equals(condition.getType())) {
            HeaderCondition headerCondition = (HeaderCondition) condition;
            conditionDTO.setConditionName(headerCondition.getHeaderName());
            conditionDTO.setConditionValue(headerCondition.getValue());
        } else if (PolicyConstants.JWT_CLAIMS_TYPE.equals(condition.getType())) {
            JWTClaimsCondition jwtClaimsCondition = (JWTClaimsCondition) condition;
            conditionDTO.setConditionName(jwtClaimsCondition.getClaimUrl());
            conditionDTO.setConditionValue(jwtClaimsCondition.getAttribute());
        } else if (PolicyConstants.QUERY_PARAMETER_TYPE.equals(condition.getType())) {
            QueryParameterCondition parameterCondition = (QueryParameterCondition) condition;
            conditionDTO.setConditionName(parameterCondition.getParameter());
            conditionDTO.setConditionValue(parameterCondition.getValue());
        }
        conditionDTOs.add(conditionDTO);
    }
    ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
    conditionGroupDTO.setConditions(conditionDTOs.toArray(new ConditionDTO[] {}));
    return conditionGroupDTO;
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition) Condition(org.wso2.carbon.apimgt.api.model.policy.Condition) IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) 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) ConditionDTO(org.wso2.carbon.apimgt.api.dto.ConditionDTO) ArrayList(java.util.ArrayList) ConditionGroupDTO(org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)

Example 17 with JWTClaimsCondition

use of org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition 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
 * @param invertCondition Invert condition relevant to the DTO
 * @return JWT Claims Condition model object derived from JWT Claims Condition DTO
 */
public static JWTClaimsCondition fromDTOToJWTClaimsCondition(JWTClaimsConditionDTO dto, boolean invertCondition) {
    JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
    jwtClaimsCondition.setConditionEnabled(Boolean.TRUE.toString());
    jwtClaimsCondition.setInvertCondition(invertCondition);
    jwtClaimsCondition.setAttribute(dto.getAttribute());
    jwtClaimsCondition.setClaimUrl(dto.getClaimUrl());
    return jwtClaimsCondition;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)

Aggregations

JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)10 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)8 IPCondition (org.wso2.carbon.apimgt.api.model.policy.IPCondition)8 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)8 ArrayList (java.util.ArrayList)6 Condition (org.wso2.carbon.apimgt.api.model.policy.Condition)5 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)5 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 UnsupportedThrottleConditionTypeException (org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException)2 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)2 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)2 DateCondition (org.wso2.carbon.apimgt.api.model.policy.DateCondition)2 DateRangeCondition (org.wso2.carbon.apimgt.api.model.policy.DateRangeCondition)2 HTTPVerbCondition (org.wso2.carbon.apimgt.api.model.policy.HTTPVerbCondition)2 Pipeline (org.wso2.carbon.apimgt.api.model.policy.Pipeline)2 QuotaPolicy (org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy)2 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)2 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)2 Condition (org.wso2.carbon.apimgt.core.models.policy.Condition)2