Search in sources :

Example 1 with Obligation

use of org.wso2.balana.xacml3.Obligation in project carbon-identity-framework by wso2.

the class PolicyEditorUtil method processPolicyData.

/**
 * Modifies the user data that are got from policy editor. If there are null values for required
 * things, replace them with default values
 */
public static String[] processPolicyData(PolicyDTO policyDTO) {
    TargetDTO targetDTO = policyDTO.getTargetDTO();
    List<RuleDTO> ruleDTOs = policyDTO.getRuleDTOs();
    List<ObligationDTO> obligationDTOs = policyDTO.getObligationDTOs();
    String ruleElementOrder = policyDTO.getRuleOrder();
    PolicyEditorDataHolder holder = PolicyEditorEngine.getInstance().getPolicyEditorData(EntitlementConstants.PolicyEditor.STANDARD);
    List<String> policyMetaDataList = new ArrayList<String>();
    List<RuleDTO> arrangedRules = new ArrayList<RuleDTO>();
    if (ruleElementOrder != null && ruleElementOrder.trim().length() > 0) {
        String[] ruleIds = ruleElementOrder.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
        for (String ruleId : ruleIds) {
            for (RuleDTO ruleDTO : ruleDTOs) {
                if (ruleId.equals(ruleDTO.getRuleId())) {
                    arrangedRules.add(ruleDTO);
                }
            }
        }
        ruleDTOs = arrangedRules;
    }
    createMetaDataFromPolicy("policy", policyDTO, policyMetaDataList);
    String algorithm = policyDTO.getRuleAlgorithm();
    if (algorithm != null && algorithm.trim().length() > 0) {
        policyDTO.setRuleAlgorithm(holder.getRuleAlgorithmUri(algorithm));
    } else {
        policyDTO.setRuleAlgorithm(holder.getDefaultRuleAlgorithm());
    }
    if (targetDTO != null && targetDTO.getRowDTOList() != null) {
        List<RowDTO> newRowDTOs = new ArrayList<RowDTO>();
        for (RowDTO rowDTO : targetDTO.getRowDTOList()) {
            createMetaDataFromRowDTO("target", rowDTO, policyMetaDataList);
            String category = rowDTO.getCategory();
            if (category == null) {
                continue;
            }
            String attributeValue = rowDTO.getAttributeValue();
            if (attributeValue == null || attributeValue.trim().length() < 1) {
                continue;
            }
            rowDTO.setCategory(holder.getCategoryUri(category));
            if (rowDTO.getAttributeDataType() == null || rowDTO.getAttributeDataType().trim().length() < 1 || rowDTO.getAttributeDataType().trim().equals("null")) {
                if (holder.getDefaultDataType() != null) {
                    rowDTO.setAttributeDataType(holder.getDefaultDataType());
                } else {
                    rowDTO.setAttributeDataType(PolicyEditorConstants.DataType.STRING);
                }
            } else {
                if (holder.getDataTypeUri(rowDTO.getAttributeDataType()) != null) {
                    rowDTO.setAttributeDataType(holder.getDataTypeUri(rowDTO.getAttributeDataType()));
                }
            }
            String attributeId = rowDTO.getAttributeId();
            if (attributeId == null || attributeId.trim().length() < 1 || attributeId.trim().equals("null")) {
                attributeId = holder.getCategoryDefaultAttributeId(category);
            }
            rowDTO.setAttributeId(holder.getAttributeIdUri(attributeId));
            rowDTO.setFunction(holder.getFunctionUri(rowDTO.getFunction()));
            rowDTO.setPreFunction(holder.getPreFunctionUri(rowDTO.getPreFunction()));
            newRowDTOs.add(rowDTO);
        }
        targetDTO.setRowDTOList(newRowDTOs);
        policyDTO.setTargetDTO(targetDTO);
    }
    if (ruleDTOs != null) {
        for (RuleDTO ruleDTO : ruleDTOs) {
            createMetaDataFromRule("rule", ruleDTO, policyMetaDataList);
            List<RowDTO> newRowDTOs = new ArrayList<RowDTO>();
            for (RowDTO rowDTO : ruleDTO.getRowDTOList()) {
                createMetaDataFromRowDTO("ruleRow" + ruleDTO.getRuleId(), rowDTO, policyMetaDataList);
                String category = rowDTO.getCategory();
                if (category == null) {
                    continue;
                }
                String attributeValue = rowDTO.getAttributeValue();
                if (attributeValue == null || attributeValue.trim().length() < 1) {
                    continue;
                }
                rowDTO.setCategory(holder.getCategoryUri(category));
                if (rowDTO.getAttributeDataType() == null || rowDTO.getAttributeDataType().trim().length() < 1 || rowDTO.getAttributeDataType().trim().equals("null")) {
                    if (holder.getDefaultDataType() != null) {
                        rowDTO.setAttributeDataType(holder.getDefaultDataType());
                    } else {
                        rowDTO.setAttributeDataType(PolicyEditorConstants.DataType.STRING);
                    }
                } else {
                    if (holder.getDataTypeUri(rowDTO.getAttributeDataType()) != null) {
                        rowDTO.setAttributeDataType(holder.getDataTypeUri(rowDTO.getAttributeDataType()));
                    }
                }
                String attributeId = rowDTO.getAttributeId();
                if (attributeId == null || attributeId.trim().length() < 1 || attributeId.trim().equals("null")) {
                    attributeId = holder.getCategoryDefaultAttributeId(category);
                }
                rowDTO.setAttributeId(holder.getAttributeIdUri(attributeId));
                rowDTO.setFunction(holder.getFunctionUri(rowDTO.getFunction()));
                rowDTO.setPreFunction(holder.getPreFunctionUri(rowDTO.getPreFunction()));
                newRowDTOs.add(rowDTO);
            }
            ruleDTO.setRowDTOList(newRowDTOs);
            TargetDTO ruleTargetDTO = ruleDTO.getTargetDTO();
            if (ruleTargetDTO == null) {
                continue;
            }
            List<RowDTO> newTargetRowDTOs = new ArrayList<RowDTO>();
            for (RowDTO rowDTO : ruleTargetDTO.getRowDTOList()) {
                createMetaDataFromRowDTO("ruleTarget" + ruleDTO.getRuleId(), rowDTO, policyMetaDataList);
                String category = rowDTO.getCategory();
                if (category == null) {
                    continue;
                }
                String attributeValue = rowDTO.getAttributeValue();
                if (attributeValue == null || attributeValue.trim().length() < 1) {
                    continue;
                }
                rowDTO.setCategory(holder.getCategoryUri(category));
                if (rowDTO.getAttributeDataType() == null || rowDTO.getAttributeDataType().trim().length() < 1 || rowDTO.getAttributeDataType().trim().equals("null")) {
                    if (holder.getDefaultDataType() != null) {
                        rowDTO.setAttributeDataType(holder.getDefaultDataType());
                    } else {
                        rowDTO.setAttributeDataType(PolicyEditorConstants.DataType.STRING);
                    }
                } else {
                    if (holder.getDataTypeUri(rowDTO.getAttributeDataType()) != null) {
                        rowDTO.setAttributeDataType(holder.getDataTypeUri(rowDTO.getAttributeDataType()));
                    }
                }
                String attributeId = rowDTO.getAttributeId();
                if (attributeId == null || attributeId.trim().length() < 1 || attributeId.trim().equals("null")) {
                    attributeId = holder.getCategoryDefaultAttributeId(category);
                }
                rowDTO.setAttributeId(holder.getAttributeIdUri(attributeId));
                rowDTO.setFunction(holder.getFunctionUri(rowDTO.getFunction()));
                rowDTO.setPreFunction(holder.getPreFunctionUri(rowDTO.getPreFunction()));
                newTargetRowDTOs.add(rowDTO);
            }
            ruleTargetDTO.setRowDTOList(newTargetRowDTOs);
            List<ObligationDTO> ruleObligationDTOs = ruleDTO.getObligationDTOs();
            if (ruleObligationDTOs != null) {
                for (ObligationDTO dto : ruleObligationDTOs) {
                    createMetaDataFromObligation("ruleObligation" + ruleDTO.getRuleId(), dto, policyMetaDataList);
                    if (dto.getAttributeValueDataType() == null || dto.getAttributeValueDataType().trim().length() < 1 || dto.getAttributeValueDataType().trim().equals("null")) {
                        dto.setAttributeValueDataType(PolicyEditorConstants.DataType.STRING);
                    }
                    if (dto.getResultAttributeId() == null || dto.getResultAttributeId().trim().length() == 0 || dto.getResultAttributeId().trim().equals("null")) {
                        // setting obligation id
                        dto.setResultAttributeId(dto.getObligationId());
                    }
                }
                ruleDTO.setObligationDTOs(ruleObligationDTOs);
            }
            ruleDTO.setTargetDTO(ruleTargetDTO);
        }
        policyDTO.setRuleDTOs(ruleDTOs);
    }
    if (obligationDTOs != null) {
        for (ObligationDTO dto : obligationDTOs) {
            createMetaDataFromObligation("obligation", dto, policyMetaDataList);
            if (dto.getAttributeValueDataType() == null || dto.getAttributeValueDataType().trim().length() == 0 || dto.getAttributeValueDataType().trim().equals("null")) {
                dto.setAttributeValueDataType(PolicyEditorConstants.DataType.STRING);
            }
            if (dto.getResultAttributeId() == null || dto.getResultAttributeId().trim().length() == 0 || dto.getResultAttributeId().trim().equals("null")) {
                // setting obligation id
                dto.setResultAttributeId(dto.getObligationId());
            }
        }
        policyDTO.setObligationDTOs(obligationDTOs);
    }
    return policyMetaDataList.toArray(new String[policyMetaDataList.size()]);
}
Also used : PolicyEditorDataHolder(org.wso2.carbon.identity.entitlement.common.dto.PolicyEditorDataHolder) RuleDTO(org.wso2.carbon.identity.entitlement.ui.dto.RuleDTO) BasicRuleDTO(org.wso2.balana.utils.policy.dto.BasicRuleDTO) ObligationDTO(org.wso2.carbon.identity.entitlement.ui.dto.ObligationDTO) RowDTO(org.wso2.carbon.identity.entitlement.ui.dto.RowDTO) ArrayList(java.util.ArrayList) TargetDTO(org.wso2.carbon.identity.entitlement.ui.dto.TargetDTO) BasicTargetDTO(org.wso2.balana.utils.policy.dto.BasicTargetDTO)

