use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class DefaultAuthorizationValidator method validate.
@Override
public boolean validate(String[] originalSql, Command command, QueryMetadataInterface metadata, CommandContext commandContext, CommandType commandType) throws QueryValidatorException, TeiidComponentException {
boolean modified = false;
if (policyDecider != null && policyDecider.validateCommand(commandContext)) {
if (ignoreUnathorizedInAsterisk(command, commandContext)) {
Query query = (Query) command;
HashMap<String, LanguageObject> map = null;
for (Expression ex : query.getSelect().getSymbols()) {
if (ex instanceof MultipleElementSymbol) {
MultipleElementSymbol mes = (MultipleElementSymbol) ex;
if (map == null) {
map = new HashMap<String, LanguageObject>();
}
for (Iterator<ElementSymbol> iter = mes.getElementSymbols().iterator(); iter.hasNext(); ) {
ElementSymbol es = iter.next();
Object metadataObject = es.getMetadataID();
if (metadataObject instanceof MultiSourceElement || metadataObject instanceof TempMetadataID) {
continue;
}
map.clear();
AuthorizationValidationVisitor.addToNameMap(metadataObject, es, map, commandContext.getMetadata());
Set<String> results = this.policyDecider.getInaccessibleResources(PermissionType.READ, map.keySet(), Context.QUERY, commandContext);
if (!results.isEmpty()) {
// remove from the select
iter.remove();
modified = true;
}
}
}
}
if (query.getProjectedSymbols().isEmpty()) {
throw new QueryValidatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31151));
}
}
AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(this.policyDecider, commandContext);
Request.validateWithVisitor(visitor, metadata, command);
}
return modified;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class LanguageBridgeFactory method translate.
public org.teiid.language.OrderBy translate(OrderBy orderBy, boolean set) {
if (orderBy == null) {
return null;
}
List<OrderByItem> items = orderBy.getOrderByItems();
List<SortSpecification> translatedItems = new ArrayList<SortSpecification>();
for (int i = 0; i < items.size(); i++) {
Expression symbol = items.get(i).getSymbol();
Ordering direction = items.get(i).isAscending() ? Ordering.ASC : Ordering.DESC;
SortSpecification orderByItem = null;
if (!set && (items.get(i).isUnrelated() || symbol instanceof ElementSymbol)) {
orderByItem = new SortSpecification(direction, translate(symbol));
} else {
orderByItem = new SortSpecification(direction, new ColumnReference(null, Symbol.getShortName(((Symbol) symbol).getOutputName()), null, symbol.getType()));
}
orderByItem.setNullOrdering(items.get(i).getNullOrdering());
translatedItems.add(orderByItem);
}
return new org.teiid.language.OrderBy(translatedItems);
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class LanguageBridgeFactory method translate.
public With translate(List<WithQueryCommand> with) {
if (with == null || with.isEmpty()) {
return null;
}
With result = new With();
ArrayList<WithItem> items = new ArrayList<WithItem>(with.size());
for (WithQueryCommand withQueryCommand : with) {
WithItem item = new WithItem();
GroupSymbol group = withQueryCommand.getGroupSymbol();
if (withQueryCommand.getCommand() != null && excludeWithName != null && excludeWithName.equalsIgnoreCase(group.getName())) {
group = RulePlaceAccess.recontextSymbol(withQueryCommand.getGroupSymbol(), commandContext.getGroups());
group.setDefinition(null);
if (remappedGroups == null) {
remappedGroups = new IdentityHashMap<Object, GroupSymbol>();
}
this.remappedGroups.put(group.getMetadataID(), group);
}
item.setTable(translate(group));
if (withQueryCommand.getColumns() != null) {
List<ColumnReference> translatedElements = new ArrayList<ColumnReference>(withQueryCommand.getColumns().size());
for (ElementSymbol es : withQueryCommand.getColumns()) {
ColumnReference cr = translate(es);
translatedElements.add(cr);
if (withQueryCommand.getCommand() == null) {
// we want to convey the metadata to the source layer if possible
Object mid = es.getMetadataID();
if (mid instanceof TempMetadataID) {
TempMetadataID tid = (TempMetadataID) mid;
mid = tid.getOriginalMetadataID();
}
if (mid instanceof Column) {
cr.setMetadataObject((Column) mid);
}
}
}
item.setColumns(translatedElements);
}
if (withQueryCommand.getCommand() != null) {
item.setSubquery(translate(withQueryCommand.getCommand()));
} else {
item.setDependentValues(new TupleBufferList(withQueryCommand.getTupleBuffer()));
}
item.setRecusive(withQueryCommand.isRecursive());
items.add(item);
}
result.setItems(items);
return result;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class AuthorizationValidationVisitor method addToNameMap.
static void addToNameMap(Object metadataID, LanguageObject symbol, Map<String, LanguageObject> nameToSymbolMap, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
String fullName = metadata.getFullName(metadataID);
Object modelId = metadata.getModelID(metadataID);
String modelName = metadata.getFullName(modelId);
if (!isSystemSchema(modelName)) {
// foreign temp table full names are not schema qualified by default
if (!metadata.isVirtualModel(modelId)) {
GroupSymbol group = null;
if (symbol instanceof ElementSymbol) {
group = ((ElementSymbol) symbol).getGroupSymbol();
} else if (symbol instanceof GroupSymbol) {
group = (GroupSymbol) symbol;
}
if (group != null && group.isTempGroupSymbol() && !group.isGlobalTable()) {
fullName = modelName + AbstractMetadataRecord.NAME_DELIM_CHAR + modelId;
}
}
nameToSymbolMap.put(fullName, symbol);
}
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestCriteriaEvaluator method helpGetCompareSubqueryCriteria.
private SubqueryCompareCriteria helpGetCompareSubqueryCriteria(int operator, int predicateQuantifier) {
// $NON-NLS-1$
ElementSymbol e1 = new ElementSymbol("e1");
SubqueryCompareCriteria crit = new SubqueryCompareCriteria(e1, new Query(), operator, predicateQuantifier);
return crit;
}
Aggregations