Search in sources :

Example 81 with Environment

use of org.wso2.carbon.apimgt.api.model.Environment in project ballerina by ballerina-lang.

the class TreeVisitor method visit.

@Override
public void visit(BLangForkJoin forkJoin) {
    SymbolEnv folkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.symbolEnv);
    // TODO: check the symbolEnter.defineNode
    forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, folkJoinEnv));
    forkJoin.workers.forEach(e -> this.acceptNode(e, folkJoinEnv));
    // if (!this.isJoinResultType(forkJoin.joinResultVar)) {
    // this.dlog.error(forkJoin.joinResultVar.pos, DiagnosticCode.INVALID_WORKER_JOIN_RESULT_TYPE);
    // }
    /* create code black and environment for join result section, i.e. (map results) */
    BLangBlockStmt joinResultsBlock = this.generateCodeBlock(this.createVarDef(forkJoin.joinResultVar));
    SymbolEnv joinResultsEnv = SymbolEnv.createBlockEnv(joinResultsBlock, this.symbolEnv);
    this.acceptNode(joinResultsBlock, joinResultsEnv);
    /* create an environment for the join body, making the enclosing environment the earlier
         * join result's environment */
    SymbolEnv joinBodyEnv = SymbolEnv.createBlockEnv(forkJoin.joinedBody, joinResultsEnv);
    this.acceptNode(forkJoin.joinedBody, joinBodyEnv);
    if (forkJoin.timeoutExpression != null) {
        /* create code black and environment for timeout section */
        BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
        SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.symbolEnv);
        this.acceptNode(timeoutVarBlock, timeoutVarEnv);
        /* create an environment for the timeout body, making the enclosing environment the earlier
             * timeout var's environment */
        SymbolEnv timeoutBodyEnv = SymbolEnv.createBlockEnv(forkJoin.timeoutBody, timeoutVarEnv);
        this.acceptNode(forkJoin.timeoutBody, timeoutBodyEnv);
    }
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 82 with Environment

use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-business-process by wso2.

the class ReadTask method execute.

@Override
public void execute(DelegateExecution execution) throws Exception {
    String originStr = getExpressionStrValue(origin, execution);
    if (originStr == null) {
        throw new WSO2TaskException("\"origin\" parameter is mandatory, but found null");
    }
    String resourceName = getExpressionStrValue(resource, execution);
    if (resourceName == null) {
        throw new WSO2TaskException("\"resource\" parameter is mandatory, but found null");
    }
    String targetVarName = getExpressionStrValue(target, execution);
    if (targetVarName == null) {
        throw new WSO2TaskException("\"target\" parameter is mandatory, but found null");
    }
    String targetType = getExpressionStrValue(type, execution);
    if (targetType == null) {
        // type is optional
        targetType = "string";
    }
    if (ORIGIN_TYPE_REGISTRY.equalsIgnoreCase(originStr)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Registry resource Path : " + resourceName);
        }
        Resource resource = RegistryUtil.getRegistryResource(resourceName, Integer.parseInt(execution.getTenantId()));
        if (resource != null) {
            String regContent = new String((byte[]) resource.getContent(), Charset.defaultCharset());
            execution.setVariable(targetVarName, typeConvert(regContent, targetType));
        }
    } else if (ORIGIN_TYPE_ENV.equalsIgnoreCase(getExpressionStrValue(origin, execution))) {
        execution.setVariable(targetVarName, typeConvert(System.getenv(resourceName), targetType));
    } else if (ORIGIN_TYPE_SYS.equalsIgnoreCase(getExpressionStrValue(origin, execution))) {
        execution.setVariable(targetVarName, typeConvert(System.getProperty(resourceName), targetType));
    } else {
        throw new WSO2TaskException("Unknown origin : " + originStr + ". Only support : REGISTRY, ENVIRONMENT, " + "SYSTEM");
    }
}
Also used : Resource(org.wso2.carbon.bpmn.extensions.registry.Resource)

Example 83 with Environment

use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-identity-framework by wso2.

the class JsGraphBuilder method executeStep.

/**
 * Adds the step given by step ID tp the authentication graph.
 *
 * @param stepId Step Id
 * @param params params
 */
