Java Code Examples for org.wso2.balana.utils.Constants.PolicyConstants

The following examples show how to use org.wso2.balana.utils.Constants.PolicyConstants. These examples are extracted from open source projects. 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
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addSubjectElement(BasicRuleDTO ruleElementDTO,
                                      SimplePolicyEditorElementDTO editorElementDTO) {

    String selectedDataType = null;
    PolicyEditorDataHolder holder = PolicyEditorEngine.getInstance().
            getPolicyEditorData(EntitlementConstants.PolicyEditor.RBAC);

    if (editorElementDTO.getUserAttributeId() == null) {
        ruleElementDTO.setSubjectId(PolicyEditorConstants.SUBJECT_ID_DEFAULT);
    } else {
        ruleElementDTO.setSubjectId(holder.getAttributeIdUri(editorElementDTO.getUserAttributeId()));
        if ((selectedDataType = holder.getDataTypeUriForAttribute(editorElementDTO.getUserAttributeId())) != null) {
            ruleElementDTO.setSubjectDataType(selectedDataType);
        }
    }

    if (ruleElementDTO.getSubjectDataType() == null) {
        ruleElementDTO.setSubjectDataType(PolicyConstants.DataType.STRING);
    }
    String function = findFunction(editorElementDTO.getUserAttributeValue(),
            ruleElementDTO.getSubjectDataType());
    String value = findAttributeValue(editorElementDTO.getUserAttributeValue());
    ruleElementDTO.setSubjectList(value);
    ruleElementDTO.setFunctionOnSubjects(function);
}
 
Example 2
/**
 * 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;
}
 
Example 3
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addSubjectElement(BasicRuleDTO ruleElementDTO,
                                      SimplePolicyEditorElementDTO editorElementDTO) {

    String selectedDataType = null;
    PolicyEditorDataHolder holder = PolicyEditorEngine.getInstance().
            getPolicyEditorData(EntitlementConstants.PolicyEditor.RBAC);

    if (editorElementDTO.getUserAttributeId() == null) {
        ruleElementDTO.setSubjectId(PolicyEditorConstants.SUBJECT_ID_DEFAULT);
    } else {
        ruleElementDTO.setSubjectId(holder.getAttributeIdUri(editorElementDTO.getUserAttributeId()));
        if ((selectedDataType = holder.getDataTypeUriForAttribute(editorElementDTO.getUserAttributeId())) != null) {
            ruleElementDTO.setSubjectDataType(selectedDataType);
        }
    }

    if (ruleElementDTO.getSubjectDataType() == null) {
        ruleElementDTO.setSubjectDataType(PolicyConstants.DataType.STRING);
    }
    String function = findFunction(editorElementDTO.getUserAttributeValue(),
            ruleElementDTO.getSubjectDataType());
    String value = findAttributeValue(editorElementDTO.getUserAttributeValue());
    ruleElementDTO.setSubjectList(value);
    ruleElementDTO.setFunctionOnSubjects(function);
}
 
Example 4
/**
 * 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;
}
 
Example 5
Source Project: carbon-identity   Source File: PolicyEditorUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addSubjectElement(BasicRuleDTO ruleElementDTO,
                                      SimplePolicyEditorElementDTO editorElementDTO) {

    String selectedDataType = null;
    PolicyEditorDataHolder holder = PolicyEditorEngine.getInstance().
            getPolicyEditorData(EntitlementConstants.PolicyEditor.RBAC);

    if (editorElementDTO.getUserAttributeId() == null) {
        ruleElementDTO.setSubjectId(PolicyEditorConstants.SUBJECT_ID_DEFAULT);
    } else {
        ruleElementDTO.setSubjectId(holder.getAttributeIdUri(editorElementDTO.getUserAttributeId()));
        if ((selectedDataType = holder.getDataTypeUriForAttribute(editorElementDTO.getUserAttributeId())) != null) {
            ruleElementDTO.setSubjectDataType(selectedDataType);
        }
    }

    if (ruleElementDTO.getSubjectDataType() == null) {
        ruleElementDTO.setSubjectDataType(PolicyConstants.DataType.STRING);
    }
    String function = findFunction(editorElementDTO.getUserAttributeValue(),
            ruleElementDTO.getSubjectDataType());
    String value = findAttributeValue(editorElementDTO.getUserAttributeValue());
    ruleElementDTO.setSubjectList(value);
    ruleElementDTO.setFunctionOnSubjects(function);
}
 
Example 6
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Element createRequestElement(RequestElementDTO requestElementDTO, Document doc)
        throws PolicyBuilderException {

    Element requestElement = doc.createElement(PolicyConstants.Request.REQUEST_ELEMENT);
    requestElement.setAttribute("xmlns", PolicyConstants.Request.REQ_RES_CONTEXT_XACML3);
    requestElement.setAttribute(PolicyConstants.Request.RETURN_POLICY_LIST ,
            Boolean.toString(requestElementDTO.isReturnPolicyIdList()));
    requestElement.setAttribute(PolicyConstants.Request.COMBINED_DECISION ,
            Boolean.toString(requestElementDTO.isCombinedDecision()));
    
    List<AttributesElementDTO>  attributesElementDTOs = requestElementDTO.getAttributesElementDTOs();
    if(attributesElementDTOs != null && attributesElementDTOs.size() > 0){
        for(AttributesElementDTO dto : attributesElementDTOs){
            requestElement.appendChild(createAttributesElement(dto,doc));
        }
    }
    return requestElement;
}
 
Example 7
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method creates the attribute value element
 * @param attributeValueElementDTO attribute value element data object
 * @param doc XML document
 * @return attribute value element
 */
