Search in sources :

Example 1 with AttributeDTO

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;
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Example 2 with AttributeDTO

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;
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 3 with AttributeDTO

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;
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) Iterator(java.util.Iterator)

Example 4 with AttributeDTO

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;
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Example 5 with AttributeDTO

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;
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Aggregations

AttributeDTO (org.wso2.carbon.identity.entitlement.dto.AttributeDTO)21 ArrayList (java.util.ArrayList)10 Iterator (java.util.Iterator)9 OMElement (org.apache.axiom.om.OMElement)8 HashSet (java.util.HashSet)6 QName (javax.xml.namespace.QName)5 EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)5 List (java.util.List)4 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 Set (java.util.Set)3 Map (java.util.Map)2 Properties (java.util.Properties)2 EntitledAttributesDTO (org.wso2.carbon.identity.entitlement.dto.EntitledAttributesDTO)2 EntitledResultSetDTO (org.wso2.carbon.identity.entitlement.dto.EntitledResultSetDTO)2 PolicyDTO (org.wso2.carbon.identity.entitlement.dto.PolicyDTO)2 PolicyFinderModule (org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule)2 Collection (org.wso2.carbon.registry.core.Collection)2 Registry (org.wso2.carbon.registry.core.Registry)2 Resource (org.wso2.carbon.registry.core.Resource)2 IOException (java.io.IOException)1