@SuppressWarnings("unchecked")
public final void executeStep(int stepId, Object... params) {
    StepConfig stepConfig;
    stepConfig = stepNamedMap.get(stepId);
    if (stepConfig == null) {
        log.error("Given Authentication Step :" + stepId + " is not in Environment");
        return;
    }
    StepConfigGraphNode newNode = wrap(stepConfig);
    if (currentNode == null) {
        result.setStartNode(newNode);
    } else {
        attachToLeaf(currentNode, newNode);
    }
    currentNode = newNode;
    if (params.length > 0) {
        // if there are any params provided, last one is assumed to be the event listeners
        if (params[params.length - 1] instanceof Map) {
            attachEventListeners((Map<String, Object>) params[params.length - 1]);
        } else {
            log.error("Invalid argument and hence ignored. Last argument should be a Map of event listeners.");
        }
    }
    if (params.length == 2) {
        // There is an argument with options present
        if (params[0] instanceof Map) {
            Map<String, Object> options = (Map<String, Object>) params[0];
            handleOptions(options, stepConfig);
        }
    }
}
Also used : StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) JSObject(jdk.nashorn.api.scripting.JSObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with Environment

use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-identity-framework by wso2.

the class AbstractPIPResourceFinder method findDescendantResources.

@Override
public Set<String> findDescendantResources(String parentResourceId, EvaluationCtx context) throws Exception {
    EvaluationResult environment;
    String environmentId = null;
    Set<String> resourceNames = null;
    NodeList children = context.getRequestRoot().getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child != null) {
            if (PDPConstants.ENVIRONMENT_ELEMENT.equals(child.getLocalName())) {
                if (child.getChildNodes() != null && child.getChildNodes().getLength() > 0) {
                    environment = context.getAttribute(new URI(StringAttribute.identifier), new URI(PDPConstants.ENVIRONMENT_ID_DEFAULT), null, new URI(XACMLConstants.ENT_CATEGORY));
                    if (environment != null && environment.getAttributeValue() != null && environment.getAttributeValue().isBag()) {
                        BagAttribute attr = (BagAttribute) environment.getAttributeValue();
                        environmentId = ((AttributeValue) attr.iterator().next()).encode();
                    }
                }
            }
        }
    }
    if (isAbstractResourceCacheEnabled) {
        IdentityCacheKey cacheKey;
        String key = PDPConstants.RESOURCE_DESCENDANTS + parentResourceId + (environmentId != null ? environmentId : "");
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        cacheKey = new IdentityCacheKey(tenantId, key);
        IdentityCacheEntry cacheEntry = (IdentityCacheEntry) abstractResourceCache.getValueFromCache(cacheKey);
        if (cacheEntry != null) {
            String[] values = cacheEntry.getCacheEntryArray();
            resourceNames = new HashSet<String>(Arrays.asList(values));
            if (log.isDebugEnabled()) {
                log.debug("Carbon Resource Cache Hit");
            }
        }
        if (resourceNames != null) {
            resourceNames = findDescendantResources(parentResourceId, environmentId);
            if (log.isDebugEnabled()) {
                log.debug("Carbon Resource Cache Miss");
            }
            if (resourceNames != null && !resourceNames.isEmpty()) {
                cacheEntry = new IdentityCacheEntry(resourceNames.toArray(new String[resourceNames.size()]));
                abstractResourceCache.addToCache(cacheKey, cacheEntry);
            }
        }
    } else {
        resourceNames = findDescendantResources(parentResourceId, environmentId);
    }
    return resourceNames;
}
Also used : IdentityCacheKey(org.wso2.carbon.identity.entitlement.cache.IdentityCacheKey) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IdentityCacheEntry(org.wso2.carbon.identity.entitlement.cache.IdentityCacheEntry) URI(java.net.URI) EvaluationResult(org.wso2.balana.cond.EvaluationResult) BagAttribute(org.wso2.balana.attr.BagAttribute)

Example 85 with Environment

use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-identity-framework by wso2.

the class PolicyEditorUtil method createMatchElement.

/**
 * This method creates a match element (such as subject,action,resource or environment) of the XACML policy
 *
 * @param matchElementDTO match element data object
 * @param doc             XML document
 * @return match Element
 * @throws PolicyEditorException if any error occurs
 */
public static Element createMatchElement(MatchElementDTO matchElementDTO, Document doc) throws PolicyEditorException {
    Element matchElement;
    if (matchElementDTO.getMatchId() != null && matchElementDTO.getMatchId().trim().length() > 0) {
        matchElement = doc.createElement(PolicyEditorConstants.MATCH_ELEMENT);
        matchElement.setAttribute(PolicyEditorConstants.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);
        } else if (matchElementDTO.getAttributeSelectorDTO() != null) {
            Element attributeSelectorElement = createAttributeSelectorElement(matchElementDTO.getAttributeSelectorDTO(), doc);
            matchElement.appendChild(attributeSelectorElement);
        }
    } else {
        throw new PolicyEditorException("Can not create Match element:" + " Required Attributes are missing");
    }
    return matchElement;
}
Also used : PolicyEditorException(org.wso2.carbon.identity.entitlement.common.PolicyEditorException) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element)

Aggregations

Environment (org.wso2.carbon.apimgt.api.model.Environment)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 ArrayList (java.util.ArrayList)38 HashMap (java.util.HashMap)28 API (org.wso2.carbon.apimgt.api.model.API)22 IOException (java.io.IOException)21 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)19 Map (java.util.Map)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)13 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)12 JsonObject (com.google.gson.JsonObject)11 Gson (com.google.gson.Gson)10 PreparedStatement (java.sql.PreparedStatement)10 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)10 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)10 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)10 JSONObject (org.json.simple.JSONObject)9 Test (org.junit.Test)9 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)9