public static Element createAttributeValueElement(AttributeValueElementDTO
                                                          attributeValueElementDTO, Document doc) {

    Element attributeValueElement = doc.createElement(PolicyConstants.ATTRIBUTE_VALUE);

    if(attributeValueElementDTO.getAttributeValue() != null && attributeValueElementDTO.
            getAttributeValue().trim().length() > 0) {

        attributeValueElement.setTextContent(attributeValueElementDTO.getAttributeValue().trim());

        if(attributeValueElementDTO.getAttributeDataType()!= null && attributeValueElementDTO.
                getAttributeDataType().trim().length() > 0){
            attributeValueElement.setAttribute(PolicyConstants.DATA_TYPE,
                    attributeValueElementDTO.getAttributeDataType());
        } else {
            attributeValueElement.setAttribute(PolicyConstants.DATA_TYPE,
                    PolicyConstants.STRING_DATA_TYPE);
        }

    }

    return attributeValueElement;

}
 
Example 8
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addResourceElement(BasicRuleDTO ruleElementDTO,
                                       SimplePolicyEditorElementDTO editorElementDTO) {


    ruleElementDTO.setResourceId(PolicyEditorConstants.RESOURCE_ID_DEFAULT);
    ruleElementDTO.setResourceDataType(PolicyConstants.DataType.STRING);
    String function = findFunction(editorElementDTO.getResourceValue(),
            ruleElementDTO.getResourceDataType());
    String value = findAttributeValue(editorElementDTO.getResourceValue());
    ruleElementDTO.setResourceList(value);
    ruleElementDTO.setFunctionOnResources(function);
}
 
Example 9
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addActionElement(BasicRuleDTO ruleElementDTO,
                                     SimplePolicyEditorElementDTO editorElementDTO) {

    ruleElementDTO.setActionId(PolicyEditorConstants.ACTION_ID_DEFAULT);
    ruleElementDTO.setActionDataType(PolicyConstants.DataType.STRING);

    String function = findFunction(editorElementDTO.getActionValue(),
            ruleElementDTO.getActionDataType());
    String value = findAttributeValue(editorElementDTO.getActionValue());
    ruleElementDTO.setActionList(value);
    ruleElementDTO.setFunctionOnActions(function);
}
 
