Search in sources :

Example 1 with PermissionMetaData

use of org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData in project teiid by teiid.

the class TestDataPolicyMetaData method testAllowed.

@Test
public void testAllowed() {
    DataPolicyMetadata policy = new DataPolicyMetadata();
    // $NON-NLS-1$
    policy.setName("readOnly");
    // $NON-NLS-1$
    policy.setDescription("Only has read only permissions");
    // $NON-NLS-1$ //$NON-NLS-2$
    policy.setMappedRoleNames(Arrays.asList("jack", "susan"));
    PermissionMetaData perm1 = new PermissionMetaData();
    // $NON-NLS-1$
    perm1.setResourceName("catalog.schema.Table1");
    perm1.setAllowRead(true);
    PermissionMetaData perm2 = new PermissionMetaData();
    // $NON-NLS-1$
    perm2.setResourceName("catalog.schema.Table2");
    perm2.setAllowRead(false);
    PermissionMetaData perm3 = new PermissionMetaData();
    // $NON-NLS-1$
    perm3.setResourceName("catalog.schema.Table3");
    perm3.setAllowRead(true);
    PermissionMetaData perm4 = new PermissionMetaData();
    // $NON-NLS-1$
    perm4.setResourceName("catalog.schema.Table4");
    perm4.setAllowRead(true);
    PermissionMetaData perm5 = new PermissionMetaData();
    // $NON-NLS-1$
    perm5.setResourceName("catalog.schema.Table5.column1");
    perm5.setAllowRead(true);
    policy.addPermission(perm1, perm2, perm3, perm4, perm5);
    // $NON-NLS-1$
    assertTrue(policy.allows("catalog.schema.Table1".toLowerCase(), PermissionType.READ));
    // $NON-NLS-1$
    assertNull(policy.allows("catalog.schema.Table1".toLowerCase(), PermissionType.CREATE));
    // $NON-NLS-1$
    assertNull(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$
    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.Table4".toLowerCase(), PermissionType.READ));
    // $NON-NLS-1$
    assertNull(policy.allows("catalog.schema.Table4".toLowerCase(), PermissionType.DELETE));
    // $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));
}
Also used : PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 2 with PermissionMetaData

use of org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData in project teiid by teiid.

the class TestVDBUtility method buildVDB.

public static VDBMetaData buildVDB() {
    VDBMetaData vdb = new VDBMetaData();
    // $NON-NLS-1$
    vdb.setName("myVDB");
    // $NON-NLS-1$
    vdb.setDescription("vdb description");
    vdb.setConnectionType("NONE");
    vdb.setVersion(1);
    // $NON-NLS-1$ //$NON-NLS-2$
    vdb.addProperty("vdb-property", "vdb-value");
    // $NON-NLS-1$ //$NON-NLS-2$
    vdb.addProperty("vdb-property2", "vdb-value2");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("x");
    vdbImport.setVersion("2");
    vdb.getVDBImports().add(vdbImport);
    ModelMetaData modelOne = new ModelMetaData();
    // $NON-NLS-1$
    modelOne.setName("model-one");
    // $NON-NLS-1$ //$NON-NLS-2$
    modelOne.addSourceMapping("s1", "translator", "java:mybinding");
    // $NON-NLS-1$
    modelOne.setModelType(Model.Type.PHYSICAL);
    // $NON-NLS-1$ //$NON-NLS-2$
    modelOne.addProperty("model-prop", "model-value");
    // $NON-NLS-1$ //$NON-NLS-2$
    modelOne.addProperty("model-prop", "model-value-override");
    modelOne.setVisible(false);
    // $NON-NLS-1$ //$NON-NLS-2$
    modelOne.addMessage("ERROR", "There is an error in VDB");
    // $NON-NLS-1$ //$NON-NLS-2$
    modelOne.addMessage("INFO", "Nothing to see here");
    modelOne.setDescription("model description");
    modelOne.addSourceMetadata("DDL", "DDL Here");
    modelOne.addSourceMetadata("OTHER", "other text");
    vdb.addModel(modelOne);
    ModelMetaData modelTwo = new ModelMetaData();
    // $NON-NLS-1$
    modelTwo.setName("model-two");
    // $NON-NLS-1$ //$NON-NLS-2$
    modelTwo.addSourceMapping("s1", "translator", "java:binding-one");
    // $NON-NLS-1$ //$NON-NLS-2$
    modelTwo.addSourceMapping("s2", "translator", "java:binding-two");
    // $NON-NLS-1$
    modelTwo.setModelType(Model.Type.VIRTUAL);
    // $NON-NLS-1$ //$NON-NLS-2$
    modelTwo.addProperty("model-prop", "model-value");
    modelTwo.addSourceMetadata("DDL", "DDL Here");
    vdb.addModel(modelTwo);
    VDBTranslatorMetaData t1 = new VDBTranslatorMetaData();
    t1.setName("oracleOverride");
    t1.setType("oracle");
    t1.setDescription("hello world");
    t1.addProperty("my-property", "my-value");
    List<Translator> list = new ArrayList<Translator>();
    list.add(t1);
    vdb.setOverrideTranslators(list);
    DataPolicyMetadata roleOne = new DataPolicyMetadata();
    // $NON-NLS-1$
    roleOne.setName("roleOne");
    // $NON-NLS-1$
    roleOne.setDescription("roleOne described");
    roleOne.setAllowCreateTemporaryTables(true);
    roleOne.setGrantAll(true);
    PermissionMetaData perm1 = new PermissionMetaData();
    // $NON-NLS-1$
    perm1.setResourceName("myTable.T1");
    perm1.setAllowRead(true);
    roleOne.addPermission(perm1);
    PermissionMetaData perm2 = new PermissionMetaData();
    // $NON-NLS-1$
    perm2.setResourceName("myTable.T2");
    perm2.setAllowRead(false);
    perm2.setAllowDelete(true);
    perm2.setCondition("col1 = user()");
    perm2.setConstraint(false);
    roleOne.addPermission(perm2);
    PermissionMetaData perm3 = new PermissionMetaData();
    // $NON-NLS-1$
    perm3.setResourceName("javascript");
    perm3.setAllowLanguage(true);
    roleOne.addPermission(perm3);
    PermissionMetaData perm4 = new PermissionMetaData();
    // $NON-NLS-1$
    perm4.setResourceName("myTable.T2.col1");
    perm4.setMask("col2");
    perm4.setOrder(1);
    roleOne.addPermission(perm4);
    // $NON-NLS-1$ //$NON-NLS-2$
    roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2"));
    vdb.addDataPolicy(roleOne);
    EntryMetaData em = new EntryMetaData();
    em.setPath("/path-one");
    em.setDescription("entry one");
    em.addProperty("entryone", "1");
    vdb.getEntries().add(em);
    EntryMetaData em2 = new EntryMetaData();
    em2.setPath("/path-two");
    vdb.getEntries().add(em2);
    return vdb;
}
Also used : Translator(org.teiid.adminapi.Translator) ArrayList(java.util.ArrayList) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)

