use of org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition in project carbon-apimgt by wso2.
the class PolicyDAOImpl method setJWTClaimConditions.
/**
* Add JWT claim conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
* provided {@link Condition} array
*
* @param pipelineId Id of the pipeline
* @param conditions condition array to populate
* @throws SQLException
*/
private void setJWTClaimConditions(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
final String query = "SELECT " + "CLAIM_URI, " + "CLAIM_ATTRIB , IS_CLAIM_MAPPING " + "FROM " + "AM_JWT_CLAIM_CONDITION " + "WHERE " + "CONDITION_GROUP_ID =?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setInt(1, pipelineId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
jwtClaimsCondition.setClaimUrl(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_URI));
jwtClaimsCondition.setAttribute(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_ATTRIBUTE));
jwtClaimsCondition.setInvertCondition(resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_IS_CLAIM_MAPPING));
conditions.add(jwtClaimsCondition);
}
}
}
}
use of org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultPipelines.
/**
* create default pipeline for api policy
*
* @return list of Pipeline objects is returned
*/
public static List<Pipeline> createDefaultPipelines() {
// Pipeline 1
IPCondition ipCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
ipCondition.setStartingIP("192.168.12.3");
ipCondition.setEndingIP("192.168.88.19");
IPCondition ipConditionSpecific = new IPCondition(PolicyConstants.IP_SPECIFIC_TYPE);
ipConditionSpecific.setSpecificIP("123.42.14.56");
// adding above conditions to condition list of pipeline 1
// contains conditions for each pipeline
List<Condition> conditionsList = new ArrayList<>();
conditionsList.add(ipCondition);
conditionsList.add(ipConditionSpecific);
// set quota policy with bandwidth limit
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_MONTH, 1, 1000, PolicyConstants.MB);
QuotaPolicy quotaPolicy1 = new QuotaPolicy();
quotaPolicy1.setType(PolicyConstants.BANDWIDTH_TYPE);
quotaPolicy1.setLimit(bandwidthLimit);
Pipeline pipeline1 = new Pipeline();
pipeline1.setId(0);
pipeline1.setConditions(conditionsList);
pipeline1.setQuotaPolicy(quotaPolicy1);
// End of pipeline 1 -> Beginning of pipeline 2
HeaderCondition headerCondition = new HeaderCondition();
headerCondition.setHeader("Browser");
headerCondition.setValue("Chrome");
JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
jwtClaimsCondition.setClaimUrl("/path/path2");
jwtClaimsCondition.setAttribute("attributed");
QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
queryParameterCondition.setParameter("Location");
queryParameterCondition.setValue("Colombo");
// adding conditions to condition list of pipeline2
conditionsList = new ArrayList<>();
conditionsList.add(headerCondition);
conditionsList.add(jwtClaimsCondition);
conditionsList.add(queryParameterCondition);
// pipeline 2 with request count as quota policy
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
QuotaPolicy quotaPolicy2 = new QuotaPolicy();
quotaPolicy2.setType(REQUEST_COUNT_TYPE);
quotaPolicy2.setLimit(requestCountLimit);
Pipeline pipeline2 = new Pipeline();
pipeline2.setId(1);
pipeline2.setConditions(conditionsList);
pipeline2.setQuotaPolicy(quotaPolicy2);
// adding pipelines
// contains all the default pipelines
List<Pipeline> pipelineList = new ArrayList<>();
pipelineList.add(pipeline1);
pipelineList.add(pipeline2);
return pipelineList;
}
use of org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition 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 JWTClaimsConditionDTO fromJWTClaimsConditionToDTO(JWTClaimsCondition condition) {
JWTClaimsConditionDTO dto = new JWTClaimsConditionDTO();
dto.setClaimUrl(condition.getClaimUrl());
dto.setAttribute(condition.getAttribute());
return dto;
}
use of org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOListToConditionList.
/**
* Converts a list of Throttle Condition DTOs into a list of Condition model objects
*
* @param throttleConditionDTOs list of Throttle Condition DTOs
* @return Derived list of Condition model objects from Throttle Condition DTOs
* @throws UnsupportedThrottleConditionTypeException
*/
public static List<Condition> fromDTOListToConditionList(List<ThrottleConditionDTO> throttleConditionDTOs) throws UnsupportedThrottleConditionTypeException {
List<Condition> conditions = new ArrayList<>();
String errorMessage;
if (throttleConditionDTOs != null) {
for (ThrottleConditionDTO dto : throttleConditionDTOs) {
ThrottleConditionDTO.TypeEnum conditionType = dto.getType();
if (conditionType != null) {
switch(conditionType) {
case HEADERCONDITION:
{
if (dto.getHeaderCondition() != null) {
conditions.add(fromDTOToHeaderCondition(dto.getHeaderCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.HEADERCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
case IPCONDITION:
{
if (dto.getIpCondition() != null) {
conditions.add(fromDTOToIPCondition(dto.getIpCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.IPCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
case QUERYPARAMETERCONDITION:
{
if (dto.getQueryParameterCondition() != null) {
conditions.add(fromDTOToQueryParameterCondition(dto.getQueryParameterCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.QUERYPARAMETERCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
case JWTCLAIMSCONDITION:
{
if (dto.getJwtClaimsCondition() != null) {
conditions.add(fromDTOToJWTClaimsCondition(dto.getJwtClaimsCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.JWTCLAIMSCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
default:
return null;
}
} else {
errorMessage = "Condition item 'type' property has not been specified\n" + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
}
}
return conditions;
}
use of org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition 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;
}
Aggregations