Example 10
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addEnvironmentElement(BasicRuleDTO ruleElementDTO,
                                          SimplePolicyEditorElementDTO editorElementDTO) {

    String selectedDataType = null;
    PolicyEditorDataHolder holder = PolicyEditorEngine.getInstance().
            getPolicyEditorData(EntitlementConstants.PolicyEditor.RBAC);
    if (editorElementDTO.getEnvironmentId() == null) {
        ruleElementDTO.setEnvironmentId(PolicyEditorConstants.ENVIRONMENT_ID_DEFAULT);
    } else {
        ruleElementDTO.setEnvironmentId(holder.getAttributeIdUri(editorElementDTO.getEnvironmentId()));
        if ((selectedDataType = holder.getDataTypeUriForAttribute(editorElementDTO.getEnvironmentId())) != null) {
            ruleElementDTO.setEnvironmentDataType(selectedDataType);
        }
    }

    if (ruleElementDTO.getEnvironmentDataType() == null) {
        ruleElementDTO.setEnvironmentDataType(PolicyConstants.DataType.STRING);
    }

    String function = findFunction(editorElementDTO.getEnvironmentValue(),
            ruleElementDTO.getEnvironmentDataType());
    String value = findAttributeValue(editorElementDTO.getEnvironmentValue());
    ruleElementDTO.setEnvironmentDataType(ruleElementDTO.getEnvironmentDataType());
    ruleElementDTO.setEnvironmentList(value);
    ruleElementDTO.setFunctionOnEnvironment(function);

}
 
