Search in sources :

Example 11 with DataPolicy

use of org.teiid.adminapi.DataPolicy in project teiid by teiid.

the class TestAuthorizationValidationVisitor method createPolicyDecider.

private DataRolePolicyDecider createPolicyDecider(QueryMetadataInterface metadata, VDBMetaData vdb, DataPolicyMetadata... roles) {
    vdb.addAttchment(QueryMetadataInterface.class, metadata);
    HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
    for (DataPolicyMetadata dataPolicyMetadata : roles) {
        policies.put(dataPolicyMetadata.getName(), dataPolicyMetadata);
    }
    vdb.setDataPolicies(new ArrayList<DataPolicy>(policies.values()));
    this.context.getDQPWorkContext().setPolicies(policies);
    this.context.getSession().setVdb(vdb);
    this.context.setMetadata(metadata);
    DataRolePolicyDecider dataRolePolicyDecider = new DataRolePolicyDecider();
    dataRolePolicyDecider.setAllowFunctionCallsByDefault(false);
    return dataRolePolicyDecider;
}
Also used : HashMap(java.util.HashMap) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPolicy(org.teiid.adminapi.DataPolicy)

Example 12 with DataPolicy

use of org.teiid.adminapi.DataPolicy in project teiid by teiid.

the class VDBMetadataParser method writeVDB.

private void writeVDB(VDBMetaData vdb, OutputStream out) throws XMLStreamException, IOException {
    XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(out);
    writer.writeStartDocument();
    writer.writeStartElement(Element.VDB.getLocalName());
    writeAttribute(writer, Element.NAME.getLocalName(), vdb.getName());
    writeAttribute(writer, Element.VERSION.getLocalName(), String.valueOf(vdb.getVersion()));
    if (vdb.getDescription() != null) {
        writeElement(writer, Element.DESCRIPTION, vdb.getDescription());
    }
    writeElement(writer, Element.CONNECTION_TYPE, vdb.getConnectionType().name());
    writeProperties(writer, vdb.getPropertiesMap());
    for (VDBImport vdbImport : vdb.getVDBImports()) {
        writer.writeStartElement(Element.IMPORT_VDB.getLocalName());
        writeAttribute(writer, Element.NAME.getLocalName(), vdbImport.getName());
        writeAttribute(writer, Element.VERSION.getLocalName(), String.valueOf(vdbImport.getVersion()));
        writeAttribute(writer, Element.IMPORT_POLICIES.getLocalName(), String.valueOf(vdbImport.isImportDataPolicies()));
        writer.writeEndElement();
    }
    // models
    Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
    for (ModelMetaData model : models) {
        if (vdb.getImportedModels().contains(model.getName())) {
            continue;
        }
        writeModel(writer, model);
    }
    // override translators
    for (VDBTranslatorMetaData translator : vdb.getOverrideTranslatorsMap().values()) {
        writeTranslator(writer, translator);
    }
    // data-roles
    for (DataPolicy dp : vdb.getDataPolicies()) {
        writeDataPolicy(writer, dp);
    }
    // designer only
    for (EntryMetaData em : vdb.getEntries()) {
        writer.writeStartElement(Element.ENTRY.getLocalName());
        writeAttribute(writer, Element.PATH.getLocalName(), em.getPath());
        if (em.getDescription() != null) {
            writeElement(writer, Element.DESCRIPTION, em.getDescription());
        }
        writeProperties(writer, em.getPropertiesMap());
        writer.writeEndElement();
    }
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.close();
    out.close();
}
Also used : XMLStreamWriter(javax.xml.stream.XMLStreamWriter) VDBImport(org.teiid.adminapi.VDBImport) DataPolicy(org.teiid.adminapi.DataPolicy)

Example 13 with DataPolicy

use of org.teiid.adminapi.DataPolicy in project teiid by teiid.

the class TestVDBUtility method validateVDB.

