Search in sources :

Example 31 with Parameter

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

the class TaintAnalyzer method analyzeReturnTaintedStatus.

private void analyzeReturnTaintedStatus(Map<Integer, TaintRecord> taintTable, BLangInvokableNode invokableNode, SymbolEnv symbolEnv, int paramIndex, int requiredParamCount, int defaultableParamCount) {
    resetTaintedStatusOfVariables(invokableNode.requiredParams);
    resetTaintedStatusOfVariableDef(invokableNode.defaultableParams);
    if (invokableNode.restParam != null) {
        resetTaintedStatusOfVariables(Arrays.asList(new BLangVariable[] { invokableNode.restParam }));
    }
    // Mark the given parameter "tainted".
    if (paramIndex != ALL_UNTAINTED_TABLE_ENTRY_INDEX) {
        if (paramIndex < requiredParamCount) {
            invokableNode.requiredParams.get(paramIndex).symbol.tainted = true;
        } else if (paramIndex < requiredParamCount + defaultableParamCount) {
            invokableNode.defaultableParams.get(paramIndex - requiredParamCount).var.symbol.tainted = true;
        } else {
            invokableNode.restParam.symbol.tainted = true;
        }
    }
    analyzeReturnTaintedStatus(invokableNode, symbolEnv);
    if (taintErrorSet.size() > 0) {
        // When invocation returns an error (due to passing a tainted argument to a sensitive parameter) add current
        // error to the table for future reference.
        taintTable.put(paramIndex, new TaintRecord(null, new ArrayList<>(taintErrorSet)));
        taintErrorSet.clear();
    } else if (this.blockedNode == null) {
        if (invokableNode.retParams.size() == 0) {
            returnTaintedStatusList = new ArrayList<>();
        } else {
            updatedReturnTaintedStatusBasedOnAnnotations(invokableNode.retParams);
        }
        taintTable.put(paramIndex, new TaintRecord(returnTaintedStatusList, null));
    }
}
Also used : ArrayList(java.util.ArrayList) TaintRecord(org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 32 with Parameter

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

the class TaintAnalyzer method attachTaintTableBasedOnAnnotations.

private void attachTaintTableBasedOnAnnotations(BLangInvokableNode invokableNode) {
    if (invokableNode.symbol.taintTable == null) {
        // Extract tainted status of the function by lookint at annotations added to returns.
        List<Boolean> retParamsTaintedStatus = new ArrayList<>();
        for (BLangVariable retParam : invokableNode.retParams) {
            retParamsTaintedStatus.add(hasAnnotation(retParam, ANNOTATION_TAINTED));
        }
        // Append taint table with tainted status when no parameter is tainted.
        Map<Integer, TaintRecord> taintTable = new HashMap<>();
        taintTable.put(ALL_UNTAINTED_TABLE_ENTRY_INDEX, new TaintRecord(retParamsTaintedStatus, null));
        int requiredParamCount = invokableNode.requiredParams.size();
        int defaultableParamCount = invokableNode.defaultableParams.size();
        int totalParamCount = requiredParamCount + defaultableParamCount + (invokableNode.restParam == null ? 0 : 1);
        if (totalParamCount > 0) {
            // Append taint table with tainted status when each parameter is tainted.
            for (int paramIndex = 0; paramIndex < totalParamCount; paramIndex++) {
                BLangVariable param = getParam(invokableNode, paramIndex, requiredParamCount, defaultableParamCount);
                // If parameter is sensitive, test for this parameter being tainted is invalid.
                if (hasAnnotation(param, ANNOTATION_SENSITIVE)) {
                    continue;
                }
                taintTable.put(paramIndex, new TaintRecord(retParamsTaintedStatus, null));
            }
        }
        invokableNode.symbol.taintTable = taintTable;
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaintRecord(org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 33 with Parameter

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

the class CodeGenerator method createActionInfoEntry.

private void createActionInfoEntry(BLangAction actionNode, ConnectorInfo connectorInfo) {
    BInvokableSymbol actionSymbol = actionNode.symbol;
    BInvokableType actionType = (BInvokableType) actionSymbol.type;
    // Add action name as an UTFCPEntry to the constant pool
    int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionNode.name.value);
    ActionInfo actionInfo = new ActionInfo(currentPackageRefCPIndex, actionNameCPIndex);
    actionInfo.paramTypes = actionType.paramTypes.toArray(new BType[0]);
    actionInfo.retParamTypes = actionType.retTypes.toArray(new BType[0]);
    actionInfo.flags = actionSymbol.flags;
    // setParameterNames(actionNode, actionInfo);
    actionInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(actionInfo.paramTypes, actionInfo.retParamTypes));
    // Add worker info
    this.addWorkerInfoEntries(actionInfo, actionNode.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(actionNode, actionInfo);
    // Add action info to the connector info
    connectorInfo.actionInfoMap.put(actionNode.name.getValue(), actionInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) ActionInfo(org.wso2.ballerinalang.programfile.ActionInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 34 with Parameter

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

the class CodeGenerator method createFunctionInfoEntry.

/**
 * Creates a {@code FunctionInfo} from the given function node in AST.
 *
 * @param funcNode function node in AST
 */
private void createFunctionInfoEntry(BLangFunction funcNode) {
    BInvokableSymbol funcSymbol = funcNode.symbol;
    BInvokableType funcType = (BInvokableType) funcSymbol.type;
    // Add function name as an UTFCPEntry to the constant pool
    int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
    FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
    funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
    funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
    funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
    funcInfo.flags = funcSymbol.flags;
    if (funcNode.receiver != null) {
        funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
    }
    this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(funcNode, funcInfo);
    this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) AttachedFunctionInfo(org.wso2.ballerinalang.programfile.AttachedFunctionInfo) FunctionInfo(org.wso2.ballerinalang.programfile.FunctionInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 35 with Parameter

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

the class Desugar method visit.

@Override
public void visit(BLangFunction funcNode) {
    SymbolEnv fucEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, env);
    if (!funcNode.interfaceFunction) {
        addReturnIfNotPresent(funcNode);
    }
    // To preserve endpoint code gen order.
    Collections.reverse(funcNode.endpoints);
    funcNode.endpoints = rewrite(funcNode.endpoints, fucEnv);
    funcNode.body = rewrite(funcNode.body, fucEnv);
    funcNode.workers = rewrite(funcNode.workers, fucEnv);
    // the struct variable as the first parameter
    if (funcNode.receiver != null) {
        BInvokableSymbol funcSymbol = funcNode.symbol;
        List<BVarSymbol> params = funcSymbol.params;
        params.add(0, funcNode.receiver.symbol);
        BInvokableType funcType = (BInvokableType) funcSymbol.type;
        funcType.paramTypes.add(0, funcNode.receiver.type);
    }
    result = funcNode;
}
Also used : BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Aggregations

HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)32 Parameter (org.apache.axis2.description.Parameter)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)13 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)11 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)11 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)11 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)11 List (java.util.List)10 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 IOException (java.io.IOException)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 Test (org.testng.annotations.Test)8 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)8