Example 11
/**
 * 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;
}
 
Example 12
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addResourceElement(BasicRuleDTO ruleElementDTO,
                                       SimplePolicyEditorElementDTO editorElementDTO) {


    ruleElementDTO.setResourceId(PolicyEditorConstants.RESOURCE_ID_DEFAULT);
    ruleElementDTO.setResourceDataType(PolicyConstants.DataType.STRING);
    String function = findFunction(editorElementDTO.getResourceValue(),
            ruleElementDTO.getResourceDataType());
    String value = findAttributeValue(editorElementDTO.getResourceValue());
    ruleElementDTO.setResourceList(value);
    ruleElementDTO.setFunctionOnResources(function);
}
 
Example 13
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addActionElement(BasicRuleDTO ruleElementDTO,
                                     SimplePolicyEditorElementDTO editorElementDTO) {

    ruleElementDTO.setActionId(PolicyEditorConstants.ACTION_ID_DEFAULT);
    ruleElementDTO.setActionDataType(PolicyConstants.DataType.STRING);

    String function = findFunction(editorElementDTO.getActionValue(),
            ruleElementDTO.getActionDataType());
    String value = findAttributeValue(editorElementDTO.getActionValue());
    ruleElementDTO.setActionList(value);
    ruleElementDTO.setFunctionOnActions(function);
}
 
Example 14
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addEnvironmentElement(BasicRuleDTO ruleElementDTO,
                                          SimplePolicyEditorElementDTO editorElementDTO) {

    String selectedDataType = null;
    PolicyEditorDataHolder holder = PolicyEditorEngine.getInstance().
            getPolicyEditorData(EntitlementConstants.PolicyEditor.RBAC);
    if (editorElementDTO.getEnvironmentId() == null) {
        ruleElementDTO.setEnvironmentId(PolicyEditorConstants.ENVIRONMENT_ID_DEFAULT);
    } else {
        ruleElementDTO.setEnvironmentId(holder.getAttributeIdUri(editorElementDTO.getEnvironmentId()));
        if ((selectedDataType = holder.getDataTypeUriForAttribute(editorElementDTO.getEnvironmentId())) != null) {
            ruleElementDTO.setEnvironmentDataType(selectedDataType);
        }
    }

    if (ruleElementDTO.getEnvironmentDataType() == null) {
        ruleElementDTO.setEnvironmentDataType(PolicyConstants.DataType.STRING);
    }

    String function = findFunction(editorElementDTO.getEnvironmentValue(),
            ruleElementDTO.getEnvironmentDataType());
    String value = findAttributeValue(editorElementDTO.getEnvironmentValue());
    ruleElementDTO.setEnvironmentDataType(ruleElementDTO.getEnvironmentDataType());
    ruleElementDTO.setEnvironmentList(value);
    ruleElementDTO.setFunctionOnEnvironment(function);

}
 
Example 15
/**
 * 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;
}
 
Example 16
Source Project: carbon-identity-framework   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isValidRuleAlgorithm(String algorithmUri, boolean isPolicy) {

        if (isPolicy) {
            return algorithmUri != null &&
                    Arrays.asList(PolicyConstants.PolicyCombiningAlog.algorithms).contains(algorithmUri);
        } else {
            return algorithmUri != null &&
                    Arrays.asList(PolicyConstants.RuleCombiningAlog.algorithms).contains(algorithmUri);
        }
    }
 
Example 17
Source Project: carbon-identity   Source File: PolicyEditorUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addResourceElement(BasicRuleDTO ruleElementDTO,
                                       SimplePolicyEditorElementDTO editorElementDTO) {


    ruleElementDTO.setResourceId(PolicyEditorConstants.RESOURCE_ID_DEFAULT);
    ruleElementDTO.setResourceDataType(PolicyConstants.DataType.STRING);
    String function = findFunction(editorElementDTO.getResourceValue(),
            ruleElementDTO.getResourceDataType());
    String value = findAttributeValue(editorElementDTO.getResourceValue());
    ruleElementDTO.setResourceList(value);
    ruleElementDTO.setFunctionOnResources(function);
}
 
Example 18
Source Project: carbon-identity   Source File: PolicyEditorUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addActionElement(BasicRuleDTO ruleElementDTO,
                                     SimplePolicyEditorElementDTO editorElementDTO) {

    ruleElementDTO.setActionId(PolicyEditorConstants.ACTION_ID_DEFAULT);
    ruleElementDTO.setActionDataType(PolicyConstants.DataType.STRING);

    String function = findFunction(editorElementDTO.getActionValue(),
            ruleElementDTO.getActionDataType());
    String value = findAttributeValue(editorElementDTO.getActionValue());
    ruleElementDTO.setActionList(value);
    ruleElementDTO.setFunctionOnActions(function);
}
 
Example 19
Source Project: carbon-identity   Source File: PolicyEditorUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to create SOA policy
 *
 * @param ruleElementDTO
 * @param editorElementDTO
 */
private static void addEnvironmentElement(BasicRuleDTO ruleElementDTO,
                                          SimplePolicyEditorElementDTO editorElementDTO) {

    String selectedDataType = null;
    PolicyEditorDataHolder holder = PolicyEditorEngine.getInstance().
            getPolicyEditorData(EntitlementConstants.PolicyEditor.RBAC);
    if (editorElementDTO.getEnvironmentId() == null) {
        ruleElementDTO.setEnvironmentId(PolicyEditorConstants.ENVIRONMENT_ID_DEFAULT);
    } else {
        ruleElementDTO.setEnvironmentId(holder.getAttributeIdUri(editorElementDTO.getEnvironmentId()));
        if ((selectedDataType = holder.getDataTypeUriForAttribute(editorElementDTO.getEnvironmentId())) != null) {
            ruleElementDTO.setEnvironmentDataType(selectedDataType);
        }
    }

    if (ruleElementDTO.getEnvironmentDataType() == null) {
        ruleElementDTO.setEnvironmentDataType(PolicyConstants.DataType.STRING);
    }

    String function = findFunction(editorElementDTO.getEnvironmentValue(),
            ruleElementDTO.getEnvironmentDataType());
    String value = findAttributeValue(editorElementDTO.getEnvironmentValue());
    ruleElementDTO.setEnvironmentDataType(ruleElementDTO.getEnvironmentDataType());
    ruleElementDTO.setEnvironmentList(value);
    ruleElementDTO.setFunctionOnEnvironment(function);

}
 