Example 2 with Obligation

use of org.wso2.balana.xacml3.Obligation in project carbon-identity-framework by wso2.

the class JSONResponseWriter method abstractResultToJSONObject.

/**
 * Private method to convert a given Balana <code>{@link AbstractResult}</code> to a <code>{@link JsonObject}</code>
 *
 * @param result <code>{@link AbstractResult}</code>
 * @return <code>{@link JsonObject}</code>
 * @throws ResponseWriteException <code>{@link ResponseWriteException}</code>
 */
private static JsonObject abstractResultToJSONObject(AbstractResult result) throws ResponseWriteException {
    JsonObject jsonResult = new JsonObject();
    // Decision property is mandatory, if not set throw error
    if (result.getDecision() == -1) {
        throw new ResponseWriteException(40031, "XACML Result should contain the Decision");
    }
    jsonResult.addProperty(EntitlementEndpointConstants.DECISION, AbstractResult.DECISIONS[result.getDecision()]);
    // If Status object is present, convert it
    if (result.getStatus() != null) {
        jsonResult.add(EntitlementEndpointConstants.STATUS, statusToJSONObject(result.getStatus()));
    }
    // If Obligations are present
    if (result.getObligations() != null && !result.getObligations().isEmpty()) {
        // can only get ObligationResult objects from balana
        JsonArray obligations = new JsonArray();
        for (ObligationResult obligation : result.getObligations()) {
            if (obligation instanceof Obligation) {
                obligations.add(obligationToJsonObject((Obligation) obligation));
            } else {
                obligations.add(new JsonPrimitive(obligation.encode()));
            }
        }
        jsonResult.add(EntitlementEndpointConstants.OBLIGATIONS, obligations);
    }
    // Do the same with attributes
    if (result.getAdvices() != null && !result.getAdvices().isEmpty()) {
        // can only get ObligationResult objects from balana
        JsonArray advices = new JsonArray();
        for (Advice advice : result.getAdvices()) {
            advices.add(adviceToJsonObject(advice));
        }
        jsonResult.add(EntitlementEndpointConstants.ASSOCIATED_ADVICE, advices);
    }
    // If includeInResponse=true, other attributes will be populated from here with the decision.
    if (((Result) result).getAttributes() != null && !((Result) result).getAttributes().isEmpty()) {
        Set<Attributes> attributes = ((Result) result).getAttributes();
        for (Attributes attribute : attributes) {
            switch(attribute.getCategory().toString()) {
                case EntitlementEndpointConstants.CATEGORY_ACTION_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_ACTION, getJsonObject(attribute));
                    break;
                case EntitlementEndpointConstants.CATEGORY_RESOURCE_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_RESOURCE, getJsonObject(attribute));
                    break;
                case EntitlementEndpointConstants.CATEGORY_ACCESS_SUBJECT_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_ACCESS_SUBJECT, getJsonObject(attribute));
                    break;
                case EntitlementEndpointConstants.CATEGORY_ENVIRONMENT_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_ENVIRONMENT, getJsonObject(attribute));
                    break;
                case EntitlementEndpointConstants.CATEGORY_RECIPIENT_SUBJECT_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_RECIPIENT_SUBJECT, getJsonObject(attribute));
                    break;
                case EntitlementEndpointConstants.CATEGORY_INTERMEDIARY_SUBJECT_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_INTERMEDIARY_SUBJECT, getJsonObject(attribute));
                    break;
                case EntitlementEndpointConstants.CATEGORY_CODEBASE_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_CODEBASE, getJsonObject(attribute));
                    break;
                case EntitlementEndpointConstants.CATEGORY_REQUESTING_MACHINE_URI:
                    jsonResult.add(EntitlementEndpointConstants.CATEGORY_REQUESTING_MACHINE, getJsonObject(attribute));
                    break;
                default:
                    jsonResult.add(attribute.getCategory().toString(), getJsonObject(attribute));
                    break;
            }
        }
    }
    return jsonResult;
}
Also used : JsonArray(com.google.gson.JsonArray) Obligation(org.wso2.balana.xacml3.Obligation) ResponseWriteException(org.wso2.carbon.identity.entitlement.endpoint.exception.ResponseWriteException) JsonPrimitive(com.google.gson.JsonPrimitive) ObligationResult(org.wso2.balana.ObligationResult) Attributes(org.wso2.balana.xacml3.Attributes) JsonObject(com.google.gson.JsonObject) Advice(org.wso2.balana.xacml3.Advice) AbstractResult(org.wso2.balana.ctx.AbstractResult) ObligationResult(org.wso2.balana.ObligationResult) Result(org.wso2.balana.ctx.xacml3.Result)

