use of org.wso2.balana.utils.policy.dto.AttributeDesignatorDTO in project carbon-identity-framework by wso2.
the class PolicyEditorUtil method processGreaterLessThanFunctions.
/**
* Process less than and greater than functions
*
* @param function
* @param dataType
* @param attributeValue
* @param designatorDTO
* @return
* @throws PolicyEditorException
*/
public static ApplyElementDTO processGreaterLessThanFunctions(String function, String dataType, String attributeValue, AttributeDesignatorDTO designatorDTO) throws PolicyEditorException {
String[] values = attributeValue.split(PolicyEditorConstants.ATTRIBUTE_SEPARATOR);
if (PolicyConstants.Functions.FUNCTION_GREATER_EQUAL_AND_LESS_EQUAL.equals(function) || PolicyConstants.Functions.FUNCTION_GREATER_AND_LESS_EQUAL.equals(function) || PolicyConstants.Functions.FUNCTION_GREATER_EQUAL_AND_LESS.equals(function) || PolicyConstants.Functions.FUNCTION_GREATER_AND_LESS.equals(function)) {
String leftValue;
String rightValue;
if (values.length == 2) {
leftValue = values[0].trim();
rightValue = values[1].trim();
} else {
throw new PolicyEditorException("Can not create Apply element:" + "Missing required attribute values for function : " + function);
}
ApplyElementDTO andApplyElement = new ApplyElementDTO();
andApplyElement.setFunctionId(processFunction("and"));
ApplyElementDTO greaterThanApplyElement = new ApplyElementDTO();
if (PolicyConstants.Functions.FUNCTION_GREATER_AND_LESS.equals(function) || PolicyConstants.Functions.FUNCTION_GREATER_AND_LESS_EQUAL.equals(function)) {
greaterThanApplyElement.setFunctionId(processFunction("greater-than", dataType));
} else {
greaterThanApplyElement.setFunctionId(processFunction("greater-than-or-equal", dataType));
}
ApplyElementDTO lessThanApplyElement = new ApplyElementDTO();
if (PolicyConstants.Functions.FUNCTION_GREATER_AND_LESS.equals(function) || PolicyConstants.Functions.FUNCTION_GREATER_EQUAL_AND_LESS.equals(function)) {
lessThanApplyElement.setFunctionId(processFunction("less-than", dataType));
} else {
lessThanApplyElement.setFunctionId(processFunction("less-than-or-equal", dataType));
}
ApplyElementDTO oneAndOnlyApplyElement = new ApplyElementDTO();
oneAndOnlyApplyElement.setFunctionId(processFunction("one-and-only", dataType));
oneAndOnlyApplyElement.setAttributeDesignators(designatorDTO);
AttributeValueElementDTO leftValueElementDTO = new AttributeValueElementDTO();
leftValueElementDTO.setAttributeDataType(dataType);
leftValueElementDTO.setAttributeValue(leftValue);
AttributeValueElementDTO rightValueElementDTO = new AttributeValueElementDTO();
rightValueElementDTO.setAttributeDataType(dataType);
rightValueElementDTO.setAttributeValue(rightValue);
greaterThanApplyElement.setApplyElement(oneAndOnlyApplyElement);
greaterThanApplyElement.setAttributeValueElementDTO(leftValueElementDTO);
lessThanApplyElement.setApplyElement(oneAndOnlyApplyElement);
lessThanApplyElement.setAttributeValueElementDTO(rightValueElementDTO);
andApplyElement.setApplyElement(greaterThanApplyElement);
andApplyElement.setApplyElement(lessThanApplyElement);
return andApplyElement;
} else {
ApplyElementDTO applyElementDTO = new ApplyElementDTO();
if (PolicyConstants.Functions.FUNCTION_GREATER.equals(function)) {
applyElementDTO.setFunctionId(processFunction("greater-than", dataType));
} else if (PolicyConstants.Functions.FUNCTION_GREATER_EQUAL.equals(function)) {
applyElementDTO.setFunctionId(processFunction("greater-than-or-equal", dataType));
} else if (PolicyConstants.Functions.FUNCTION_LESS.equals(function)) {
applyElementDTO.setFunctionId(processFunction("less-than", dataType));
} else if (PolicyConstants.Functions.FUNCTION_LESS_EQUAL.equals(function)) {
applyElementDTO.setFunctionId(processFunction("less-than-or-equal", dataType));
} else {
throw new PolicyEditorException("Can not create Apply element:" + "Invalid function : " + function);
}
ApplyElementDTO oneAndOnlyApplyElement = new ApplyElementDTO();
oneAndOnlyApplyElement.setFunctionId(processFunction("one-and-only", dataType));
oneAndOnlyApplyElement.setAttributeDesignators(designatorDTO);
AttributeValueElementDTO valueElementDTO = new AttributeValueElementDTO();
valueElementDTO.setAttributeDataType(dataType);
valueElementDTO.setAttributeValue(values[0]);
applyElementDTO.setApplyElement(oneAndOnlyApplyElement);
applyElementDTO.setAttributeValueElementDTO(valueElementDTO);
return applyElementDTO;
}
}
use of org.wso2.balana.utils.policy.dto.AttributeDesignatorDTO in project carbon-identity-framework by wso2.
the class PolicyEditorUtil method createAttributeDesignatorElement.
/**
* This method creates attribute designator DOM element
*
* @param attributeDesignatorDTO attribute designator data object
* @param doc XML document
* @return attribute designator element as DOM
* @throws PolicyEditorException throws if missing required data
*/
public static Element createAttributeDesignatorElement(AttributeDesignatorDTO attributeDesignatorDTO, Document doc) throws PolicyEditorException {
Element attributeDesignatorElement;
if (attributeDesignatorDTO != null && doc != null) {
String category = attributeDesignatorDTO.getCategory();
String attributeId = attributeDesignatorDTO.getAttributeId();
String dataType = attributeDesignatorDTO.getDataType();
String mustBe = attributeDesignatorDTO.getMustBePresent();
if (category != null && category.trim().length() > 0 && attributeId != null && attributeId.trim().length() > 0 && dataType != null && dataType.trim().length() > 0 && mustBe != null && mustBe.trim().length() > 0) {
attributeDesignatorElement = doc.createElement(PolicyEditorConstants.ATTRIBUTE_DESIGNATOR);
attributeDesignatorElement.setAttribute(PolicyEditorConstants.ATTRIBUTE_ID, attributeId);
attributeDesignatorElement.setAttribute(PolicyEditorConstants.CATEGORY, category);
attributeDesignatorElement.setAttribute(PolicyEditorConstants.DATA_TYPE, dataType);
attributeDesignatorElement.setAttribute(PolicyEditorConstants.MUST_BE_PRESENT, mustBe);
if (attributeDesignatorDTO.getIssuer() != null && attributeDesignatorDTO.getIssuer().trim().length() > 0) {
attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.ISSUER, attributeDesignatorDTO.getIssuer());
}
} else {
throw new PolicyEditorException("Can not create AttributeDesignator element:" + " Required Attributes are missing");
}
} else {
throw new PolicyEditorException("Can not create AttributeDesignator element:" + " A Null object is received");
}
return attributeDesignatorElement;
}
use of org.wso2.balana.utils.policy.dto.AttributeDesignatorDTO in project carbon-identity-framework by wso2.
the class PolicyEditorUtil method processEqualFunctions.
/**
* Process equal function
*
* @param function
* @param dataType
* @param attributeValue
* @param designatorDTO
* @return
*/
public static ApplyElementDTO processEqualFunctions(String function, String dataType, String attributeValue, AttributeDesignatorDTO designatorDTO) {
if (PolicyConstants.Functions.FUNCTION_EQUAL.equals(function)) {
ApplyElementDTO applyElementDTO = new ApplyElementDTO();
if (PolicyEditorConstants.DataType.DAY_TIME_DURATION.equals(dataType) || PolicyEditorConstants.DataType.YEAR_MONTH_DURATION.equals(dataType)) {
applyElementDTO.setFunctionId(processFunction("equal", dataType, "3.0"));
} else {
applyElementDTO.setFunctionId(processFunction("equal", dataType));
}
ApplyElementDTO oneAndOnlyApplyElement = new ApplyElementDTO();
oneAndOnlyApplyElement.setFunctionId(processFunction("one-and-only", dataType));
oneAndOnlyApplyElement.setAttributeDesignators(designatorDTO);
if (applyElementMap.containsKey(attributeValue)) {
applyElementDTO.setApplyElement(applyElementMap.get(attributeValue));
} else {
AttributeValueElementDTO valueElementDTO = new AttributeValueElementDTO();
valueElementDTO.setAttributeDataType(dataType);
valueElementDTO.setAttributeValue(attributeValue);
applyElementDTO.setAttributeValueElementDTO(valueElementDTO);
}
applyElementDTO.setApplyElement(oneAndOnlyApplyElement);
return applyElementDTO;
}
return null;
}
use of org.wso2.balana.utils.policy.dto.AttributeDesignatorDTO in project carbon-identity-framework by wso2.
the class PolicyEditorUtil method processRegexpFunctions.
/**
* Process regexp-match functions.
*
* @param function Function name.
* @param dataType Data type.
* @param attributeValue Attribute Value.
* @param designatorDTO AttributeDesignator information.
* @return ApplyElementDTO.
*/
public static ApplyElementDTO processRegexpFunctions(String function, String dataType, String attributeValue, AttributeDesignatorDTO designatorDTO) {
if (PolicyConstants.Functions.FUNCTION_EQUAL_MATCH_REGEXP.equals(function)) {
ApplyElementDTO applyElementDTO = new ApplyElementDTO();
applyElementDTO.setFunctionId(PolicyConstants.XACMLData.FUNCTION_ANY_OF);
if (applyElementMap.containsKey(attributeValue)) {
applyElementDTO.setApplyElement(applyElementMap.get(attributeValue));
} else {
AttributeValueElementDTO valueElementDTO = new AttributeValueElementDTO();
valueElementDTO.setAttributeDataType(dataType);
valueElementDTO.setAttributeValue(attributeValue);
applyElementDTO.setAttributeValueElementDTO(valueElementDTO);
}
applyElementDTO.setFunctionFunctionId(processFunction(PolicyConstants.Functions.FUNCTION_EQUAL_MATCH_REGEXP, dataType));
applyElementDTO.setAttributeDesignators(designatorDTO);
return applyElementDTO;
}
return null;
}
use of org.wso2.balana.utils.policy.dto.AttributeDesignatorDTO in project carbon-identity-framework by wso2.
the class PolicyEditorUtil method createApplyElement.
/**
* @param dynamicAttributeDTO
* @param map
* @return
*/
private static ApplyElementDTO createApplyElement(ExtendAttributeDTO dynamicAttributeDTO, Map<String, ExtendAttributeDTO> map) {
if (PolicyEditorConstants.DYNAMIC_SELECTOR_CATEGORY.equals(dynamicAttributeDTO.getSelector())) {
String category = dynamicAttributeDTO.getCategory();
String attributeId = dynamicAttributeDTO.getAttributeId();
String attributeDataType = dynamicAttributeDTO.getDataType();
if (category != null && category.trim().length() > 0 && attributeDataType != null && attributeDataType.trim().length() > 0) {
AttributeDesignatorDTO designatorDTO = new AttributeDesignatorDTO();
designatorDTO.setCategory(category);
designatorDTO.setAttributeId(attributeId);
designatorDTO.setDataType(attributeDataType);
designatorDTO.setMustBePresent("true");
ApplyElementDTO applyElementDTO = new ApplyElementDTO();
applyElementDTO.setAttributeDesignators(designatorDTO);
applyElementDTO.setFunctionId(processFunction("bag", attributeDataType));
return applyElementDTO;
}
} else {
String function = dynamicAttributeDTO.getFunction();
String attributeValue = dynamicAttributeDTO.getAttributeValue();
String attributeDataType = dynamicAttributeDTO.getDataType();
if (attributeValue != null && function != null) {
String[] values = attributeValue.split(",");
if (values != null && values.length > 0) {
if (function.contains("concatenate")) {
ApplyElementDTO applyElementDTO = new ApplyElementDTO();
applyElementDTO.setFunctionId(processFunction(function, attributeDataType, "2.0"));
// there can be any number of inputs
for (String value : values) {
if (map.containsKey(value)) {
applyElementDTO.setApplyElement(createApplyElement(map.get(value), map));
} else {
AttributeValueElementDTO valueElementDTO = new AttributeValueElementDTO();
valueElementDTO.setAttributeDataType(attributeDataType);
valueElementDTO.setAttributeValue(value);
applyElementDTO.setAttributeValueElementDTO(valueElementDTO);
}
}
return applyElementDTO;
}
}
}
}
return null;
}
Aggregations