Example 20
Source Project: carbon-identity   Source File: PolicyEditorUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 21
Source Project: carbon-identity   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isValidRuleAlgorithm(String algorithmUri, boolean isPolicy) {

        if (isPolicy) {
            return algorithmUri != null &&
                    Arrays.asList(PolicyConstants.PolicyCombiningAlog.algorithms).contains(algorithmUri);
        } else {
            return algorithmUri != null &&
                    Arrays.asList(PolicyConstants.RuleCombiningAlog.algorithms).contains(algorithmUri);
        }
    }
 
Example 22
Source Project: balana   Source File: BasicPolicyHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static ApplyElementDTO createApplyElementForNonBagFunctions(String functionId,
                                                                   String category,
                                                                   String attributeId,
                                                                   String attributeValue,
                                                                   String dataType){

    ApplyElementDTO applyElementDTO = new ApplyElementDTO();
    functionId = processFunction(functionId, dataType);
    if(attributeValue != null && attributeValue.trim().length() > 0 && functionId != null &&
            functionId.trim().length() > 0 && category != null &&
            category.trim().length() > 0 && attributeId != null &&
            attributeId.trim().length() > 0) {

        AttributeValueElementDTO attributeValueElementDTO = new AttributeValueElementDTO();
        if(dataType != null && dataType.trim().length() > 0){
            attributeValueElementDTO.setAttributeDataType(dataType);
        } else {
            attributeValueElementDTO.setAttributeDataType(PolicyConstants.STRING_DATA_TYPE);
        }
        attributeValueElementDTO.setAttributeValue(attributeValue.trim());

        AttributeDesignatorDTO attributeDesignatorDTO = new AttributeDesignatorDTO();
        if(dataType != null && dataType.trim().length() > 0){
            attributeDesignatorDTO.setDataType(dataType);
        } else {
            attributeDesignatorDTO.setDataType(PolicyConstants.STRING_DATA_TYPE);
        }
        attributeDesignatorDTO.setAttributeId(attributeId);
        attributeDesignatorDTO.setCategory(category);

        applyElementDTO.setAttributeValueElementDTO(attributeValueElementDTO);
        applyElementDTO.setAttributeDesignators(attributeDesignatorDTO);
        applyElementDTO.setFunctionId(functionId);

    }

    return applyElementDTO;
}
 
Example 23
Source Project: balana   Source File: BasicPolicyHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static ApplyElementDTO createApplyElementForNonBagFunctionsWithAnyOf(String functionId,
                                                                            String category,
                                                                            String attributeDesignatorId,
                                                                            String dataType,
                                                                            String attributeValue){
    ApplyElementDTO applyElementDTO = null;
    functionId = processFunction(functionId, dataType);
    if(attributeValue != null && attributeValue.trim().length() > 0 && functionId != null &&
            functionId.trim().length() > 0 && category != null &&
            category.trim().length() > 0 && attributeDesignatorId != null &&
            attributeDesignatorId.trim().length() > 0) {
        applyElementDTO = new ApplyElementDTO();
        AttributeValueElementDTO attributeValueElementDTO = new AttributeValueElementDTO();
        attributeValueElementDTO.setAttributeDataType(PolicyConstants.STRING_DATA_TYPE);
        if(dataType != null && dataType.trim().length() > 0){
            attributeValueElementDTO.setAttributeDataType(dataType);
        } else {
            attributeValueElementDTO.setAttributeDataType(PolicyConstants.STRING_DATA_TYPE);
        }
        attributeValueElementDTO.setAttributeValue(attributeValue.trim());

        AttributeDesignatorDTO attributeDesignatorDTO = new AttributeDesignatorDTO();
        if(dataType != null && dataType.trim().length() > 0){
            attributeDesignatorDTO.setDataType(dataType);
        } else {
            attributeDesignatorDTO.setDataType(PolicyConstants.STRING_DATA_TYPE);
        }
        attributeDesignatorDTO.setAttributeId(attributeDesignatorId);
        attributeDesignatorDTO.setCategory(category);

        applyElementDTO.setFunctionFunctionId(functionId);
        applyElementDTO.setAttributeValueElementDTO(attributeValueElementDTO);
        applyElementDTO.setAttributeDesignators(attributeDesignatorDTO);
        applyElementDTO.setFunctionId(PolicyConstants.XACMLData.FUNCTION_ANY_OF);

    }

    return applyElementDTO;
}
 
