use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method createMetaDataFromXACML3MatchElement.
/**
* This extract policy meta data from match element in the policy
*
* @param omElement match element as an OMElement
* @return AttributeValueDTO object which holds the policy meta data in String format
*/
public List<AttributeDTO> createMetaDataFromXACML3MatchElement(OMElement omElement) {
List<AttributeDTO> attributeDTOs = new ArrayList<AttributeDTO>();
String attributeId = null;
String category = null;
if (omElement != null) {
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_DESIGNATOR);
while (iterator1.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator1.next();
if (attributeDesignator != null) {
attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.ATTRIBUTE_ID));
category = attributeDesignator.getAttributeValue(new QName(PDPConstants.CATEGORY));
}
}
Iterator iterator3 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_VALUE);
while (iterator3.hasNext()) {
OMElement attributeElement = (OMElement) iterator3.next();
if (attributeElement != null) {
String dataType = attributeElement.getAttributeValue(new QName(PDPConstants.DATA_TYPE));
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setAttributeValue(attributeElement.getText());
attributeDTO.setAttributeId(attributeId);
attributeDTO.setAttributeDataType(dataType);
attributeDTO.setCategory(category);
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 getPolicyMetaDataFromPolicy.
/**
* This creates properties object which contains the policy meta data.
*
* @return properties object which contains the policy meta data
* @throws EntitlementException throws
*/
public Properties getPolicyMetaDataFromPolicy() throws EntitlementException {
List<AttributeDTO> attributeDTOs = new ArrayList<AttributeDTO>();
try {
attributeDTOs = createPolicyMetaData(policy, attributeDTOs);
} catch (EntitlementException e) {
throw new EntitlementException("Can not create Policy MetaData for given policy");
}
int attributeElementNo = 0;
Properties properties = new Properties();
if (attributeDTOs != null) {
for (AttributeDTO attributeDTO : attributeDTOs) {
properties.setProperty(PDPConstants.POLICY_META_DATA + attributeElementNo, attributeDTO.getCategory() + PDPConstants.ATTRIBUTE_SEPARATOR + attributeDTO.getAttributeValue() + PDPConstants.ATTRIBUTE_SEPARATOR + attributeDTO.getAttributeId() + PDPConstants.ATTRIBUTE_SEPARATOR + attributeDTO.getAttributeDataType());
attributeElementNo++;
}
}
return properties;
}
use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method createMetaDataFromConditionElement.
/**
* This extract policy meta data from condition element in the policy
*
* @param omElement condition 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> createMetaDataFromConditionElement(OMElement omElement, List<AttributeDTO> attributeDTOs) {
Iterator iterator = omElement.getChildrenWithLocalName(PDPConstants.APPLY_ELEMENT);
if (iterator.hasNext()) {
if (version == XACMLConstants.XACML_VERSION_3_0) {
createMetaDataFromXACML3ApplyElement(omElement, attributeDTOs);
} else {
createMetaDataFromApplyElement(omElement, attributeDTOs);
}
} else {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE4);
}
// TODO currently only search meta data on Apply Element, support for other elements
return attributeDTOs;
}
use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.
the class PolicyAttributeBuilder method createMetaDataFromTargetElement.
/**
* 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> createMetaDataFromTargetElement(OMElement omElement, List<AttributeDTO> attributeDTOs) {
if (omElement != null) {
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.RESOURCE_ELEMENT + "s");
while (iterator1.hasNext()) {
OMElement resourceElements = (OMElement) iterator1.next();
Iterator iterator2 = resourceElements.getChildrenWithLocalName(PDPConstants.RESOURCE_ELEMENT);
while (iterator2.hasNext()) {
OMElement resourceElement = (OMElement) iterator2.next();
Iterator iterator3 = resourceElement.getChildrenWithLocalName(PDPConstants.RESOURCE_ELEMENT + PDPConstants.MATCH_ELEMENT);
while (iterator3.hasNext()) {
OMElement resourceMatch = (OMElement) iterator3.next();
List<AttributeDTO> attributeDTOList = createMetaDataFromMatchElement(resourceMatch, PDPConstants.RESOURCE_ELEMENT);
for (AttributeDTO attributeDTO : attributeDTOList) {
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator4 = omElement.getChildrenWithLocalName(PDPConstants.SUBJECT_ELEMENT + "s");
while (iterator4.hasNext()) {
OMElement resourceElements = (OMElement) iterator4.next();
Iterator iterator2 = resourceElements.getChildrenWithLocalName(PDPConstants.SUBJECT_ELEMENT);
while (iterator2.hasNext()) {
OMElement resourceElement = (OMElement) iterator2.next();
Iterator iterator3 = resourceElement.getChildrenWithLocalName(PDPConstants.SUBJECT_ELEMENT + PDPConstants.MATCH_ELEMENT);
while (iterator3.hasNext()) {
OMElement resourceMatch = (OMElement) iterator3.next();
List<AttributeDTO> attributeDTOList = createMetaDataFromMatchElement(resourceMatch, PDPConstants.SUBJECT_ELEMENT);
for (AttributeDTO attributeDTO : attributeDTOList) {
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator5 = omElement.getChildrenWithLocalName(PDPConstants.ACTION_ELEMENT + "s");
while (iterator5.hasNext()) {
OMElement resourceElements = (OMElement) iterator5.next();
Iterator iterator2 = resourceElements.getChildrenWithLocalName(PDPConstants.ACTION_ELEMENT);
while (iterator2.hasNext()) {
OMElement resourceElement = (OMElement) iterator2.next();
Iterator iterator3 = resourceElement.getChildrenWithLocalName(PDPConstants.ACTION_ELEMENT + PDPConstants.MATCH_ELEMENT);
while (iterator3.hasNext()) {
OMElement resourceMatch = (OMElement) iterator3.next();
List<AttributeDTO> attributeDTOList = createMetaDataFromMatchElement(resourceMatch, PDPConstants.ACTION_ELEMENT);
for (AttributeDTO attributeDTO : attributeDTOList) {
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator6 = omElement.getChildrenWithLocalName(PDPConstants.ENVIRONMENT_ELEMENT + "s");
while (iterator6.hasNext()) {
OMElement resourceElements = (OMElement) iterator6.next();
Iterator iterator2 = resourceElements.getChildrenWithLocalName(PDPConstants.ENVIRONMENT_ELEMENT);
while (iterator2.hasNext()) {
OMElement resourceElement = (OMElement) iterator2.next();
Iterator iterator3 = resourceElement.getChildrenWithLocalName(PDPConstants.ENVIRONMENT_ELEMENT + PDPConstants.MATCH_ELEMENT);
while (iterator3.hasNext()) {
OMElement resourceMatch = (OMElement) iterator3.next();
List<AttributeDTO> attributeDTOList = createMetaDataFromMatchElement(resourceMatch, PDPConstants.ENVIRONMENT_ELEMENT);
for (AttributeDTO attributeDTO : attributeDTOList) {
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 createMetaDataFromApplyElement.
/**
* 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> createMetaDataFromApplyElement(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.RESOURCE_ELEMENT + PDPConstants.ATTRIBUTE_DESIGNATOR);
while (iterator1.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator1.next();
if (attributeDesignator != null) {
String attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.ATTRIBUTE_ID));
String dataType = attributeDesignator.getAttributeValue(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(PDPConstants.RESOURCE_ELEMENT);
attributeDTO.setAttributeId(attributeId);
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator2 = omElement.getChildrenWithLocalName(PDPConstants.SUBJECT_ELEMENT + PDPConstants.ATTRIBUTE_DESIGNATOR);
while (iterator2.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator2.next();
if (attributeDesignator != null) {
String attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.ATTRIBUTE_ID));
String dataType = attributeDesignator.getAttributeValue(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(PDPConstants.SUBJECT_ELEMENT);
attributeDTO.setAttributeId(attributeId);
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator3 = omElement.getChildrenWithLocalName(PDPConstants.ACTION_ELEMENT + PDPConstants.ATTRIBUTE_DESIGNATOR);
while (iterator3.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator3.next();
if (attributeDesignator != null) {
String attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.ATTRIBUTE_ID));
String dataType = attributeDesignator.getAttributeValue(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(PDPConstants.ACTION_ELEMENT);
attributeDTO.setAttributeId(attributeId);
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator4 = omElement.getChildrenWithLocalName(PDPConstants.ENVIRONMENT_ELEMENT + PDPConstants.ATTRIBUTE_DESIGNATOR);
while (iterator4.hasNext()) {
OMElement attributeDesignator = (OMElement) iterator4.next();
if (attributeDesignator != null) {
String attributeId = attributeDesignator.getAttributeValue(new QName(PDPConstants.ATTRIBUTE_ID));
String dataType = attributeDesignator.getAttributeValue(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(PDPConstants.ENVIRONMENT_ELEMENT);
attributeDTO.setAttributeId(attributeId);
attributeDTOs.add(attributeDTO);
}
}
}
}
Iterator iterator5 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_SELECTOR);
while (iterator5.hasNext()) {
OMElement attributeSelector = (OMElement) iterator5.next();
if (attributeSelector != null) {
String attributeId = attributeSelector.getAttributeValue(new QName(PDPConstants.REQUEST_CONTEXT_PATH));
// TODO Fix finding element name from Xpath
String subElementName = attributeId;
String dataType = attributeSelector.getAttributeValue(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_MESSAGE3);
attributeDTOs.add(attributeDTO);
} else if (attributeValues.isEmpty()) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE3);
} else {
for (String value : attributeValues) {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setAttributeValue(value);
attributeDTO.setAttributeDataType(dataType);
attributeDTO.setCategory(subElementName);
attributeDTO.setAttributeId(attributeId);
attributeDTOs.add(attributeDTO);
// Remove following after fixing XPath issues
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE3);
}
}
}
}
Iterator iterator6 = omElement.getChildrenWithLocalName(PDPConstants.ATTRIBUTE_VALUE);
if (iterator6.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();
if (version == XACMLConstants.XACML_VERSION_3_0) {
searchXACML3Designator(applyElement, attributeDTO);
} else {
searchDesignatorOrSelector(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();
createMetaDataFromApplyElement(applyElement, attributeDTOs);
}
}
return attributeDTOs;
}
Aggregations