Search in sources :

Example 26 with PermissionMetaData

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

the class TestRowBasedSecurity method testMultipleRoles.

/**
 * Here the other role makes the g1 rows visible again
 */
@Test
public void testMultipleRoles() throws Exception {
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List<?>[] { Arrays.asList("a", 1), Arrays.asList("b", 2) });
    ProcessorPlan plan = helpGetPlan(helpParse("select e2 from pm1.g1"), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
    helpProcess(plan, context, dataManager, new List<?>[0]);
    DataPolicyMetadata policy1 = new DataPolicyMetadata();
    PermissionMetaData pmd3 = new PermissionMetaData();
    pmd3.setResourceName("pm1.g1");
    pmd3.setCondition("true");
    policy1.addPermission(pmd3);
    policy1.setName("some-other-role");
    context.getAllowedDataPolicies().put("some-other-role", policy1);
    dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT pm1.g1.e2 FROM pm1.g1", new List<?>[] { Arrays.asList(1), Arrays.asList(2) });
    plan = helpGetPlan(helpParse("select e2 from pm1.g1"), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
    List<?>[] expectedResults = new List<?>[] { Arrays.asList(1), Arrays.asList(2) };
    helpProcess(plan, context, dataManager, expectedResults);
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 27 with PermissionMetaData

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

the class TestRowBasedSecurity method testInsertConstraintCorrelatedSubquery.

@Test(expected = TeiidProcessingException.class)
public void testInsertConstraintCorrelatedSubquery() throws Exception {
    DataPolicyMetadata policy1 = new DataPolicyMetadata();
    PermissionMetaData pmd3 = new PermissionMetaData();
    pmd3.setResourceName("pm1.g1");
    pmd3.setCondition("e1 = (select min(e1) from pm1.g3 where pm1.g1.e2 = e2)");
    policy1.addPermission(pmd3);
    policy1.setName("some-other-role");
    context.getAllowedDataPolicies().put("some-other-role", policy1);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    ProcessorPlan plan = helpGetPlan(helpParse("insert into pm1.g1 (e1, e2) values ('a', 1)"), RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder(), context);
    List<?>[] expectedResults = new List<?>[] { Arrays.asList(0) };
    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 28 with PermissionMetaData

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

the class TestRowBasedSecurity method createContext.

private static CommandContext createContext() {
    CommandContext context = createCommandContext();
    DQPWorkContext workContext = new DQPWorkContext();
    HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
    DataPolicyMetadata policy = new DataPolicyMetadata();
    pmd = new PermissionMetaData();
    pmd.setResourceName("pm1.g1");
    pmd.setCondition("e1 = user()");
    PermissionMetaData pmd1 = new PermissionMetaData();
    pmd1.setResourceName("pm1.g2");
    pmd1.setCondition("foo = bar");
    PermissionMetaData pmd2 = new PermissionMetaData();
    pmd2.setResourceName("pm1.g4");
    pmd2.setCondition("e1 = max(e2)");
    PermissionMetaData pmd3 = new PermissionMetaData();
    pmd3.setResourceName("pm1.g3");
    pmd3.setAllowDelete(true);
    PermissionMetaData pmd4 = new PermissionMetaData();
    pmd4.setResourceName("pm1.sp1");
    pmd4.setCondition("e1 = 'a'");
    policy.addPermission(pmd, pmd1, pmd2, pmd3, pmd4);
    policy.setName("some-role");
    policies.put("some-role", policy);
    workContext.setPolicies(policies);
    context.setDQPWorkContext(workContext);
    return context;
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) CommandContext(org.teiid.query.util.CommandContext) HashMap(java.util.HashMap) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPolicy(org.teiid.adminapi.DataPolicy) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)

Example 29 with PermissionMetaData

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

the class TestAdminObjectBuilder method testVDB.

@Test
public void testVDB() {
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("myVDB");
    vdb.setDescription("vdb description");
    vdb.setVersion(1);
    vdb.addProperty("vdb-property", "vdb-value");
    ModelMetaData modelOne = new ModelMetaData();
    modelOne.setName("model-one");
    modelOne.addSourceMapping("s1", "translator", "java:mybinding");
    modelOne.setModelType(Model.Type.PHYSICAL);
    modelOne.addProperty("model-prop", "model-value");
    modelOne.addProperty("model-prop", "model-value-override");
    modelOne.setVisible(false);
    modelOne.addMessage("ERROR", "There is an error in VDB");
    modelOne.setDescription("model description");
    vdb.addModel(modelOne);
    ModelMetaData modelTwo = new ModelMetaData();
    modelTwo.setName("model-two");
    modelTwo.addSourceMapping("s1", "translator", "java:binding-one");
    modelTwo.addSourceMapping("s2", "translator", "java:binding-two");
    modelTwo.setModelType(Model.Type.VIRTUAL);
    modelTwo.addProperty("model-prop", "model-value");
    vdb.addModel(modelTwo);
    VDBTranslatorMetaData t1 = new VDBTranslatorMetaData();
    t1.setName("oracleOverride");
    t1.setType("oracle");
    t1.addProperty("my-property", "my-value");
    List<Translator> list = new ArrayList<Translator>();
    list.add(t1);
    vdb.setOverrideTranslators(list);
    DataPolicyMetadata roleOne = new DataPolicyMetadata();
    roleOne.setName("roleOne");
    roleOne.setDescription("roleOne described");
    PermissionMetaData perm1 = new PermissionMetaData();
    perm1.setResourceName("myTable.T1");
    perm1.setAllowRead(true);
    roleOne.addPermission(perm1);
    PermissionMetaData perm2 = new PermissionMetaData();
    perm2.setResourceName("myTable.T2");
    perm2.setAllowRead(false);
    perm2.setAllowDelete(true);
    roleOne.addPermission(perm2);
    roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2"));
    vdb.addDataPolicy(roleOne);
    // convert to managed object and build the VDB out of MO
    ModelNode node = VDBMetadataMapper.INSTANCE.wrap(vdb, new ModelNode());
    vdb = VDBMetadataMapper.INSTANCE.unwrap(node);
    assertEquals("myVDB", vdb.getName());
    assertEquals("vdb description", vdb.getDescription());
    assertEquals("1", vdb.getVersion());
    assertEquals("vdb-value", vdb.getPropertyValue("vdb-property"));
    assertNotNull(vdb.getModel("model-one"));
    assertNotNull(vdb.getModel("model-two"));
    assertNull(vdb.getModel("model-unknown"));
    modelOne = vdb.getModel("model-one");
    assertEquals("model-one", modelOne.getName());
    assertEquals("s1", modelOne.getSourceNames().get(0));
    assertEquals(Model.Type.PHYSICAL, modelOne.getModelType());
    assertEquals("model-value-override", modelOne.getPropertyValue("model-prop"));
    assertFalse(modelOne.isVisible());
    assertEquals("model description", modelOne.getDescription());
    modelTwo = vdb.getModel("model-two");
    assertEquals("model-two", modelTwo.getName());
    assertTrue(modelTwo.getSourceNames().contains("s1"));
    assertTrue(modelTwo.getSourceNames().contains("s2"));
    // this is not persisted in the XML
    assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType());
    assertEquals("model-value", modelTwo.getPropertyValue("model-prop"));
    assertTrue(vdb.getValidityErrors().contains("There is an error in VDB"));
    List<Translator> translators = vdb.getOverrideTranslators();
    assertTrue(translators.size() == 1);
    Translator translator = translators.get(0);
    assertEquals("oracleOverride", translator.getName());
    assertEquals("oracle", translator.getType());
    assertEquals("my-value", translator.getPropertyValue("my-property"));
    List<DataPolicy> roles = vdb.getDataPolicies();
    assertTrue(roles.size() == 1);
    DataPolicyMetadata role = vdb.getDataPolicyMap().get("roleOne");
    assertEquals("roleOne described", role.getDescription());
    assertNotNull(role.getMappedRoleNames());
    assertTrue(role.getMappedRoleNames().contains("ROLE1"));
    assertTrue(role.getMappedRoleNames().contains("ROLE2"));
    List<DataPolicy.DataPermission> permissions = role.getPermissions();
    assertEquals(2, permissions.size());
    for (DataPolicy.DataPermission p : permissions) {
        if (p.getResourceName().equalsIgnoreCase("myTable.T1")) {
            assertTrue(p.getAllowRead());
            assertNull(p.getAllowDelete());
        } else {
            assertFalse(p.getAllowRead());
            assertTrue(p.getAllowDelete());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Translator(org.teiid.adminapi.Translator) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) DataPolicy(org.teiid.adminapi.DataPolicy) ModelNode(org.jboss.dmr.ModelNode) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) 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