Example 24
Source Project: balana   Source File: BasicPolicyHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static MatchElementDTO createMatchElementForNonBagFunctions(String functionId,
                                                                   String attributeValue,
                                                                   String category,
                                                                   String attributeId,
                                                                   String dataType) {

    MatchElementDTO matchElementDTO = new MatchElementDTO();
    functionId = processFunction(functionId, dataType);
    if(functionId != null && functionId.trim().length() > 0 && attributeValue != null &&
            attributeValue.trim().length() > 0&& category != null &&
            category.trim().length() > 0 && attributeId != null &&
            attributeId.trim().length() > 0) {
        AttributeValueElementDTO attributeValueElementDTO = new AttributeValueElementDTO();
        if(dataType != null && dataType.trim().length() > 0){
            attributeValueElementDTO.setAttributeDataType(dataType);
        } else {
            attributeValueElementDTO.setAttributeDataType(PolicyConstants.STRING_DATA_TYPE);
        }
        attributeValueElementDTO.setAttributeValue(attributeValue.trim());

        AttributeDesignatorDTO attributeDesignatorDTO = new AttributeDesignatorDTO();
        if(dataType != null && dataType.trim().length() > 0){
            attributeDesignatorDTO.setDataType(dataType);
        } else {
            attributeDesignatorDTO.setDataType(PolicyConstants.STRING_DATA_TYPE);
        }
        attributeDesignatorDTO.setAttributeId(attributeId);
        attributeDesignatorDTO.setCategory(category);

        matchElementDTO.setMatchId(functionId);
        matchElementDTO.setAttributeValueElementDTO(attributeValueElementDTO);
        matchElementDTO.setAttributeDesignatorDTO(attributeDesignatorDTO);
    }

    return matchElementDTO;
}
 
Example 25
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method creates a match elementof the XACML policy
 * @param matchElementDTO match element data object
 * @param doc XML document
 * @return match Element
 * @throws PolicyBuilderException throws
 */
public static Element createMatchElement(MatchElementDTO matchElementDTO,
                                         Document doc) throws PolicyBuilderException {

    Element matchElement = null;
    if(matchElementDTO.getMatchId() != null && matchElementDTO.getMatchId().trim().length() > 0) {

        matchElement = doc.createElement(PolicyConstants.MATCH_ELEMENT);

        matchElement.setAttribute(PolicyConstants.MATCH_ID,
                matchElementDTO.getMatchId());

        if(matchElementDTO.getAttributeValueElementDTO() != null) {
            Element attributeValueElement = createAttributeValueElement(matchElementDTO.
                    getAttributeValueElementDTO(), doc);
            matchElement.appendChild(attributeValueElement);
        }

        if(matchElementDTO.getAttributeDesignatorDTO() != null ) {
            Element attributeDesignatorElement = createAttributeDesignatorElement(matchElementDTO.
                    getAttributeDesignatorDTO(), doc);
            matchElement.appendChild(attributeDesignatorElement);
        }

        if(matchElementDTO.getAttributeSelectorDTO() != null ) {
            Element attributeSelectorElement = createAttributeSelectorElement(matchElementDTO.
                    getAttributeSelectorDTO(), doc);
            matchElement.appendChild(attributeSelectorElement);
        }
    }
    return matchElement;
}
 