Example 3 with PermissionMetaData

use of org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData in project teiid by teiid.

the class VDBMetadataParser method parseDataRole.

private static void parseDataRole(XMLStreamReader reader, DataPolicyMetadata policy) throws XMLStreamException {
    Properties props = getAttributes(reader);
    policy.setName(props.getProperty(Element.NAME.getLocalName()));
    policy.setAnyAuthenticated(Boolean.parseBoolean(props.getProperty(Element.DATA_ROLE_ANY_ATHENTICATED_ATTR.getLocalName())));
    policy.setGrantAll(Boolean.parseBoolean(props.getProperty(Element.DATA_ROLE_GRANT_ALL_ATTR.getLocalName())));
    policy.setAllowCreateTemporaryTables(Boolean.parseBoolean(props.getProperty(Element.DATA_ROLE_ALLOW_TEMP_TABLES_ATTR.getLocalName())));
    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
        Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case DESCRIPTION:
                policy.setDescription(reader.getElementText());
                break;
            case PERMISSION:
                PermissionMetaData permission = new PermissionMetaData();
                parsePermission(reader, permission);
                policy.addPermission(permission);
                break;
            case MAPPED_ROLE_NAME:
                policy.addMappedRoleName(reader.getElementText());
                break;
            default:
                throw new XMLStreamException(AdminPlugin.Util.gs("unexpected_element2", reader.getName(), Element.DESCRIPTION.getLocalName(), Element.PERMISSION.getLocalName(), Element.MAPPED_ROLE_NAME.getLocalName()), reader.getLocation());
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) Properties(java.util.Properties) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)