Example 3 with Obligation

use of org.wso2.balana.xacml3.Obligation in project carbon-identity-framework by wso2.

the class TestJSONResponseWriter method testWriteWithObligations.

@Test
public void testWriteWithObligations() throws URISyntaxException {
    List<AttributeAssignment> assignments = new ArrayList<>();
    String content = "Error: Channel request is not WEB.";
    URI type = new URI("http://www.w3.org/2001/XMLSchema#string");
    URI attributeId = new URI("urn:oasis:names:tc:xacml:3.0:example:attribute:text");
    AttributeAssignment attributeAssignment = new AttributeAssignment(attributeId, type, null, content, null);
    assignments.add(attributeAssignment);
    List<ObligationResult> obligationResults = new ArrayList<>();
    ObligationResult obligationResult = new Obligation(assignments, new URI("channel_ko"));
    obligationResults.add(obligationResult);
    List<String> codes = new ArrayList<>();
    codes.add("urn:oasis:names:tc:xacml:1.0:status:ok");
    AbstractResult abstractResult = new Result(1, new Status(codes), obligationResults, null, null);
    ResponseCtx responseCtx = new ResponseCtx(abstractResult);
    JSONResponseWriter jsonResponseWriter = new JSONResponseWriter();
    try {
        JsonObject jsonObject = jsonResponseWriter.write(responseCtx);
        assertNotNull("Failed to build the XACML json response", jsonObject.toString());
        assertFalse("Failed to build the XACML json response", jsonObject.entrySet().isEmpty());
        for (Map.Entry<String, JsonElement> jsonElementEntry : jsonObject.entrySet()) {
            if (jsonElementEntry.getKey().equals("Response")) {
                JsonArray jsonArray = (JsonArray) jsonElementEntry.getValue();
                assertEquals("Failed to build the XACML json response with correct evaluation", jsonArray.get(0).getAsJsonObject().get("Decision").getAsString(), "Deny");
            }
        }
    } catch (ResponseWriteException e) {
        assertNull("Failed to build the XACML response", e);
    }
}
Also used : AttributeAssignment(org.wso2.balana.ctx.AttributeAssignment) Status(org.wso2.balana.ctx.Status) Obligation(org.wso2.balana.xacml3.Obligation) ResponseWriteException(org.wso2.carbon.identity.entitlement.endpoint.exception.ResponseWriteException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) URI(java.net.URI) ResponseCtx(org.wso2.balana.ctx.ResponseCtx) AbstractResult(org.wso2.balana.ctx.AbstractResult) ObligationResult(org.wso2.balana.ObligationResult) Result(org.wso2.balana.ctx.xacml3.Result) JsonArray(com.google.gson.JsonArray) ObligationResult(org.wso2.balana.ObligationResult) JsonElement(com.google.gson.JsonElement) AbstractResult(org.wso2.balana.ctx.AbstractResult) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 4 with Obligation