Example 26
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of Attributes Element using AttributesElementDTO object
 *
 * @param elementDTO  AttributesElementDTO
 * @param doc Document
 * @return DOM element
 */
public static Element createAttributesElement(AttributesElementDTO elementDTO, Document doc){

    Element attributesElement = doc.createElement(PolicyConstants.ATTRIBUTES);

    attributesElement.setAttribute(PolicyConstants.CATEGORY, elementDTO.getCategory());

    List<AttributeElementDTO> attributeElementDTOs = elementDTO.getAttributeElementDTOs();
    if(attributeElementDTOs != null && attributeElementDTOs.size() > 0){
        for(AttributeElementDTO attributeElementDTO : attributeElementDTOs){
            Element attributeElement = doc.createElement(PolicyConstants.ATTRIBUTE);
            attributeElement.setAttribute(PolicyConstants.ATTRIBUTE_ID,
                    attributeElementDTO.getAttributeId());
            attributeElement.setAttribute(PolicyConstants.INCLUDE_RESULT,
                    Boolean.toString(attributeElementDTO.isIncludeInResult()));

            if(attributeElementDTO.getIssuer() != null &&
                    attributeElementDTO.getIssuer().trim().length() > 0){
                attributeElement.setAttribute(PolicyConstants.ISSUER,
                        attributeElementDTO.getIssuer());
            }

            List<String> values = attributeElementDTO.getAttributeValues();
            for(String value : values){
                Element attributeValueElement = doc.createElement(PolicyConstants.
                        ATTRIBUTE_VALUE);
                attributeValueElement.setAttribute(PolicyConstants.DATA_TYPE,
                        attributeElementDTO.getDataType());
                attributeValueElement.setTextContent(value.trim());
                attributeElement.appendChild(attributeValueElement);
            }
            attributesElement.appendChild(attributeElement);
        }
    }
    return attributesElement;
}
 
Example 27
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of function Element using FunctionElementDTO object
 *
 * @param functionElementDTO  FunctionElementDTO
 * @param doc Document
 * @return DOM element
 */
public static Element createFunctionElement(FunctionElementDTO functionElementDTO, Document doc) {

    Element functionElement = doc.createElement(PolicyConstants.FUNCTION);

    if(functionElementDTO.getFunctionId() != null && functionElementDTO.getFunctionId().trim().length() > 0) {
        functionElement.setAttribute(PolicyConstants.FUNCTION_ID,
                functionElementDTO.getFunctionId());
    }

    return functionElement;
}
 
Example 28
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of attribute selector Element using AttributeSelectorDTO object
 *
 * @param attributeSelectorDTO  AttributeSelectorDTO
 * @param doc Document
 * @return DOM element
 */
public static Element createAttributeSelectorElement(AttributeSelectorDTO attributeSelectorDTO,
                                                     Document doc)  {

    Element attributeSelectorElement = doc.createElement(PolicyConstants.
            ATTRIBUTE_SELECTOR);

    if(attributeSelectorDTO.getAttributeSelectorRequestContextPath() != null &&
            attributeSelectorDTO.getAttributeSelectorRequestContextPath().trim().length() > 0) {

        attributeSelectorElement.setAttribute(PolicyConstants.REQUEST_CONTEXT_PATH,
                PolicyConstants.ATTRIBUTE_NAMESPACE + attributeSelectorDTO.
                        getAttributeSelectorRequestContextPath());

        if(attributeSelectorDTO.getAttributeSelectorDataType() != null &&
                attributeSelectorDTO.getAttributeSelectorDataType().trim().length() > 0) {
            attributeSelectorElement.setAttribute(PolicyConstants.DATA_TYPE,
                    attributeSelectorDTO.getAttributeSelectorDataType());
        } else {
            attributeSelectorElement.setAttribute(PolicyConstants.DATA_TYPE,
                    PolicyConstants.STRING_DATA_TYPE);
        }

        if(attributeSelectorDTO.getAttributeSelectorMustBePresent() != null &&
                attributeSelectorDTO.getAttributeSelectorMustBePresent().trim().length() > 0) {
            attributeSelectorElement.setAttribute(PolicyConstants.MUST_BE_PRESENT,
                    attributeSelectorDTO.getAttributeSelectorMustBePresent());
        }

    }

    return attributeSelectorElement;
}
 
