org.wso2.balana.utils.policy.dto.PolicyElementDTO Java Examples

The following examples show how to use org.wso2.balana.utils.policy.dto.PolicyElementDTO. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PolicyEditorUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static void processPolicyEditorData(PolicyElementDTO policyElementDTO, String[] policyEditorData) {

        List<String> targetList = new ArrayList<String>();

        if (policyEditorData != null) {
            for (String data : policyEditorData) {
                if (data.contains("|")) {
                    String identifier = data.substring(0, data.indexOf("|"));
                    if (("policy").equals(identifier)) {
                        targetList.add(data.substring(data.indexOf("|") + 1));
                    }
                }
            }

            policyElementDTO.setPolicyName(targetList.get(0));
            policyElementDTO.setRuleCombiningAlgorithms(targetList.get(1));
            if (targetList.get(2) != null) {
                policyElementDTO.setPolicyDescription(targetList.get(2));
            }
            policyElementDTO.setVersion(targetList.get(3));
        }
    }
 
Example #2
Source File: PolicyEditorUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static void processPolicyEditorData(PolicyElementDTO policyElementDTO, String[] policyEditorData) {

        List<String> targetList = new ArrayList<String>();

        if (policyEditorData != null) {
            for (String data : policyEditorData) {
                if (data.contains("|")) {
                    String identifier = data.substring(0, data.indexOf("|"));
                    if (("policy").equals(identifier)) {
                        targetList.add(data.substring(data.indexOf("|") + 1));
                    }
                }
            }

            policyElementDTO.setPolicyName(targetList.get(0));
            policyElementDTO.setRuleCombiningAlgorithms(targetList.get(1));
            if (targetList.get(2) != null) {
                policyElementDTO.setPolicyDescription(targetList.get(2));
            }
            policyElementDTO.setVersion(targetList.get(3));
        }
    }
 
Example #3
Source File: PolicyEditorUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static void processPolicyEditorData(PolicyElementDTO policyElementDTO, String[] policyEditorData) {

        List<String> targetList = new ArrayList<String>();

        if (policyEditorData != null) {
            for (String data : policyEditorData) {
                if (data.contains("|")) {
                    String identifier = data.substring(0, data.indexOf("|"));
                    if (("policy").equals(identifier)) {
                        targetList.add(data.substring(data.indexOf("|") + 1));
                    }
                }
            }

            policyElementDTO.setPolicyName(targetList.get(0));
            policyElementDTO.setRuleCombiningAlgorithms(targetList.get(1));
            if (targetList.get(2) != null) {
                policyElementDTO.setPolicyDescription(targetList.get(2));
            }
            policyElementDTO.setVersion(targetList.get(3));
        }
    }
 
Example #4
Source File: EntitlementPolicyCreator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Create XACML policy using the data received from basic policy wizard
 *
 * @param policyDTO PolicyDTO
 * @return String object of the XACML policy
 * @throws PolicyEditorException throws
 */
public String createPolicy(PolicyDTO policyDTO) throws PolicyEditorException {

    if (policyDTO == null) {
        throw new PolicyEditorException("Policy object can not be null");
    }

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    policyElementDTO.setPolicyName(policyDTO.getPolicyId());
    policyElementDTO.setRuleCombiningAlgorithms(policyDTO.getRuleAlgorithm());
    policyElementDTO.setPolicyDescription(policyDTO.getDescription());
    policyElementDTO.setVersion(policyDTO.getVersion());

    if (policyDTO.getTargetDTO() != null) {
        TargetElementDTO targetElementDTO = PolicyEditorUtil.
                createTargetElementDTO(policyDTO.getTargetDTO());
        policyElementDTO.setTargetElementDTO(targetElementDTO);
    }

    if (policyDTO.getRuleDTOs() != null) {
        for (RuleDTO ruleDTO : policyDTO.getRuleDTOs()) {
            RuleElementDTO ruleElementDTO = PolicyEditorUtil.createRuleElementDTO(ruleDTO);
            policyElementDTO.addRuleElementDTO(ruleElementDTO);
        }
    }

    if (policyDTO.getObligationDTOs() != null) {
        List<ObligationElementDTO> obligationElementDTOs = PolicyEditorUtil.
                createObligation(policyDTO.getObligationDTOs());
        policyElementDTO.setObligationElementDTOs(obligationElementDTOs);
    }

    try {
        return PolicyBuilder.getInstance().build(policyElementDTO);
    } catch (PolicyBuilderException e) {
        throw new PolicyEditorException("Error while building XACML Policy");
    }
}
 
Example #5
Source File: EntitlementPolicyCreator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Create XACML policy using the data received from basic policy wizard
 *
 * @param policyDTO PolicyDTO
 * @return String object of the XACML policy
 * @throws PolicyEditorException throws
 */