public static void validateVDB(VDBMetaData vdb) {
    ModelMetaData modelOne;
    ModelMetaData modelTwo;
    // $NON-NLS-1$
    assertEquals("myVDB", vdb.getName());
    // $NON-NLS-1$
    assertEquals("vdb description", vdb.getDescription());
    assertEquals("connection-type", "NONE", vdb.getConnectionType().name());
    assertEquals("1", vdb.getVersion());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("vdb-value", vdb.getPropertyValue("vdb-property"));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("vdb-value2", vdb.getPropertyValue("vdb-property2"));
    // $NON-NLS-1$
    assertNotNull(vdb.getModel("model-one"));
    // $NON-NLS-1$
    assertNotNull(vdb.getModel("model-two"));
    // $NON-NLS-1$
    assertNull(vdb.getModel("model-unknown"));
    assertEquals(1, vdb.getVDBImports().size());
    VDBImport vdbImport = vdb.getVDBImports().get(0);
    assertEquals("x", vdbImport.getName());
    assertEquals("2", vdbImport.getVersion());
    // $NON-NLS-1$
    modelOne = vdb.getModel("model-one");
    // $NON-NLS-1$
    assertEquals("model-one", modelOne.getName());
    // $NON-NLS-1$
    assertEquals("s1", modelOne.getSourceNames().get(0));
    assertEquals(Model.Type.PHYSICAL, modelOne.getModelType());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("model-value-override", modelOne.getPropertyValue("model-prop"));
    assertFalse(modelOne.isVisible());
    assertEquals("model description", modelOne.getDescription());
    assertEquals("DDL", modelOne.getSourceMetadataType().get(0));
    assertEquals("DDL Here", modelOne.getSourceMetadataText().get(0));
    assertEquals("OTHER", modelOne.getSourceMetadataType().get(1));
    assertEquals("other text", modelOne.getSourceMetadataText().get(1));
    // $NON-NLS-1$
    modelTwo = vdb.getModel("model-two");
    // $NON-NLS-1$
    assertEquals("model-two", modelTwo.getName());
    // $NON-NLS-1$
    assertTrue(modelTwo.getSourceNames().contains("s1"));
    // $NON-NLS-1$
    assertTrue(modelTwo.getSourceNames().contains("s2"));
    // this is not persisted in the XML
    assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("model-value", modelTwo.getPropertyValue("model-prop"));
    assertEquals("DDL", modelTwo.getSourceMetadataType().get(0));
    assertEquals("DDL Here", modelTwo.getSourceMetadataText().get(0));
    // $NON-NLS-1$
    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"));
    assertEquals("hello world", translator.getDescription());
    List<DataPolicy> roles = vdb.getDataPolicies();
    assertTrue(roles.size() == 1);
    // $NON-NLS-1$
    DataPolicyMetadata role = vdb.getDataPolicyMap().get("roleOne");
    assertTrue(role.isGrantAll());
    assertTrue(role.isAllowCreateTemporaryTables());
    // $NON-NLS-1$
    assertEquals("roleOne described", role.getDescription());
    assertNotNull(role.getMappedRoleNames());
    // $NON-NLS-1$
    assertTrue(role.getMappedRoleNames().contains("ROLE1"));
    // $NON-NLS-1$
    assertTrue(role.getMappedRoleNames().contains("ROLE2"));
    List<DataPolicy.DataPermission> permissions = role.getPermissions();
    assertEquals(4, permissions.size());
    boolean lang = false;
    for (DataPolicy.DataPermission p : permissions) {
        if (p.getAllowLanguage() != null) {
            assertTrue(p.getAllowLanguage());
            assertEquals("javascript", p.getResourceName());
            lang = true;
            continue;
        }
        if (p.getResourceName().equalsIgnoreCase("myTable.T1")) {
            // $NON-NLS-1$
            assertTrue(p.getAllowRead());
            assertNull(p.getAllowDelete());
            continue;
        }
        if (p.getResourceName().equalsIgnoreCase("myTable.T2.col1")) {
            // $NON-NLS-1$
            assertEquals("col2", p.getMask());
            assertEquals(1, p.getOrder().intValue());
            continue;
        }
        assertFalse(p.getAllowRead());
        assertTrue(p.getAllowDelete());
        assertEquals("col1 = user()", p.getCondition());
        assertFalse(p.getConstraint());
    }
    assertTrue(lang);
}
Also used : Translator(org.teiid.adminapi.Translator) VDBImport(org.teiid.adminapi.VDBImport) DataPolicy(org.teiid.adminapi.DataPolicy)

Example 14 with DataPolicy

use of org.teiid.adminapi.DataPolicy in project teiid by teiid.

the class TestColumnMasking 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();
    PermissionMetaData pmd = new PermissionMetaData();
    pmd.setResourceName("pm1.sp1.e1");
    pmd.setMask("case when e2 > 1 then null else e1 end");
    PermissionMetaData pmd1 = new PermissionMetaData();
    pmd1.setResourceName("pm1.g1.e2");
    pmd1.setMask("case when e1 = 'a' then null else e2 end");
    policy.addPermission(pmd, pmd1);
    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 15 with DataPolicy

use of org.teiid.adminapi.DataPolicy 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)

Aggregations

DataPolicy (org.teiid.adminapi.DataPolicy)17 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)11 HashMap (java.util.HashMap)7 PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)6 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)5 Map (java.util.Map)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Translator (org.teiid.adminapi.Translator)3 VDBImport (org.teiid.adminapi.VDBImport)3 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)3 Expression (org.teiid.query.sql.symbol.Expression)3 CommandContext (org.teiid.query.util.CommandContext)3 ModelNode (org.jboss.dmr.ModelNode)2 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)2 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)2 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 SearchedCaseExpression (org.teiid.query.sql.symbol.SearchedCaseExpression)2