Example 29
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of obligation Element  using List of ObligationElementDTO object
 *
 * @param obligationElementDTOs List of ObligationElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createObligationsElement(List<ObligationElementDTO> obligationElementDTOs,
                                               Document doc) throws PolicyBuilderException {


    Element obligationExpressions = null;

    if(obligationElementDTOs != null && obligationElementDTOs.size() > 0){

        for(ObligationElementDTO dto : obligationElementDTOs){
            String id = dto.getId();
            String effect = dto.getEffect();

            if(id != null && id.trim().length() > 0 && effect != null){
                if(obligationExpressions == null){
                    obligationExpressions = doc.
                            createElement(PolicyConstants.OBLIGATION_EXPRESSIONS);
                }
                Element obligationExpression = doc.
                        createElement(PolicyConstants.OBLIGATION_EXPRESSION);
                obligationExpression.setAttribute(PolicyConstants.OBLIGATION_ID, id);
                obligationExpression.setAttribute(PolicyConstants.OBLIGATION_EFFECT,
                        effect);
                List<AttributeAssignmentElementDTO> elementDTOs = dto.getAssignmentElementDTOs();
                if(elementDTOs != null){
                    for(AttributeAssignmentElementDTO elementDTO : elementDTOs){
                        Element element = createAttributeAssignmentElement(elementDTO, doc);
                        if(element != null){
                            obligationExpression.appendChild(element);
                        }
                    }
                }
                obligationExpressions.appendChild(obligationExpression);
            }
        }
    }

    return obligationExpressions;
}
 
Example 30
Source Project: balana   Source File: PolicyUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of advice element using List of ObligationElementDTO object
 *
 * @param obligationElementDTOs List of ObligationElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createAdvicesElement(List<ObligationElementDTO> obligationElementDTOs,
                                               Document doc) throws PolicyBuilderException {

    Element adviceExpressions = null;

    if(obligationElementDTOs != null && obligationElementDTOs.size() > 0){

        for(ObligationElementDTO dto : obligationElementDTOs){
            String id = dto.getId();
            String effect = dto.getEffect();

            if(id != null && id.trim().length() > 0 && effect != null){
                if(adviceExpressions == null){
                    adviceExpressions = doc.
                            createElement(PolicyConstants.ADVICE_EXPRESSIONS);
                }

                Element adviceExpression = doc.
                        createElement(PolicyConstants.ADVICE_EXPRESSION);
                adviceExpression.setAttribute(PolicyConstants.ADVICE_ID, id);
                adviceExpression.setAttribute(PolicyConstants.ADVICE_EFFECT, effect);
                List<AttributeAssignmentElementDTO> elementDTOs = dto.getAssignmentElementDTOs();
                if(elementDTOs != null){
                    for(AttributeAssignmentElementDTO elementDTO : elementDTOs){
                        Element element = createAttributeAssignmentElement(elementDTO, doc);
                        if(element != null){
                            adviceExpression.appendChild(element);
                        }
                    }
                }
                adviceExpressions.appendChild(adviceExpression);
            }
        }
    }

    return adviceExpressions;
}