use of org.wso2.balana.xacml3.Obligation in project carbon-mediation by wso2.

the class EntitlementMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Entitlement mediator : Mediating from ContinuationState");
    }
    if (keyInvolved) {
        try {
            resolveEntitlementServerDynamicConfigs(synCtx);
        } catch (EntitlementProxyException e) {
            log.error("Error while initializing the PEP Proxy" + e);
            throw new SynapseException("Error while initializing the Entitlement PEP Proxy");
        }
    }
    boolean result = false;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    if (subBranch == 0) {
        // For Advice mediator
        if (!continuationState.hasChild()) {
            result = ((SequenceMediator) adviceMediator).mediate(synCtx, continuationState.getPosition() + 1);
            if (result) {
                // Stop the flow after executing all the mediators
                ContinuationStackManager.clearStack(synCtx);
                return false;
            }
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) ((SequenceMediator) adviceMediator).getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
        }
    } else if (subBranch == 1 || subBranch == 2) {
        // For Obligation
        SequenceMediator sequenceMediator;
        if (subBranch == 1) {
            sequenceMediator = (SequenceMediator) synCtx.getSequence(obligationsSeqKey);
        } else {
            sequenceMediator = (SequenceMediator) obligationsMediator;
        }
        if (!continuationState.hasChild()) {
            result = sequenceMediator.mediate(synCtx, continuationState.getPosition() + 1);
            Boolean isContinuationCall = (Boolean) synCtx.getProperty(SynapseConstants.CONTINUATION_CALL);
            if (!result && isContinuationCall != null && isContinuationCall) {
                // If result is false due to presence of a Call mediator, stop the flow
                return false;
            } else {
                ContinuationStackManager.removeReliantContinuationState(synCtx);
                String decision = (String) synCtx.getProperty(ENTITLEMENT_DECISION);
                if (!result) {
                    decision = "Deny";
                }
                // Set back the original payload
                OMElement originalEnv = (OMElement) synCtx.getProperty(ORIGINAL_ENTITLEMENT_PAYLOAD);
                try {
                    synCtx.setEnvelope(AXIOMUtils.getSOAPEnvFromOM(originalEnv));
                } catch (AxisFault axisFault) {
                    handleException("Error while setting the original envelope back", synCtx);
                }
                result = executeDecisionMessageFlow(synCtx, decision);
                if (result) {
                    // Just adding a dummy state back, which will be removed at the Sequence when returning.
                    ContinuationStackManager.addReliantContinuationState(synCtx, 1, getMediatorPosition());
                }
            }
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) sequenceMediator.getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
        }
    } else if (subBranch == 3) {
        // For onAcceptMediator
        if (!continuationState.hasChild()) {
            result = ((SequenceMediator) onAcceptMediator).mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) ((SequenceMediator) onAcceptMediator).getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
        }
    } else if (subBranch == 4) {
        // For onReject Mediator
        if (!continuationState.hasChild()) {
            result = ((SequenceMediator) onRejectMediator).mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) ((SequenceMediator) onRejectMediator).getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
        }
    }
    return result;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) SynapseException(org.apache.synapse.SynapseException) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) EntitlementProxyException(org.wso2.carbon.identity.entitlement.proxy.exception.EntitlementProxyException) OMElement(org.apache.axiom.om.OMElement) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 5 with Obligation

