Author: shawkins
Date: 2012-08-27 16:14:33 -0400 (Mon, 27 Aug 2012)
New Revision: 4369
Added:
trunk/engine/src/test/java/org/teiid/query/processor/TestObjectTable.java
Removed:
trunk/admin/src/main/java/org/teiid/adminapi/impl/PermissionMap.java
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/DataPolicy.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
trunk/admin/src/test/java/org/teiid/adminapi/impl/TestDataPolicyMetaData.java
trunk/client/src/main/resources/vdb-deployer.xsd
trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java
trunk/engine/src/main/java/org/teiid/query/util/Options.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
Log:
TEIID-2141 TEIID-2164 rounding out objecttable with authorization and fixing permissionmap
by turning permissions into bit masked values
Modified: trunk/admin/src/main/java/org/teiid/adminapi/DataPolicy.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/DataPolicy.java 2012-08-27 17:50:17 UTC
(rev 4368)
+++ trunk/admin/src/main/java/org/teiid/adminapi/DataPolicy.java 2012-08-27 20:14:33 UTC
(rev 4369)
@@ -37,8 +37,9 @@
STORED_PROCEDURE;
}
- public enum PermissionType {CREATE, READ, UPDATE, DELETE, ALTER, EXECUTE, DROP};
+ public enum PermissionType {CREATE, READ, UPDATE, DELETE, ALTER, EXECUTE, DROP,
LANGUAGE};
+
/**
* Get the Name of the Data Policy
* @return
@@ -116,6 +117,13 @@
* Is "EXECUTE" allowed?
* @return
*/
- Boolean getAllowExecute();
+ Boolean getAllowExecute();
+
+ /**
+ * Is "LANGUAGE" allowed?
+ * @return
+ */
+ Boolean getAllowLanguage();
+
}
}
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2012-08-27
17:50:17 UTC (rev 4368)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -23,7 +23,9 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import org.teiid.adminapi.DataPolicy;
@@ -37,7 +39,8 @@
protected boolean anyAuthenticated;
protected Boolean allowCreateTemporaryTables;
- protected PermissionMap permissions = new PermissionMap();
+ protected Map<String, PermissionMetaData> permissions = new HashMap<String,
PermissionMetaData>();
+ protected Map<String, PermissionMetaData> languagePermissions = new
HashMap<String, PermissionMetaData>(2);
protected List<String> mappedRoleNames = new
CopyOnWriteArrayList<String>();
@@ -61,21 +64,36 @@
@Override
public List<DataPermission> getPermissions() {
- return new ArrayList<DataPermission>(this.permissions.values());
+ List<DataPermission> result = new
ArrayList<DataPermission>(this.permissions.values());
+ result.addAll(this.languagePermissions.values());
+ return result;
}
public void setPermissions(List<DataPermission> permissions) {
this.permissions.clear();
for (DataPermission permission:permissions) {
- this.permissions.put(permission.getResourceName().toLowerCase(),
(PermissionMetaData)permission);
+ addPermission((PermissionMetaData)permission);
}
}
- public void addPermission(PermissionMetaData... permissions) {
- for (PermissionMetaData permission:permissions) {
- this.permissions.put(permission.getResourceName().toLowerCase(), permission);
+ public void addPermission(PermissionMetaData... perms) {
+ for (PermissionMetaData permission:perms) {
+ addPermission(permission);
}
}
+
+ private void addPermission(PermissionMetaData permission) {
+ PermissionMetaData previous = null;
+ if (permission.getAllowLanguage() != null) {
+ previous = this.languagePermissions.put(permission.getResourceName(), permission);
+ } else {
+ previous = permissions.put(permission.getResourceName().toLowerCase(), permission);
+ }
+ if (previous != null) {
+ permission.bits |= previous.bits;
+ permission.bitsSet |= previous.bitsSet;
+ }
+ }
@Override
public List<String> getMappedRoleNames() {
@@ -87,27 +105,25 @@
this.mappedRoleNames.addAll(names);
}
- public void addMappedRoleName(String name) {
- this.mappedRoleNames.add(name);
+ public void addMappedRoleName(String mappedName) {
+ this.mappedRoleNames.add(mappedName);
}
- public void removeMappedRoleName(String name) {
- this.mappedRoleNames.remove(name);
+ public void removeMappedRoleName(String mappedName) {
+ this.mappedRoleNames.remove(mappedName);
}
- public boolean allows(String resourceName, DataPolicy.PermissionType type) {
- resourceName = resourceName.toLowerCase();
- while (resourceName.length() > 0) {
- PermissionMetaData p = this.permissions.get(resourceName);
- if (p != null) {
- Boolean allowed = p.allows(type);
- if (allowed != null) {
- return allowed;
- }
- }
- resourceName = resourceName.substring(0, Math.max(0,
resourceName.lastIndexOf('.')));
+ public Boolean allows(String resourceName, DataPolicy.PermissionType type) {
+ PermissionMetaData p = null;
+ if (type == PermissionType.LANGUAGE) {
+ p = this.languagePermissions.get(resourceName);
+ } else {
+ p = this.permissions.get(resourceName);
}
- return false;
+ if (p != null) {
+ return p.allows(type);
+ }
+ return null;
}
public static class PermissionMetaData implements DataPermission, Serializable {
@@ -115,12 +131,8 @@
// XML based fields
private String resourceName;
- protected Boolean allowCreate;
- protected Boolean allowRead;
- protected Boolean allowUpdate;
- protected Boolean allowDelete;
- protected Boolean allowExecute;
- protected Boolean allowAlter;
+ protected byte bits;
+ protected byte bitsSet;
@Override
public String getResourceName() {
@@ -133,38 +145,62 @@
@Override
public Boolean getAllowCreate() {
- return allowCreate;
+ return bitSet(0x01);
}
+ private Boolean bitSet(int bitMask) {
+ if ((bitsSet & bitMask) == bitMask) {
+ if ((bits & bitMask) == bitMask) {
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+ return null;
+ }
+
+ private void setBit(int bitMask, Boolean bool) {
+ if (bool == null) {
+ bitsSet &= (~bitMask);
+ bits &= (~bitMask);
+ return;
+ }
+ bitsSet |= bitMask;
+ if (bool) {
+ bits |= bitMask;
+ } else {
+ bits &= (~bitMask);
+ }
+ }
+
public void setAllowCreate(Boolean value) {
- this.allowCreate = value;
+ setBit(0x01, value);
}
@Override
public Boolean getAllowRead() {
- return allowRead;
+ return bitSet(0x02);
}
public void setAllowRead(Boolean value) {
- this.allowRead = value;
+ setBit(0x02, value);
}
@Override
public Boolean getAllowUpdate() {
- return allowUpdate;
+ return bitSet(0x04);
}
public void setAllowUpdate(Boolean value) {
- this.allowUpdate = value;
+ setBit(0x04, value);
}
@Override
public Boolean getAllowDelete() {
- return allowDelete;
+ return bitSet(0x08);
}
public void setAllowDelete(Boolean value) {
- this.allowDelete = value;
+ setBit(0x08, value);
}
public String getType() {
@@ -187,6 +223,9 @@
if (Boolean.TRUE.equals(getAllowAlter())) {
sb.append("A");//$NON-NLS-1$
}
+ if (Boolean.TRUE.equals(getAllowLanguage())) {
+ sb.append("L");//$NON-NLS-1$
+ }
return sb.toString();
}
@@ -206,27 +245,38 @@
return getAllowUpdate();
case DELETE:
return getAllowDelete();
- }
+ case LANGUAGE:
+ return getAllowLanguage();
+ }
throw new AssertionError();
}
@Override
public Boolean getAllowAlter() {
- return allowAlter;
+ return bitSet(0x10);
}
@Override
public Boolean getAllowExecute() {
- return allowExecute;
+ return bitSet(0x20);
}
public void setAllowAlter(Boolean allowAlter) {
- this.allowAlter = allowAlter;
+ setBit(0x10, allowAlter);
}
public void setAllowExecute(Boolean allowExecute) {
- this.allowExecute = allowExecute;
+ setBit(0x20, allowExecute);
}
+
+ @Override
+ public Boolean getAllowLanguage() {
+ return bitSet(0x40);
+ }
+
+ public void setAllowLanguage(Boolean value) {
+ setBit(0x40, value);
+ }
public String toString() {
StringBuilder sb = new StringBuilder();
Deleted: trunk/admin/src/main/java/org/teiid/adminapi/impl/PermissionMap.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/PermissionMap.java 2012-08-27
17:50:17 UTC (rev 4368)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/PermissionMap.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright (C) 2008 Red Hat, Inc.
- * Licensed to Red Hat, Inc. under one or more contributor
- * license agreements. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.adminapi.impl;
-
-import java.util.LinkedHashMap;
-
-import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
-
-public class PermissionMap extends LinkedHashMap<String, PermissionMetaData> {
-
- private static final long serialVersionUID = -1170556665834875267L;
-
- @Override
- public PermissionMetaData put(String key, PermissionMetaData element) {
- PermissionMetaData previous = get(element.getResourceName().toLowerCase());
- if (previous != null) {
- if (element.allowCreate != null) {
- previous.setAllowCreate(element.allowCreate);
- }
- if (element.allowRead != null) {
- previous.setAllowRead(element.allowRead);
- }
- if (element.allowUpdate != null) {
- previous.setAllowUpdate(element.allowUpdate);
- }
- if (element.allowDelete != null) {
- previous.setAllowDelete(element.allowDelete);
- }
- return previous;
- }
- return super.put(element.getResourceName().toLowerCase(), element);
- }
-}
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-08-27
17:50:17 UTC (rev 4368)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -214,6 +214,9 @@
case ALLOW_CREATE:
permission.setAllowCreate(Boolean.parseBoolean(reader.getElementText()));
break;
+ case ALLOW_LANGUAGE:
+ permission.setAllowLanguage(Boolean.parseBoolean(reader.getElementText()));
+ break;
case ALLOW_DELETE:
permission.setAllowDelete(Boolean.parseBoolean(reader.getElementText()));
break;
@@ -235,7 +238,7 @@
Element.ALLOW_DELETE.getLocalName(),
Element.ALLOW_EXECUTE.getLocalName(),
Element.ALLOW_READ.getLocalName(),
- Element.ALLOW_UPADTE), reader.getLocation());
+ Element.ALLOW_UPADTE, Element.ALLOW_LANGUAGE), reader.getLocation());
}
}
}
@@ -375,6 +378,7 @@
ALLOW_DELETE("allow-delete"),
ALLOW_EXECUTE("allow-execute"),
ALLOW_ALTER("allow-alter"),
+ ALLOW_LANGUAGE("allow-language"),
MAPPED_ROLE_NAME("mapped-role-name"),
ENTRY("entry"),
METADATA("metadata");
@@ -497,6 +501,9 @@
if (permission.getAllowAlter() != null) {
writeElement(writer, Element.ALLOW_ALTER, permission.getAllowAlter().toString());
}
+ if (permission.getAllowLanguage() != null) {
+ writeElement(writer, Element.ALLOW_LANGUAGE,
permission.getAllowCreate().toString());
+ }
writer.writeEndElement();
}
Modified: trunk/admin/src/test/java/org/teiid/adminapi/impl/TestDataPolicyMetaData.java
===================================================================
---
trunk/admin/src/test/java/org/teiid/adminapi/impl/TestDataPolicyMetaData.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/admin/src/test/java/org/teiid/adminapi/impl/TestDataPolicyMetaData.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -21,12 +21,13 @@
*/
package org.teiid.adminapi.impl;
+import static org.junit.Assert.*;
+
import java.util.Arrays;
import org.junit.Test;
import org.teiid.adminapi.DataPolicy.PermissionType;
import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
-import static junit.framework.Assert.*;
public class TestDataPolicyMetaData {
@@ -60,24 +61,22 @@
policy.addPermission(perm1, perm2, perm3, perm4, perm5);
+ assertTrue(policy.allows("catalog.schema.Table1".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
+ assertNull(policy.allows("catalog.schema.Table1".toLowerCase(),
PermissionType.CREATE)); //$NON-NLS-1$
- assertTrue(policy.allows("catalog.schema.Table1", PermissionType.READ));
//$NON-NLS-1$
- assertFalse(policy.allows("catalog.schema.Table1", PermissionType.CREATE));
//$NON-NLS-1$
+ assertNull(policy.allows("catalog.schema", PermissionType.READ));
//$NON-NLS-1$
- assertFalse(policy.allows("catalog.schema", PermissionType.READ));
//$NON-NLS-1$
+ assertNull(policy.allows("catalog.schema.Table2.column".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
+ assertFalse(policy.allows("catalog.schema.Table2".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
- assertFalse(policy.allows("catalog.schema.Table2.column",
PermissionType.READ)); //$NON-NLS-1$
- assertFalse(policy.allows("catalog.schema.Table2", PermissionType.READ));
//$NON-NLS-1$
+ assertNull(policy.allows("catalog.schema.Table3.column".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
+ assertTrue(policy.allows("catalog.schema.Table3".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
- assertTrue(policy.allows("catalog.schema.Table3.column",
PermissionType.READ)); //$NON-NLS-1$
- assertTrue(policy.allows("catalog.schema.Table3", PermissionType.READ));
//$NON-NLS-1$
+ assertTrue(policy.allows("catalog.schema.Table4".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
+ assertNull(policy.allows("catalog.schema.Table4".toLowerCase(),
PermissionType.DELETE)); //$NON-NLS-1$
- assertTrue(policy.allows("catalog.schema.Table4.column",
PermissionType.READ)); //$NON-NLS-1$
- assertTrue(policy.allows("catalog.schema.Table4", PermissionType.READ));
//$NON-NLS-1$
- assertFalse(policy.allows("catalog.schema.Table4", PermissionType.DELETE));
//$NON-NLS-1$
-
- assertTrue(policy.allows("catalog.schema.Table5.column1",
PermissionType.READ)); //$NON-NLS-1$
- assertFalse(policy.allows("catalog.schema.Table5.column2",
PermissionType.READ)); //$NON-NLS-1$
- assertFalse(policy.allows("catalog.schema.Table5", PermissionType.READ));
//$NON-NLS-1$
+ assertTrue(policy.allows("catalog.schema.Table5.column1".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
+ assertNull(policy.allows("catalog.schema.Table5.column2".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
+ assertNull(policy.allows("catalog.schema.Table5".toLowerCase(),
PermissionType.READ)); //$NON-NLS-1$
}
}
Modified: trunk/client/src/main/resources/vdb-deployer.xsd
===================================================================
--- trunk/client/src/main/resources/vdb-deployer.xsd 2012-08-27 17:50:17 UTC (rev 4368)
+++ trunk/client/src/main/resources/vdb-deployer.xsd 2012-08-27 20:14:33 UTC (rev 4369)
@@ -118,12 +118,17 @@
<xs:complexType>
<xs:sequence>
<xs:element name="resource-name"
type="xs:string"/>
- <xs:element name="allow-create"
type="xs:boolean" minOccurs="0"/>
- <xs:element name="allow-read"
type="xs:boolean" minOccurs="0"/>
- <xs:element name="allow-update"
type="xs:boolean" minOccurs="0"/>
- <xs:element name="allow-delete"
type="xs:boolean" minOccurs="0"/>
- <xs:element name="allow-execute"
type="xs:boolean" minOccurs="0"/>
- <xs:element name="allow-alter"
type="xs:boolean" minOccurs="0"/>
+ <xs:choice>
+ <xs:sequence>
+ <xs:element
name="allow-create" type="xs:boolean" minOccurs="0"/>
+ <xs:element name="allow-read"
type="xs:boolean" minOccurs="0"/>
+ <xs:element name="allow-update"
type="xs:boolean" minOccurs="0"/>
+ <xs:element name="allow-delete"
type="xs:boolean" minOccurs="0"/>
+ <xs:element name="allow-execute"
type="xs:boolean" minOccurs="0"/>
+ <xs:element name="allow-alter"
type="xs:boolean" minOccurs="0"/>
+ </xs:sequence>
+ <xs:element name="allow-language" type="xs:boolean"
minOccurs="0"/>
+ </xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
Modified: trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2012-08-27
17:50:17 UTC (rev 4368)
+++ trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -20,14 +20,7 @@
import java.lang.reflect.Array;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
+import java.util.*;
import java.util.regex.Pattern;
import org.teiid.core.CorePlugin;
@@ -974,6 +967,9 @@
else if (type.isAssignableFrom(List.class)) {
return (T)new ArrayList<String>(Arrays.asList(value.split(",")));
//$NON-NLS-1$
}
+ else if (type.isAssignableFrom(Set.class)) {
+ return (T)new HashSet<String>(Arrays.asList(value.split(",")));
//$NON-NLS-1$
+ }
else if (type.isArray()) {
String[] values = value.split(","); //$NON-NLS-1$
Object array = Array.newInstance(type.getComponentType(), values.length);
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -84,6 +84,17 @@
public void visit(AlterView obj) {
validateEntitlements(Arrays.asList(obj.getTarget()),
DataPolicy.PermissionType.ALTER, Context.ALTER);
}
+
+ @Override
+ public void visit(ObjectTable objectTable) {
+ String language = ObjectTable.DEFAULT_LANGUAGE;
+ if (objectTable.getScriptingLanguage() != null) {
+ language = objectTable.getScriptingLanguage();
+ }
+ Map<String, LanguageObject> map = new HashMap<String,
LanguageObject>();
+ map.put(language, objectTable);
+ validateEntitlements(PermissionType.LANGUAGE, Context.QUERY, map);
+ }
private void validateTemp(DataPolicy.PermissionType action, GroupSymbol symbol, Context
context) {
String resource = symbol.getNonCorrelationName();
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -22,9 +22,10 @@
package org.teiid.dqp.internal.process;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
import org.teiid.CommandContext;
@@ -45,22 +46,33 @@
if (action == PermissionType.EXECUTE && context == Context.FUNCTION &&
allowFunctionCallsByDefault) {
return Collections.emptySet();
}
- LinkedHashSet<String> results = new LinkedHashSet<String>(resources);
- for(DataPolicy p:commandContext.getAllowedDataPolicies().values()) {
- DataPolicyMetadata policy = (DataPolicyMetadata)p;
-
- if (results.isEmpty()) {
- break;
+ List<DataPolicy> policies = new
ArrayList<DataPolicy>(commandContext.getAllowedDataPolicies().values());
+ int policyCount = policies.size();
+ outer:for (Iterator<String> iter = resources.iterator(); iter.hasNext();) {
+ String resource = iter.next();
+ if (action != PermissionType.LANGUAGE) {
+ resource = resource.toLowerCase();
}
-
- Iterator<String> i = results.iterator();
- while (i.hasNext()) {
- if (policy.allows(i.next(), action)) {
- i.remove();
+ while (resource.length() > 0) {
+ boolean isFalse = false;
+ for (int j = 0; j < policyCount; j++) {
+ DataPolicyMetadata policy = (DataPolicyMetadata)policies.get(j);
+ Boolean allows = policy.allows(resource, action);
+ if (allows != null) {
+ if (allows) {
+ iter.remove();
+ continue outer;
+ }
+ isFalse = true;
+ }
}
+ if (isFalse || action == PermissionType.LANGUAGE) {
+ break; //don't check less specific permissions
+ }
+ resource = resource.substring(0, Math.max(0, resource.lastIndexOf('.')));
}
}
- return results;
+ return resources;
}
@Override
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -28,6 +28,7 @@
import java.io.Serializable;
import java.util.*;
+import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
@@ -75,6 +76,8 @@
*/
public class TransformationMetadata extends BasicQueryMetadata implements Serializable {
+ public static final String ALLOWED_LANGUAGES = "allowed-languages";
//$NON-NLS-1$
+
private static final class LiveQueryNode extends QueryNode {
Procedure p;
private LiveQueryNode(Procedure p) {
@@ -158,7 +161,9 @@
private FunctionLibrary functionLibrary;
private VDBMetaData vdbMetaData;
private ScriptEngineManager scriptEngineManager;
+ private Map<String, ScriptEngineFactory> scriptEngineFactories =
Collections.synchronizedMap(new HashMap<String, ScriptEngineFactory>());
private Set<String> importedModels;
+ private Set<String> allowedLanguages;
/*
* TODO: move caching to jboss cache structure
@@ -177,6 +182,10 @@
if (this.vdbMetaData !=null) {
this.scriptEngineManager = vdbMetadata.getAttachment(ScriptEngineManager.class);
this.importedModels = this.vdbMetaData.getImportedModels();
+ this.allowedLanguages =
StringUtil.valueOf(vdbMetadata.getPropertyValue(ALLOWED_LANGUAGES), Set.class);
+ if (this.allowedLanguages == null) {
+ this.allowedLanguages = Collections.emptySet();
+ }
} else {
this.importedModels = Collections.emptySet();
}
@@ -1096,6 +1105,7 @@
tm.procedureCache = this.procedureCache;
tm.scriptEngineManager = this.scriptEngineManager;
tm.importedModels = this.importedModels;
+ tm.allowedLanguages = this.allowedLanguages;
return tm;
}
@@ -1112,18 +1122,34 @@
if (language == null) {
language = ObjectTable.DEFAULT_LANGUAGE;
}
- /*
- * because of state caching in the engine, we'll return a new instance for each
- * usage. we can pool if needed and add a returnEngine method
- */
- ScriptEngine engine = this.scriptEngineManager.getEngineByName(language);
+ ScriptEngine engine = null;
+ if (allowedLanguages == null || allowedLanguages.contains(language)) {
+ /*
+ * because of state caching in the engine, we'll return a new instance for each
+ * usage. we can pool if needed and add a returnEngine method
+ */
+ ScriptEngineFactory sef = this.scriptEngineFactories.get(language);
+ if (sef != null) {
+ try {
+ engine = sef.getScriptEngine();
+ engine.setBindings(scriptEngineManager.getBindings(), ScriptContext.ENGINE_SCOPE);
+ } catch (Exception e) {
+ //just swallow the exception to mimic the jsr behavior
+ }
+ }
+ engine = this.scriptEngineManager.getEngineByName(language);
+ }
if (engine == null) {
Set<String> names = new LinkedHashSet<String>();
for (ScriptEngineFactory factory : this.scriptEngineManager.getEngineFactories()) {
names.addAll(factory.getNames());
}
+ if (allowedLanguages != null) {
+ names.retainAll(allowedLanguages);
+ }
throw new TeiidProcessingException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31109,
language, names));
}
+ this.scriptEngineFactories.put(language, engine.getFactory());
return engine;
}
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -51,7 +51,7 @@
*/
public class ObjectTableNode extends SubqueryAwareRelationalNode {
- private static final String TEIID_ROW_COUNT = "teiid_rowcount"; //$NON-NLS-1$
+ private static final String TEIID_ROWN_NUMBER = "teiid_row_number";
//$NON-NLS-1$
private static final String TEIID_ROW = "teiid_row"; //$NON-NLS-1$
private static final String TEIID_CONTEXT = "teiid_context"; //$NON-NLS-1$
@@ -168,7 +168,7 @@
TeiidComponentException, TeiidProcessingException {
List<Object> tuple = new ArrayList<Object>(projectedColumns.size());
this.scriptContext.setAttribute(TEIID_ROW, this.item, ScriptContext.ENGINE_SCOPE);
- this.scriptContext.setAttribute(TEIID_ROW_COUNT, this.rowCount,
ScriptContext.ENGINE_SCOPE);
+ this.scriptContext.setAttribute(TEIID_ROWN_NUMBER, this.rowCount,
ScriptContext.ENGINE_SCOPE);
for (ObjectColumn proColumn : projectedColumns) {
Object value = evalScript(proColumn.getCompiledScript(), proColumn.getPath());
if (value == null) {
Modified: trunk/engine/src/main/java/org/teiid/query/util/Options.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/util/Options.java 2012-08-27 17:50:17 UTC
(rev 4368)
+++ trunk/engine/src/main/java/org/teiid/query/util/Options.java 2012-08-27 20:14:33 UTC
(rev 4369)
@@ -23,6 +23,7 @@
package org.teiid.query.util;
import java.util.Properties;
+import java.util.Set;
/**
* A holder for options
@@ -30,8 +31,10 @@
public class Options {
public static final String UNNEST_DEFAULT = "org.teiid.subqueryUnnestDefault";
//$NON-NLS-1$
+ public static final String LANGUAGES_DEFAULT =
"org.teiid.languagesWithoutDataRoles"; //$NON-NLS-1$
private Properties properties;
+ private Set<String> languages;
private boolean subqueryUnnestDefault;
public Properties getProperties() {
@@ -42,6 +45,14 @@
this.properties = properties;
}
+ public void setLanguages(Set<String> languages) {
+ this.languages = languages;
+ }
+
+ public Set<String> getLanguages() {
+ return languages;
+ }
+
public boolean isSubqueryUnnestDefault() {
return subqueryUnnestDefault;
}
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-08-27 17:50:17
UTC (rev 4368)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-08-27 20:14:33
UTC (rev 4369)
@@ -2636,7 +2636,7 @@
/*
name=object table column
description=object table column.
-example={code:sql}y integer 'teiid_rowcount'{code}
+example={code:sql}y integer 'teiid_row_number'{code}
*/
ObjectTable.ObjectColumn objectColumn(ParseInfo info):
{
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-08-27 17:50:17
UTC (rev 4368)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-08-27 20:14:33
UTC (rev 4369)
@@ -1024,8 +1024,8 @@
TEIID31105=Returing warning to client: {0}
TEIID31106=Duplicate parameter {1} defined on {0}
TEIID31107=Procedure {0} can only have 1 RESULT/return value
-TEIID31109=Invalid language {0}. Supported language names are {1}.
-TEIID31109=Invalid script {0}. Scrpting engine reported: {1}.
+TEIID31109=Invalid language {0}. Supported and allowed language names are {1}.
+TEIID31110=Invalid script {0}. Scrpting engine reported: {1}.
SQLParser.proc_type_conflict=Result type {1} conflicts with return type {2} for procedure
{0}
SQLParser.param_out=Procedure {0} RESULT param {1} must be of type OUT.
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -30,6 +30,7 @@
import java.util.Set;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.adminapi.DataPolicy;
import org.teiid.adminapi.DataPolicy.PermissionType;
@@ -57,14 +58,21 @@
public static final String CONN_ID = "connID"; //$NON-NLS-1$
private CommandContext context;
+ private static DataPolicyMetadata exampleAuthSvc1;
+ private static DataPolicyMetadata exampleAuthSvc2;
@Before public void setup() {
context = new CommandContext();
context.setSession(new SessionMetadata());
context.setDQPWorkContext(new DQPWorkContext());
}
+
+ @BeforeClass static public void oneTimeSetup() {
+ exampleAuthSvc1 = exampleAuthSvc1();
+ exampleAuthSvc2 = exampleAuthSvc2();
+ }
- PermissionMetaData addResource(PermissionType type, boolean flag, String resource) {
+ static PermissionMetaData addResource(PermissionType type, boolean flag, String
resource) {
PermissionMetaData p = new PermissionMetaData();
p.setResourceName(resource);
switch(type) {
@@ -86,14 +94,16 @@
case EXECUTE:
p.setAllowExecute(flag);
break;
+ case LANGUAGE:
+ p.setAllowLanguage(flag);
}
return p;
}
- PermissionMetaData addResource(PermissionType type, String resource) {
+ static PermissionMetaData addResource(PermissionType type, String resource) {
return addResource(type, true, resource);
}
- private DataPolicyMetadata exampleAuthSvc1() {
+ private static DataPolicyMetadata exampleAuthSvc1() {
DataPolicyMetadata svc = new DataPolicyMetadata();
svc.setName("test"); //$NON-NLS-1$
@@ -143,7 +153,7 @@
}
//allow by default
- private DataPolicyMetadata exampleAuthSvc2() {
+ private static DataPolicyMetadata exampleAuthSvc2() {
DataPolicyMetadata svc = new DataPolicyMetadata();
svc.setName("test"); //$NON-NLS-1$
@@ -208,137 +218,144 @@
}
@Test public void testProcRelational() throws Exception {
- helpTest("select * from sp1", RealMetadataFactory.example1Cached(), new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
- helpTest("select * from pm1.sp1", RealMetadataFactory.example1Cached(),
new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
- helpTest("select * from sp1", RealMetadataFactory.example1Cached(), new
String[] {"sp1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2());
//$NON-NLS-1$
+ helpTest("select * from sp1", RealMetadataFactory.example1Cached(), new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
+ helpTest("select * from pm1.sp1", RealMetadataFactory.example1Cached(),
new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
+ helpTest("select * from sp1", RealMetadataFactory.example1Cached(), new
String[] {"sp1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2);
//$NON-NLS-1$
}
@Test public void testTemp() throws Exception {
//allowed by default
- helpTest("create local temporary table x (y string)",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("create local temporary table x (y string)",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1); //$NON-NLS-1$
//explicitly denied
- helpTest("create local temporary table x (y string)",
RealMetadataFactory.example1Cached(), new String[] {"x"},
RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$
+ helpTest("create local temporary table x (y string)",
RealMetadataFactory.example1Cached(), new String[] {"x"},
RealMetadataFactory.example1VDB(), exampleAuthSvc2); //$NON-NLS-1$
}
@Test public void testFunction() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
- helpTest("SELECT e1 FROM pm1.g1 where xyz() > 0", metadata, new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
- helpTest("SELECT e1, curdate() FROM pm1.g2 where xyz() > 0",
metadata, new String[] {"xyz()"}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2()); //$NON-NLS-1$
+ helpTest("SELECT e1 FROM pm1.g1 where xyz() > 0", metadata, new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
+ helpTest("SELECT e1, curdate() FROM pm1.g2 where xyz() > 0",
metadata, new String[] {"xyz()"}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2); //$NON-NLS-1$
}
@Test public void testEverythingAccessible() throws Exception {
- helpTest("SELECT e1 FROM pm1.g1", RealMetadataFactory.example1Cached(),
new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("SELECT e1 FROM pm1.g1", RealMetadataFactory.example1Cached(),
new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testEverythingAccessible1() throws Exception {
- helpTest("SELECT e1 FROM (select e1 from pm1.g1) x",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("SELECT e1 FROM (select e1 from pm1.g1) x",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testEverythingAccessible2() throws Exception {
- helpTest("SELECT lookup('pm1.g1', 'e1', 'e1',
'1'), e1 FROM (select e1 from pm1.g1) x",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("SELECT lookup('pm1.g1', 'e1', 'e1',
'1'), e1 FROM (select e1 from pm1.g1) x",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testInaccesibleElement() throws Exception {
- helpTest("SELECT e2 FROM pm1.g1", RealMetadataFactory.example1Cached(),
new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("SELECT e2 FROM pm1.g1", RealMetadataFactory.example1Cached(),
new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1);
//$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testInaccesibleElement2() throws Exception {
- helpTest("SELECT lookup('pm1.g1', 'e1', 'e2',
'1')", RealMetadataFactory.example1Cached(), new String[]
{"pm1.g1.e2"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1());
//$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("SELECT lookup('pm1.g1', 'e1', 'e2',
'1')", RealMetadataFactory.example1Cached(), new String[]
{"pm1.g1.e2"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1);
//$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testInaccesibleGroup() throws Exception {
- helpTest("SELECT e1 FROM pm1.g2", RealMetadataFactory.example1Cached(),
new String[] {"pm1.g2", "pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ helpTest("SELECT e1 FROM pm1.g2", RealMetadataFactory.example1Cached(),
new String[] {"pm1.g2", "pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
}
@Test public void testInsert() throws Exception {
- helpTest("INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES ('x', 5,
{b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[] {},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES ('x', 5,
{b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[] {},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testInsertInaccessible() throws Exception {
- helpTest("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('x', 5,
{b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[]
{"pm1.g2.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1());
//$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('x', 5,
{b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[]
{"pm1.g2.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1);
//$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testUpdate() throws Exception {
- helpTest("UPDATE pm1.g1 SET e2 = 5",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("UPDATE pm1.g1 SET e2 = 5",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testUpdateCriteriaInaccessibleForRead() throws Exception {
- helpTest("UPDATE pm1.g2 SET e2 = 5 WHERE e1 = 'x'",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("UPDATE pm1.g2 SET e2 = 5 WHERE e1 = 'x'",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testUpdateCriteriaInaccessibleForRead1() throws Exception {
- helpTest("UPDATE pm1.g2 SET e2 = cast(e1 as integer)",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("UPDATE pm1.g2 SET e2 = cast(e1 as integer)",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testUpdateElementInaccessibleForUpdate() throws Exception {
- helpTest("UPDATE pm1.g1 SET e1 = 5 WHERE e1 = 'x'",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("UPDATE pm1.g1 SET e1 = 5 WHERE e1 = 'x'",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testDelete() throws Exception {
- helpTest("DELETE FROM pm1.g1", RealMetadataFactory.example1Cached(),
new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("DELETE FROM pm1.g1", RealMetadataFactory.example1Cached(),
new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testDeleteCriteriaInaccesibleForRead() throws Exception {
- helpTest("DELETE FROM pm1.g2 WHERE e1 = 'x'",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("DELETE FROM pm1.g2 WHERE e1 = 'x'",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testDeleteInaccesibleGroup() throws Exception {
- helpTest("DELETE FROM pm1.g3", RealMetadataFactory.example1Cached(),
new String[] {"pm1.g3"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1());
//$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("DELETE FROM pm1.g3", RealMetadataFactory.example1Cached(),
new String[] {"pm1.g3"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1);
//$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testProc() throws Exception {
- helpTest("EXEC pm1.sq1()", RealMetadataFactory.example1Cached(), new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("EXEC pm1.sq1()", RealMetadataFactory.example1Cached(), new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testProcInaccesible() throws Exception {
- helpTest("EXEC pm1.sq2('xyz')",
RealMetadataFactory.example1Cached(), new String[] {"pm1.sq2"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
//$NON-NLS-2$
+ helpTest("EXEC pm1.sq2('xyz')",
RealMetadataFactory.example1Cached(), new String[] {"pm1.sq2"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testSelectIntoEverythingAccessible() throws Exception {
- helpTest("SELECT e1, e2, e3, e4 INTO pm1.g2 FROM pm2.g1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2()); //$NON-NLS-1$
+ helpTest("SELECT e1, e2, e3, e4 INTO pm1.g2 FROM pm2.g1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2); //$NON-NLS-1$
}
@Test public void testSelectIntoTarget_e1_NotAccessible() throws Exception {
- helpTest("SELECT e1, e2, e3, e4 INTO pm2.g2 FROM pm2.g1",
RealMetadataFactory.example1Cached(), new String[] {"pm2.g2",
"pm2.g2.e2","pm2.g2.e4","pm2.g2.e3"},
RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
+ helpTest("SELECT e1, e2, e3, e4 INTO pm2.g2 FROM pm2.g1",
RealMetadataFactory.example1Cached(), new String[] {"pm2.g2",
"pm2.g2.e2","pm2.g2.e4","pm2.g2.e3"},
RealMetadataFactory.example1VDB(), exampleAuthSvc2); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
}
@Test public void testSelectIntoTarget_e1e2_NotAccessible() throws Exception {
- helpTest("SELECT e1, e2, e3, e4 INTO pm3.g2 FROM pm2.g1",
RealMetadataFactory.example1Cached(), new String[] {"pm3.g2",
"pm3.g2.e4", "pm3.g2.e3"},
RealMetadataFactory.example1VDB(),exampleAuthSvc2()); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ helpTest("SELECT e1, e2, e3, e4 INTO pm3.g2 FROM pm2.g1",
RealMetadataFactory.example1Cached(), new String[] {"pm3.g2",
"pm3.g2.e4", "pm3.g2.e3"},
RealMetadataFactory.example1VDB(),exampleAuthSvc2); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
}
@Test public void testTempTableSelectInto() throws Exception {
- helpTest("SELECT e1 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1()); //$NON-NLS-1$
- helpTest("SELECT e1 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {"#temp"},
RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$
- helpTest("SELECT e1 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2(), exampleAuthSvc1()); //$NON-NLS-1$
+ helpTest("SELECT e1 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc1); //$NON-NLS-1$
+ helpTest("SELECT e1 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {"#temp"},
RealMetadataFactory.example1VDB(), exampleAuthSvc2); //$NON-NLS-1$
+ helpTest("SELECT e1 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2, exampleAuthSvc1); //$NON-NLS-1$
}
@Test public void testCommonTable() throws Exception {
- helpTest("WITH X AS (SELECT e1 from pm1.g2) SELECT e1 from x",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2()); //$NON-NLS-1$
+ helpTest("WITH X AS (SELECT e1 from pm1.g2) SELECT e1 from x",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2); //$NON-NLS-1$
}
@Test public void testTempTableSelectInto1() throws Exception {
- helpTest("SELECT e1, e2 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("SELECT e1, e2 INTO #temp FROM pm1.g1",
RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testTempTableInsert() throws Exception {
- helpTest("insert into #temp (e1, e2, e3, e4) values ('1',
'2', '3', '4')", RealMetadataFactory.example1Cached(), new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
- helpTest("insert into #temp (e1, e2, e3, e4) values ('1',
'2', '3', '4')", RealMetadataFactory.example1Cached(), new
String[] {"#temp"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2());
//$NON-NLS-1$
+ helpTest("insert into #temp (e1, e2, e3, e4) values ('1',
'2', '3', '4')", RealMetadataFactory.example1Cached(), new
String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$
+ helpTest("insert into #temp (e1, e2, e3, e4) values ('1',
'2', '3', '4')", RealMetadataFactory.example1Cached(), new
String[] {"#temp"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2);
//$NON-NLS-1$
}
@Test public void testXMLAccessible() throws Exception {
- helpTest("select * from xmltest.doc1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("select * from xmltest.doc1",
RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(),
exampleAuthSvc2); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testXMLInAccessible() throws Exception {
- helpTest("select * from xmltest.doc1",
RealMetadataFactory.example1Cached(), new String[] {"xmltest.doc1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("select * from xmltest.doc1",
RealMetadataFactory.example1Cached(), new String[] {"xmltest.doc1"},
RealMetadataFactory.example1VDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testAlter() throws Exception {
- helpTest("alter view SmallA_2589 as select * from bqt1.smalla",
RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"},
RealMetadataFactory.exampleBQTVDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("alter view SmallA_2589 as select * from bqt1.smalla",
RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"},
RealMetadataFactory.exampleBQTVDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
helpTest("alter view SmallA_2589 as select * from bqt1.smalla",
RealMetadataFactory.exampleBQTCached(), new String[] {},
RealMetadataFactory.exampleBQTVDB(), examplePolicyBQT()); //$NON-NLS-1$ //$NON-NLS-2$
- helpTest("alter trigger on SmallA_2589 INSTEAD OF UPDATE enabled",
RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"},
RealMetadataFactory.exampleBQTVDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest("alter trigger on SmallA_2589 INSTEAD OF UPDATE enabled",
RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"},
RealMetadataFactory.exampleBQTVDB(), exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
helpTest("alter trigger on SmallA_2589 INSTEAD OF UPDATE enabled",
RealMetadataFactory.exampleBQTCached(), new String[] {},
RealMetadataFactory.exampleBQTVDB(), examplePolicyBQT()); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @Test public void testObjectTable() throws Exception {
+ helpTest("select * from objecttable(language 'javascript'
'teiid_context' columns x string 'teiid_row.userName') as x",
RealMetadataFactory.exampleBQTCached(), new String[] {"OBJECTTABLE(LANGUAGE
'javascript' 'teiid_context' COLUMNS x string
'teiid_row.userName') AS x"}, RealMetadataFactory.exampleBQTVDB(),
exampleAuthSvc1); //$NON-NLS-1$ //$NON-NLS-2$
+ DataPolicyMetadata policy = exampleAuthSvc1();
+ policy.addPermission(addResource(PermissionType.LANGUAGE, "javascript"));
+ helpTest("select * from objecttable(language 'javascript'
'teiid_context' columns x string 'teiid_row.userName') as x",
RealMetadataFactory.exampleBQTCached(), new String[] {},
RealMetadataFactory.exampleBQTVDB(), policy); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
}
Added: trunk/engine/src/test/java/org/teiid/query/processor/TestObjectTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestObjectTable.java
(rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestObjectTable.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.processor;
+
+import static org.teiid.query.processor.TestProcessor.*;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.teiid.query.metadata.TransformationMetadata;
+import org.teiid.query.sql.lang.ObjectTable;
+import org.teiid.query.unittest.RealMetadataFactory;
+
+@SuppressWarnings({"nls", "unchecked"})
+public class TestObjectTable {
+
+ @Test public void testIterator() throws Exception {
+ String sql = "select x.* from bqt1.smalla, objecttable('ov' passing
objectvalue as ov COLUMNS x string 'teiid_row', y integer
'teiid_row_number') x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List[] {
+ Arrays.asList("hello", 1),
+ Arrays.asList("world", 2),
+ Arrays.asList("x", 1),
+ Arrays.asList("y", 2),
+ };
+
+ process(sql, expected);
+ }
+
+ @Test public void testProjection() throws Exception {
+ String sql = "select y, z from bqt1.smalla, objecttable('ov' passing
objectvalue as ov COLUMNS x string 'teiid_row', y integer
'teiid_row_number', z integer 'teiid_row.length') x order by x.x desc
limit 1"; //$NON-NLS-1$
+
+ List<?>[] expected = new List[] {
+ Arrays.asList(2, 1),
+ };
+
+ process(sql, expected);
+ }
+
+ @Test public void testContext() throws Exception {
+ String sql = "select * from objecttable('teiid_context' COLUMNS y
string 'teiid_row.userName') as X"; //$NON-NLS-1$
+
+ List<?>[] expected = new List[] {
+ Arrays.asList("user"),
+ };
+
+ process(sql, expected);
+ }
+
+ public static void process(String sql, List[] expectedResults) throws Exception {
+ HardcodedDataManager dataManager = new HardcodedDataManager();
+ dataManager.addData("SELECT BQT1.SmallA.ObjectValue FROM BQT1.SmallA", new
List[] {Collections.singletonList(Arrays.asList("hello", "world")),
Collections.singletonList(Arrays.asList("x", null, "y")),
Collections.singletonList(null)} );
+ Properties p = new Properties();
+ p.put(TransformationMetadata.ALLOWED_LANGUAGES, ObjectTable.DEFAULT_LANGUAGE);
+ TransformationMetadata metadata =
RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.exampleBQTCached().getMetadataStore(),
"bqt", p);
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata);
+ helpProcess(plan, createCommandContext(), dataManager, expectedResults);
+ }
+
+}
Property changes on:
trunk/engine/src/test/java/org/teiid/query/processor/TestObjectTable.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import org.teiid.adminapi.Model;
import org.teiid.adminapi.impl.ModelMetaData;
@@ -322,10 +323,17 @@
}
public static TransformationMetadata createTransformationMetadata(MetadataStore
metadataStore, String vdbName, FunctionTree... functionModels) {
+ return createTransformationMetadata(metadataStore, vdbName, null, functionModels);
+ }
+
+ public static TransformationMetadata createTransformationMetadata(MetadataStore
metadataStore, String vdbName, Properties vdbProperties, FunctionTree... functionModels)
{
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
VDBMetaData vdbMetaData = new VDBMetaData();
vdbMetaData.setName(vdbName); //$NON-NLS-1$
vdbMetaData.setVersion(1);
+ if (vdbProperties != null) {
+ vdbMetaData.setProperties(vdbProperties);
+ }
List<FunctionTree> udfs = new ArrayList<FunctionTree>();
udfs.addAll(Arrays.asList(functionModels));
for (Schema schema : metadataStore.getSchemas().values()) {
Modified:
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2012-08-27
17:50:17 UTC (rev 4368)
+++
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2012-08-27
20:14:33 UTC (rev 4369)
@@ -225,7 +225,11 @@
}
@Test public void testUseInDifferentThreads() throws Throwable {
- assertTrue(server.getDqp().getRequests().isEmpty());
+ for (int i = 0; !server.getDqp().getRequests().isEmpty() && i < 40; i++) {
+ //the previous test may not have cleaned up
+ Thread.sleep(50);
+ }
+ int count = server.getDqp().getRequests().size();
Connection c = server.createConnection("jdbc:teiid:PartsSupplier");
final Statement s = c.createStatement();
@@ -252,11 +256,11 @@
if (handler.t != null) {
throw handler.t;
}
- for (int i = 0; !server.getDqp().getRequests().isEmpty() && i < 40; i++)
{
+ for (int i = 0; server.getDqp().getRequests().size() != count && i < 40;
i++) {
//the concurrent modification may not be seen initially
Thread.sleep(50);
}
- assertTrue(server.getDqp().getRequests().isEmpty());
+ assertEquals(count, server.getDqp().getRequests().size());
}
@Test public void testWait() throws Throwable {