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);
}
}
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");
}
}
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);
}
}
}
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;
}
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;
}
Aggregations