use of org.wso2.balana.xacml3.Obligation in project carbon-mediation by wso2.

the class EntitlementMediatorSerializer method serializeSpecificMediator.

/**
 * {@inheritDoc}
 */
public OMElement serializeSpecificMediator(Mediator mediator) {
    if (!(mediator instanceof EntitlementMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + mediator.getType());
    }
    EntitlementMediator entitlement = null;
    OMElement entitlementElem = null;
    entitlement = (EntitlementMediator) mediator;
    entitlementElem = fac.createOMElement("entitlementService", synNS);
    saveTracingState(entitlementElem, entitlement);
    if (entitlement.getRemoteServiceUrl() != null && !entitlement.getRemoteServiceUrl().isEmpty()) {
        entitlementElem.addAttribute(fac.createOMAttribute("remoteServiceUrl", nullNS, entitlement.getRemoteServiceUrl()));
    } else if (entitlement.getRemoteServiceUrlKey() != null && !entitlement.getRemoteServiceUrlKey().isEmpty()) {
        entitlementElem.addAttribute(fac.createOMAttribute("remoteServiceUrlKey", nullNS, entitlement.getRemoteServiceUrlKey()));
    }
    if (entitlement.getRemoteServiceUserName() != null && !entitlement.getRemoteServiceUserName().isEmpty()) {
        entitlementElem.addAttribute(fac.createOMAttribute("remoteServiceUserName", nullNS, entitlement.getRemoteServiceUserName()));
    } else if (entitlement.getRemoteServiceUserNameKey() != null && !entitlement.getRemoteServiceUserNameKey().isEmpty()) {
        entitlementElem.addAttribute(fac.createOMAttribute("remoteServiceUserNameKey", nullNS, entitlement.getRemoteServiceUserNameKey()));
    }
    if (entitlement.getRemoteServicePassword() != null && !entitlement.getRemoteServicePassword().isEmpty()) {
        entitlementElem.addAttribute(fac.createOMAttribute("remoteServicePassword", nullNS, entitlement.getRemoteServicePassword()));
    } else if (entitlement.getRemoteServicePasswordKey() != null && !entitlement.getRemoteServicePasswordKey().isEmpty()) {
        entitlementElem.addAttribute(fac.createOMAttribute("remoteServicePasswordKey", nullNS, entitlement.getRemoteServicePasswordKey()));
    }
    if (entitlement.getCallbackClass() != null) {
        entitlementElem.addAttribute(fac.createOMAttribute("callbackClass", nullNS, entitlement.getCallbackClass()));
    }
    if (entitlement.getCacheType() != null) {
        entitlementElem.addAttribute(fac.createOMAttribute("cacheType", nullNS, entitlement.getCacheType()));
    }
    if (entitlement.getInvalidationInterval() != 0) {
        entitlementElem.addAttribute(fac.createOMAttribute("invalidationInterval", nullNS, Integer.toString(entitlement.getInvalidationInterval())));
    }
    if (entitlement.getMaxCacheEntries() != 0) {
        entitlementElem.addAttribute(fac.createOMAttribute("maxCacheEntries", nullNS, Integer.toString(entitlement.getMaxCacheEntries())));
    }
    if (entitlement.getClient() != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(EntitlementConstants.CLIENT, nullNS, entitlement.getClient()));
    }
    if (entitlement.getThriftHost() != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(EntitlementConstants.THRIFT_HOST, nullNS, entitlement.getThriftHost()));
    }
    if (entitlement.getThriftPort() != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(EntitlementConstants.THRIFT_PORT, nullNS, entitlement.getThriftPort()));
    }
    if (entitlement.getReuseSession() != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(EntitlementConstants.REUSE_SESSION, nullNS, entitlement.getReuseSession()));
    }
    String onReject = entitlement.getOnRejectSeqKey();
    if (onReject != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(XMLConfigConstants.ONREJECT, nullNS, onReject));
    } else {
        Mediator m = entitlement.getOnRejectMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (m != null && m instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) m);
            element.setLocalName(XMLConfigConstants.ONREJECT);
            entitlementElem.addChild(element);
        }
    }
    String onAccept = entitlement.getOnAcceptSeqKey();
    if (onAccept != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(XMLConfigConstants.ONACCEPT, nullNS, onAccept));
    } else {
        Mediator m = entitlement.getOnAcceptMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (m != null && m instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) m);
            element.setLocalName(XMLConfigConstants.ONACCEPT);
            entitlementElem.addChild(element);
        }
    }
    String obligation = entitlement.getObligationsSeqKey();
    if (obligation != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(EntitlementMediatorFactory.OBLIGATIONS, nullNS, obligation));
    } else {
        Mediator m = entitlement.getObligationsMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (m != null && m instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) m);
            element.setLocalName(EntitlementMediatorFactory.OBLIGATIONS);
            entitlementElem.addChild(element);
        }
    }
    String advice = entitlement.getAdviceSeqKey();
    if (advice != null) {
        entitlementElem.addAttribute(fac.createOMAttribute(EntitlementMediatorFactory.ADVICE, nullNS, advice));
    } else {
        Mediator m = entitlement.getAdviceMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (m != null && m instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) m);
            element.setLocalName(EntitlementMediatorFactory.ADVICE);
            entitlementElem.addChild(element);
        }
    }
    serializeComments(entitlementElem, entitlement.getCommentsList());
    return entitlementElem;
}
Also used : OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) EntitlementMediator(org.wso2.carbon.identity.entitlement.mediator.EntitlementMediator) SequenceMediatorSerializer(org.apache.synapse.config.xml.SequenceMediatorSerializer) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) EntitlementMediator(org.wso2.carbon.identity.entitlement.mediator.EntitlementMediator)