public String createPolicy(PolicyDTO policyDTO) throws PolicyEditorException {

    if (policyDTO == null) {
        throw new PolicyEditorException("Policy object can not be null");
    }

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    policyElementDTO.setPolicyName(policyDTO.getPolicyId());
    policyElementDTO.setRuleCombiningAlgorithms(policyDTO.getRuleAlgorithm());
    policyElementDTO.setPolicyDescription(policyDTO.getDescription());
    policyElementDTO.setVersion(policyDTO.getVersion());

    if (policyDTO.getTargetDTO() != null) {
        TargetElementDTO targetElementDTO = PolicyEditorUtil.
                createTargetElementDTO(policyDTO.getTargetDTO());
        policyElementDTO.setTargetElementDTO(targetElementDTO);
    }

    if (policyDTO.getRuleDTOs() != null) {
        for (RuleDTO ruleDTO : policyDTO.getRuleDTOs()) {
            RuleElementDTO ruleElementDTO = PolicyEditorUtil.createRuleElementDTO(ruleDTO);
            policyElementDTO.addRuleElementDTO(ruleElementDTO);
        }
    }

    if (policyDTO.getObligationDTOs() != null) {
        List<ObligationElementDTO> obligationElementDTOs = PolicyEditorUtil.
                createObligation(policyDTO.getObligationDTOs());
        policyElementDTO.setObligationElementDTOs(obligationElementDTOs);
    }

    try {
        return PolicyBuilder.getInstance().build(policyElementDTO);
    } catch (PolicyBuilderException e) {
        throw new PolicyEditorException("Error while building XACML Policy");
    }
}
 
Example #6
Source File: PolicyEditorUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static PolicyElementDTO createPolicyElementDTO(String policy)
        throws EntitlementPolicyCreationException {

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    OMElement omElement;
    try {
        omElement = AXIOMUtil.stringToOM(policy);
    } catch (XMLStreamException e) {
        throw new EntitlementPolicyCreationException("Policy can not be converted to OMElement");
    }

    if (omElement != null) {

        policyElementDTO.setPolicyName(omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.POLICY_ID)));

        String ruleCombiningAlgorithm = omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.RULE_ALGORITHM));

        try {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_3)[1]);
        } catch (Exception ignore) {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_1)[1]);
            // if this is also fails, can not edit the policy
        }

        Iterator iterator = omElement.getChildrenWithLocalName(EntitlementPolicyConstants.
                DESCRIPTION_ELEMENT);

        if (iterator.hasNext()) {
            OMElement descriptionElement = (OMElement) iterator.next();
            if (descriptionElement != null && descriptionElement.getText() != null) {
                policyElementDTO.setPolicyDescription(descriptionElement.getText().trim());
            }
        }

    }
    return policyElementDTO;
}
 
Example #7
Source File: PolicyEditorUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static PolicyElementDTO createPolicyElementDTO(String policy)
        throws EntitlementPolicyCreationException {

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    OMElement omElement;
    try {
        omElement = AXIOMUtil.stringToOM(policy);
    } catch (XMLStreamException e) {
        throw new EntitlementPolicyCreationException("Policy can not be converted to OMElement");
    }

    if (omElement != null) {

        policyElementDTO.setPolicyName(omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.POLICY_ID)));

        String ruleCombiningAlgorithm = omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.RULE_ALGORITHM));

        try {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_3)[1]);
        } catch (Exception ignore) {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_1)[1]);
            // if this is also fails, can not edit the policy
        }

        Iterator iterator = omElement.getChildrenWithLocalName(EntitlementPolicyConstants.
                DESCRIPTION_ELEMENT);

        if (iterator.hasNext()) {
            OMElement descriptionElement = (OMElement) iterator.next();
            if (descriptionElement != null && descriptionElement.getText() != null) {
                policyElementDTO.setPolicyDescription(descriptionElement.getText().trim());
            }
        }

    }
    return policyElementDTO;
}
 
Example #8
Source File: PolicyEditorUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static PolicyElementDTO createPolicyElementDTO(String policy)
        throws EntitlementPolicyCreationException {

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    OMElement omElement;
    try {
        omElement = AXIOMUtil.stringToOM(policy);
    } catch (XMLStreamException e) {
        throw new EntitlementPolicyCreationException("Policy can not be converted to OMElement");
    }

    if (omElement != null) {

        policyElementDTO.setPolicyName(omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.POLICY_ID)));

        String ruleCombiningAlgorithm = omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.RULE_ALGORITHM));

        try {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_3)[1]);
        } catch (Exception ignore) {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_1)[1]);
            // if this is also fails, can not edit the policy
        }

        Iterator iterator = omElement.getChildrenWithLocalName(EntitlementPolicyConstants.
                DESCRIPTION_ELEMENT);

        if (iterator.hasNext()) {
            OMElement descriptionElement = (OMElement) iterator.next();
            if (descriptionElement != null && descriptionElement.getText() != null) {
                policyElementDTO.setPolicyDescription(descriptionElement.getText().trim());
            }
        }

    }
    return policyElementDTO;
}