Example 4 with PermissionMetaData

use of org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData in project teiid by teiid.

the class TestRowBasedSecurity method testInsertConstraintSubquery.

@Test
public void testInsertConstraintSubquery() throws Exception {
    DataPolicyMetadata policy1 = new DataPolicyMetadata();
    PermissionMetaData pmd3 = new PermissionMetaData();
    pmd3.setResourceName("pm1.g1");
    pmd3.setCondition("e1 = (select min(e1) from pm1.g3)");
    policy1.addPermission(pmd3);
    policy1.setName("some-other-role");
    context.getAllowedDataPolicies().put("some-other-role", policy1);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.e1 FROM pm1.g3 AS g_0", new List<?>[] { Arrays.asList("a"), Arrays.asList("b") });
    dataManager.addData("INSERT INTO pm1.g1 (e1, e2) VALUES ('a', 1)", new List<?>[] { Arrays.asList(1) });
    ProcessorPlan plan = helpGetPlan(helpParse("insert into pm1.g1 (e1, e2) values ('a', 1)"), RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder(), context);
    List<?>[] expectedResults = new List<?>[] { Arrays.asList(1) };
    helpProcess(plan, context, dataManager, expectedResults);
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) List(java.util.List) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 5 with PermissionMetaData

use of org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData in project teiid by teiid.

the class TestRowBasedSecurity method testSelectFilterOuterJoin1.

@Test
public void testSelectFilterOuterJoin1() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table t (x string, y integer); create foreign table t1 (x string, y integer); create view v as select t.x, t1.y from t left outer join t1 on t.y = t1.y", "x", "y");
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
    caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, false);
    CommandContext context = createCommandContext();
    DQPWorkContext workContext = new DQPWorkContext();
    HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
    DataPolicyMetadata policy = new DataPolicyMetadata();
    pmd = new PermissionMetaData();
    pmd.setResourceName("y.v");
    pmd.setCondition("x = user()");
    policy.addPermission(pmd);
    policy.setName("some-role");
    policies.put("some-role", policy);
    workContext.setPolicies(policies);
    context.setDQPWorkContext(workContext);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.y AS c_0, g_0.x AS c_1 FROM y.t AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1, "a"), Arrays.asList(2, "b") });
    dataManager.addData("SELECT g_0.y AS c_0 FROM y.t1 AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1) });
    ProcessorPlan plan = helpGetPlan(helpParse("select count(1) from v"), tm, new DefaultCapabilitiesFinder(caps), context);
    List<?>[] expectedResults = new List<?>[] { Arrays.asList(0) };
    helpProcess(plan, context, dataManager, expectedResults);
    plan = helpGetPlan(helpParse("select count(1) from v where y is not null"), tm, new DefaultCapabilitiesFinder(caps), context);
    dataManager.addData("SELECT g_0.y FROM y.t AS g_0 WHERE g_0.x = 'user'", new List<?>[] { Arrays.asList(1), Arrays.asList(2) });
    dataManager.addData("SELECT g_0.y AS c_0 FROM y.t1 AS g_0 WHERE g_0.y IS NOT NULL ORDER BY c_0", Arrays.asList(1));
    expectedResults = new List<?>[] { Arrays.asList(1) };
    helpProcess(plan, context, dataManager, expectedResults);
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HashMap(java.util.HashMap) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) List(java.util.List) DataPolicy(org.teiid.adminapi.DataPolicy) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Aggregations

PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)29 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)24 Test (org.junit.Test)20 List (java.util.List)14 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)13 DataPolicy (org.teiid.adminapi.DataPolicy)6 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)3 CommandContext (org.teiid.query.util.CommandContext)3 Map (java.util.Map)2 Translator (org.teiid.adminapi.Translator)2 Expression (org.teiid.query.sql.symbol.Expression)2 Properties (java.util.Properties)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ModelNode (org.jboss.dmr.ModelNode)1 DataPermission (org.teiid.adminapi.DataPolicy.DataPermission)1 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)1