Aggregations

ArrayList (java.util.ArrayList)6 BasicTargetDTO (org.wso2.balana.utils.policy.dto.BasicTargetDTO)4 PolicyEditorDataHolder (org.wso2.carbon.identity.entitlement.common.dto.PolicyEditorDataHolder)4 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 RowDTO (org.wso2.carbon.identity.entitlement.ui.dto.RowDTO)3 Map (java.util.Map)2 OMElement (org.apache.axiom.om.OMElement)2 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)2 ObligationResult (org.wso2.balana.ObligationResult)2 AbstractResult (org.wso2.balana.ctx.AbstractResult)2 AttributeAssignment (org.wso2.balana.ctx.AttributeAssignment)2 Result (org.wso2.balana.ctx.xacml3.Result)2 BasicRuleDTO (org.wso2.balana.utils.policy.dto.BasicRuleDTO)2 Obligation (org.wso2.balana.xacml3.Obligation)2 ObligationDTO (org.wso2.carbon.identity.entitlement.common.dto.ObligationDTO)2 RowDTO (org.wso2.carbon.identity.entitlement.common.dto.RowDTO)2 TargetDTO (org.wso2.carbon.identity.entitlement.common.dto.TargetDTO)2 ResponseWriteException (org.wso2.carbon.identity.entitlement.endpoint.exception.ResponseWriteException)2 ObligationDTO (org.wso2.carbon.identity.entitlement.ui.dto.ObligationDTO)2