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

The following examples show how to use org.wso2.balana.utils.Constants.PolicyConstants. 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
/**
 * 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
Source File: PolicyEditorUtil.java    From carbon-identity with 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 #3
Source File: PolicyEditorUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #5
Source File: PolicyEditorUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: PolicyUtils.java    From balana with 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 #7
Source File: PolicyUtils.java    From balana with 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 #8
Source File: PolicyUtils.java    From balana with 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 #9
Source File: PolicyUtils.java    From balana with 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 #10
Source File: BasicPolicyHelper.java    From balana with 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 #11
Source File: Utils.java    From carbon-identity with 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 #12
Source File: PolicyEditorUtil.java    From carbon-identity with 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 #13
Source File: PolicyUtils.java    From balana with 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 #14
Source File: PolicyEditorUtil.java    From carbon-identity with 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 #15
Source File: PolicyEditorUtil.java    From carbon-identity with 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 #16
Source File: BasicPolicyHelper.java    From balana with 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 #17
Source File: BasicPolicyHelper.java    From balana with 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 #18
Source File: PolicyEditorUtil.java    From carbon-identity with 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 #19
Source File: PolicyUtils.java    From balana with 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 #20
Source File: PolicyUtils.java    From balana with 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;
}
 
Example #21
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #22
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #23
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #24
Source File: PolicyUtils.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of condition element using ConditionElementDT0 object
 *
 * @param conditionElementDT0 ConditionElementDT0
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createConditionElement(ConditionElementDT0 conditionElementDT0,
                                             Document doc) throws PolicyBuilderException {

    Element conditionElement = doc.createElement(PolicyConstants.CONDITION_ELEMENT);

    if(conditionElementDT0.getApplyElement() != null){
        conditionElement.appendChild(createApplyElement(conditionElementDT0.getApplyElement(), doc));

    } else if(conditionElementDT0.getAttributeValueElementDTO() != null) {
        Element attributeValueElement = createAttributeValueElement(conditionElementDT0.
                getAttributeValueElementDTO(), doc);
        conditionElement.appendChild(attributeValueElement);

    } else if(conditionElementDT0.getAttributeDesignator() != null) {
        AttributeDesignatorDTO attributeDesignatorDTO = conditionElementDT0.getAttributeDesignator();
        conditionElement.appendChild(createAttributeDesignatorElement(attributeDesignatorDTO, doc));

    } else if(conditionElementDT0.getFunctionFunctionId() != null) {
        Element functionElement = doc.createElement(PolicyConstants.FUNCTION_ELEMENT);
        functionElement.setAttribute(PolicyConstants.FUNCTION_ID,
                conditionElementDT0.getFunctionFunctionId());
        conditionElement.appendChild(functionElement);
    } else if(conditionElementDT0.getVariableId() != null){
        Element variableReferenceElement = doc.createElement(PolicyConstants.
                VARIABLE_REFERENCE);
        variableReferenceElement.setAttribute(PolicyConstants.VARIABLE_ID,
                conditionElementDT0.getVariableId());
        conditionElement.appendChild(variableReferenceElement);
    }

    return conditionElement;

}
 
Example #25
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #26
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #27
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #28
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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 #29
Source File: PolicyUtils.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of target element using TargetElementDTO object
 *
 * @param targetElementDTO TargetElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createTargetElement(TargetElementDTO targetElementDTO,
                                                Document doc) throws PolicyBuilderException {

    Element targetElement = doc.createElement(PolicyConstants.TARGET_ELEMENT);
    List<AnyOfElementDTO> anyOfElementDTOs = targetElementDTO.getAnyOfElementDTOs();

    for(AnyOfElementDTO anyOfElementDTO : anyOfElementDTOs){
        Element anyOfElement = doc.createElement(PolicyConstants.ANY_OF_ELEMENT);
        List<AllOfElementDTO> allOfElementDTOs = anyOfElementDTO.getAllOfElementDTOs();

        for(AllOfElementDTO allOfElementDTO : allOfElementDTOs){
            Element allOfElement = doc.createElement(PolicyConstants.ALL_OF_ELEMENT);
            List<MatchElementDTO> matchElementDTOs =  allOfElementDTO.getMatchElementDTOs();

            for(MatchElementDTO matchElementDTO : matchElementDTOs){
                Element matchElement = createMatchElement(matchElementDTO, doc);

                allOfElement.appendChild(matchElement);
            }

            anyOfElement.appendChild(allOfElement);
        }

        targetElement.appendChild(anyOfElement);
    }

    return targetElement;

}
 
Example #30
Source File: PolicyEditorUtil.java    From carbon-identity-framework with 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;
}