use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method createMetaDataFromMatchElement.
/**
* This extract policy meta data from match element in the policy
*
* @param omElement match element as an OMElement
* @param subElementName match element name
* @return AttributeValueDTO object which holds the policy meta data in String format
*/
public List<AttributeDTO> createMetaDataFromMatchElement(OMElement omElement, String subElementName) {
List<AttributeDTO> attributeDTOs = new ArrayList<AttributeDTO>();
String attributeId = null;
String dataType = null;
if (omElement != null) {
Iterator iterator1 = omElement.getChildrenWithLocalName(subElementName + PDPConstants.ATTRIBUTE_DESIGNATOR);
while (iterator1.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator1.next();
if (attributeDesignator != null) {
attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.ATTRIBUTE_ID));
dataType = attributeDesignator.getAttributeValue(new QName(PDPConstants.DATA_TYPE));
}
}
Iterator iterator2 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_SELECTOR);
while (iterator2.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator2.next();
if (attributeDesignator != null) {
attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.REQUEST_CONTEXT_PATH));
dataType = attributeDesignator.getAttributeValue(new QName(PDPConstants.DATA_TYPE));
}
}
Iterator iterator3 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_VALUE);
while (iterator3.hasNext()) {
OMElement attributeElement = (OMElement) iterator3.next();
if (attributeElement != null) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setAttributeValue(attributeElement.getText());
attributeDTO.setAttributeId(attributeId);
attributeDTO.setAttributeDataType(dataType);
attributeDTO.setCategory(subElementName);
attributeDTOs.add(attributeDTO);
}
}
}
return attributeDTOs;
}
use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method createPolicyMetaData.
/**
* This creates the OMElement from the policy xml and create the the meta data for hole policy
*
* @param policy policy as a String
* @param attributeDTOs object which holds the policy meta data in String format
* @return list of AttributeDTO object which holds the policy meta data in String format
* @throws EntitlementException throws if OMElement can not be created
*/
public List<AttributeDTO> createPolicyMetaData(String policy, List<AttributeDTO> attributeDTOs) throws EntitlementException {
OMElement omElement;
try {
omElement = AXIOMUtil.stringToOM(policy);
} catch (XMLStreamException e) {
throw new EntitlementException("Policy xml can not be converted to OMElement");
}
if (omElement != null) {
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.TARGET_ELEMENT);
while (iterator1.hasNext()) {
OMElement targetElement = (OMElement) iterator1.next();
if (version == XACMLConstants.XACML_VERSION_3_0) {
createMetaDataFromXACML3TargetElement(targetElement, attributeDTOs);
} else {
createMetaDataFromTargetElement(targetElement, attributeDTOs);
}
}
Iterator iterator2 = omElement.getChildrenWithLocalName(PDPConstants.RULE_ELEMENT);
while (iterator2.hasNext()) {
OMElement targetElement = (OMElement) iterator2.next();
createMetaDataFromRuleElement(targetElement, attributeDTOs);
}
Iterator iterator3 = omElement.getChildrenWithLocalName(PDPConstants.POLICY_ELEMENT);
while (iterator3.hasNext()) {
OMElement targetElement = (OMElement) iterator3.next();
createPolicyMetaData(targetElement.toString(), attributeDTOs);
}
}
return attributeDTOs;
}
use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method createMetaDataFromXACML3ApplyElement.
/**
* This extract policy meta data from apply element in the policy
*
* @param omElement apply element as an OMElement
* @param attributeDTOs list of AttributeDTO object which holds the policy meta data
* in String format
* @return list of AttributeDTO object which holds the policy meta data in String format
*/
public List<AttributeDTO> createMetaDataFromXACML3ApplyElement(OMElement omElement, List<AttributeDTO> attributeDTOs) {
// TODO check with function id and decide whether search can be done or not
if (omElement != null) {
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_DESIGNATOR);
while (iterator1.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator1.next();
if (attributeDesignator != null) {
String attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.ATTRIBUTE_ID));
String category = attributeDesignator.getAttributeValue(new QName(PDPConstants.CATEGORY));
String dataType = attributeDesignator.getAttributeValue(// TODO
new QName(PDPConstants.DATA_TYPE));
List<String> attributeValues = searchAttributeValues(omElement, new ArrayList<String>(), true);
if (attributeValues == null) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE1 + " for " + PDPConstants.RESOURCE_ELEMENT + " Designator Element ");
attributeDTOs.add(attributeDTO);
} else if (attributeValues.isEmpty()) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE2 + " for " + PDPConstants.RESOURCE_ELEMENT + " Designator Element ");
} else {
for (String value : attributeValues) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setAttributeValue(value);
attributeDTO.setAttributeDataType(dataType);
attributeDTO.setCategory(category);
attributeDTO.setAttributeId(attributeId);
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator2 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_VALUE);
if (iterator2.hasNext()) {
List<String> attributeValues = searchAttributeValues(omElement, new ArrayList<String>(), false);
if (attributeValues == null) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE1 + " for " + PDPConstants.RESOURCE_ELEMENT + " Designator Element ");
attributeDTOs.add(attributeDTO);
} else if (attributeValues.isEmpty()) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE2 + " for " + PDPConstants.RESOURCE_ELEMENT + " Designator Element ");
} else {
for (String values : attributeValues) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setAttributeValue(values);
Iterator iterator8 = omElement.getChildrenWithLocalName(PDPConstants.APPLY_ELEMENT);
while (iterator8.hasNext()) {
OMElement applyElement = (OMElement) iterator8.next();
searchXACML3Designator(applyElement, attributeDTO);
}
if (attributeDTO.getCategory() != null || "".equals(attributeDTO.getCategory())) {
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator7 = omElement.getChildrenWithLocalName(PDPConstants.APPLY_ELEMENT);
while (iterator7.hasNext()) {
OMElement applyElement = (OMElement) iterator7.next();
createMetaDataFromXACML3ApplyElement(applyElement, attributeDTOs);
}
}
return attributeDTOs;
}
use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method searchAttributeValues.
/**
* This searches through attribute values in the attribute elements to extract the policy meta data
*
* @param omElement apply element as an OMElement
* @param values set of String objects
* @param searchDesignators states where, to find designators which are involved in creating
* attribute values
* @return AttributeValueDTO object which holds the policy meta data in String format
*/
public List<String> searchAttributeValues(OMElement omElement, List<String> values, boolean searchDesignators) {
if (values != null) {
Iterator iterator = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_VALUE);
while (iterator.hasNext()) {
OMElement attributeElement = (OMElement) iterator.next();
if (attributeElement != null) {
String dataType = attributeElement.getAttributeValue(// TODO
new QName(PDPConstants.DATA_TYPE));
values.add(attributeElement.getText());
}
}
}
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.APPLY_ELEMENT);
while (iterator1.hasNext()) {
OMElement applyElement = (OMElement) iterator1.next();
searchAttributeValues(applyElement, values, searchDesignators);
AttributeDTO attributeDTO = new AttributeDTO();
if (searchDesignators) {
if (version == XACMLConstants.XACML_VERSION_3_0) {
searchXACML3Designator(applyElement, attributeDTO);
} else {
searchDesignatorOrSelector(applyElement, attributeDTO);
}
}
if (attributeDTO.getCategory() != null || attributeDTO.getAttributeId() != null || attributeDTO.getAttributeDataType() != null) {
values = null;
}
}
return values;
}
use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method createMetaDataFromXACML3TargetElement.
/**
* This extract policy meta data from target element in the policy
*
* @param omElement target element as an OMElement
* @param attributeDTOs list of AttributeDTO object which holds the policy meta data
* in String format
* @return list of AttributeDTO object which holds the policy meta data in String format
*/
public List<AttributeDTO> createMetaDataFromXACML3TargetElement(OMElement omElement, List<AttributeDTO> attributeDTOs) {
if (omElement != null) {
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.ANY_OF);
while (iterator1.hasNext()) {
OMElement anyOff = (OMElement) iterator1.next();
Iterator iterator2 = anyOff.getChildrenWithLocalName(PDPConstants.ALL_OF);
while (iterator2.hasNext()) {
OMElement allOf = (OMElement) iterator2.next();
Iterator iterator3 = allOf.getChildrenWithLocalName(PDPConstants.MATCH_ELEMENT);
while (iterator3.hasNext()) {
OMElement resourceMatch = (OMElement) iterator3.next();
List<AttributeDTO> attributeDTOList = createMetaDataFromXACML3MatchElement(resourceMatch);
for (AttributeDTO attributeDTO : attributeDTOList) {
attributeDTOs.add(attributeDTO);
}
}
}
}
}
return attributeDTOs;
}
Aggregations