Search in sources :

Example 1 with DataPolicyMetadata

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

the class DatabaseUtil method convert.

public static Database convert(VDBMetaData vdb, MetadataStore metadataStore) {
    Database db = new Database(vdb.getName(), vdb.getVersion());
    db.setProperties(vdb.getPropertiesMap());
    if (vdb.getDescription() != null) {
        db.setAnnotation(vdb.getDescription());
    }
    db.setProperty("connection-type", vdb.getConnectionType().name());
    db.getMetadataStore().addDataTypes(metadataStore.getDatatypes());
    // override translators
    List<Translator> translators = vdb.getOverrideTranslators();
    for (Translator t : translators) {
        // add the base
        if (db.getDataWrapper(t.getType()) == null) {
            DataWrapper dw = new DataWrapper(t.getType());
            db.addDataWrapper(dw);
        }
        // add override with properties
        if (db.getDataWrapper(t.getName()) == null) {
            DataWrapper dw = new DataWrapper(t.getName());
            dw.setType(t.getType());
            for (final String key : t.getProperties().stringPropertyNames()) {
                dw.setProperty(key, t.getPropertyValue(key));
            }
            if (t.getDescription() != null) {
                dw.setAnnotation(t.getDescription());
            }
            db.addDataWrapper(dw);
        }
    }
    Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
    for (ModelMetaData m : models) {
        Schema schema = metadataStore.getSchema(m.getName());
        // add servers
        if (m.isSource()) {
            Collection<SourceMappingMetadata> sources = m.getSourceMappings();
            for (SourceMappingMetadata s : sources) {
                // add translators, that are not override
                if (db.getDataWrapper(s.getTranslatorName()) == null) {
                    DataWrapper dw = new DataWrapper(s.getTranslatorName());
                    db.addDataWrapper(dw);
                }
                // add servers
                Server server = new Server(s.getName());
                server.setJndiName(s.getConnectionJndiName());
                server.setDataWrapper(s.getTranslatorName());
                // no need to add duplicate definitions.
                if (db.getServer(s.getName()) == null) {
                    db.addServer(server);
                    schema.addServer(server);
                }
            }
        }
        db.addSchema(schema);
    }
    for (String key : vdb.getDataPolicyMap().keySet()) {
        DataPolicyMetadata dpm = vdb.getDataPolicyMap().get(key);
        Role role = new Role(dpm.getName());
        if (dpm.getMappedRoleNames() != null && !dpm.getMappedRoleNames().isEmpty()) {
            role.setJaasRoles(dpm.getMappedRoleNames());
        }
        if (dpm.isAnyAuthenticated()) {
            role.setAnyAuthenticated(true);
        }
        Grant grant = null;
        if (dpm.isGrantAll()) {
            if (grant == null) {
                grant = new Grant();
                grant.setRole(role.getName());
            }
            Permission permission = new Permission();
            permission.setAllowAllPrivileges(true);
            permission.setResourceType(ResourceType.DATABASE);
            grant.addPermission(permission);
        }
        if (dpm.isAllowCreateTemporaryTables() != null && dpm.isAllowCreateTemporaryTables()) {
            if (grant == null) {
                grant = new Grant();
                grant.setRole(role.getName());
            }
            Permission permission = new Permission();
            permission.setAllowTemporyTables(true);
            permission.setResourceType(ResourceType.DATABASE);
            grant.addPermission(permission);
        }
        for (DataPolicy.DataPermission dp : dpm.getPermissions()) {
            if (grant == null) {
                grant = new Grant();
                grant.setRole(role.getName());
            }
            Permission permission = convert(dp);
            grant.addPermission(permission);
        }
        db.addRole(role);
        db.addGrant(grant);
    }
    return db;
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) Translator(org.teiid.adminapi.Translator) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPermission(org.teiid.adminapi.DataPolicy.DataPermission) DataPermission(org.teiid.adminapi.DataPolicy.DataPermission) Permission(org.teiid.metadata.Grant.Permission) DataPolicy(org.teiid.adminapi.DataPolicy)

Example 2 with DataPolicyMetadata

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

the class TestAuthorizationValidationVisitor method examplePolicyBQT.

private DataPolicyMetadata examplePolicyBQT() {
    DataPolicyMetadata svc = new DataPolicyMetadata();
    // $NON-NLS-1$
    svc.setName("test");
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.ALTER, "VQT.SmallA_2589"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "bqt1"));
    svc.setAllowCreateTemporaryTables(true);
    return svc;
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata)

Example 3 with DataPolicyMetadata

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

the class TestAuthorizationValidationVisitor method testCreateForeignTemp.

@Test
public void testCreateForeignTemp() throws Exception {
    DataPolicyMetadata dpm = exampleAuthSvc1();
    dpm.setAllowCreateTemporaryTables(false);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("create foreign temporary table x (id string) on bqt1", RealMetadataFactory.exampleBQTCached(), new String[] { "x" }, RealMetadataFactory.exampleBQTVDB(), dpm);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("create foreign temporary table x (id string) on bqt1", RealMetadataFactory.exampleBQTCached(), new String[] {}, RealMetadataFactory.exampleBQTVDB(), examplePolicyBQT());
    TempTableTestHarness harness = new TempTableTestHarness();
    harness.setUp(RealMetadataFactory.exampleBQTCached(), new HardcodedDataManager());
    harness.execute("create foreign temporary table x (id string) on bqt1", new List[] { Arrays.asList(0) });
    helpTest("insert into x (id) values ('a')", harness.getMetadata(), new String[] { "x.id" }, RealMetadataFactory.exampleBQTVDB(), dpm);
    // we have create on bqt1
    helpTest("insert into x (id) values ('a')", harness.getMetadata(), new String[] {}, RealMetadataFactory.exampleBQTVDB(), examplePolicyBQT());
    // we don't have read on bqt1
    helpTest("select * from x", harness.getMetadata(), new String[] { "x.id" }, RealMetadataFactory.exampleBQTVDB(), examplePolicyBQT());
}
Also used : TempTableTestHarness(org.teiid.query.processor.TempTableTestHarness) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) Test(org.junit.Test)

Example 4 with DataPolicyMetadata

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

the class TestAuthorizationValidationVisitor method exampleAuthSvc2.

// allow by default
private static DataPolicyMetadata exampleAuthSvc2() {
    DataPolicyMetadata svc = new DataPolicyMetadata();
    // $NON-NLS-1$
    svc.setName("test");
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1.g2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1.g1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm2.g1"));
    // pm2.g2
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm2.g2.e1"));
    // pm3.g2
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm3.g2.e1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm3.g2.e2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "xmltest.doc1"));
    svc.setAllowCreateTemporaryTables(false);
    return svc;
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata)

Example 5 with DataPolicyMetadata

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

the class TestAuthorizationValidationVisitor method exampleAuthSvc1.

private static DataPolicyMetadata exampleAuthSvc1() {
    DataPolicyMetadata svc = new DataPolicyMetadata();
    // $NON-NLS-1$
    svc.setName("test");
    // pm1.g1
    // $NON-NLS-1$
    svc.addPermission(addResource(PermissionType.DELETE, "pm1.g1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1.g1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1.g1.e1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, false, "pm1.g1.e2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g1.e1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g1.e2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g1.e3"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g1.e4"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, false, "pm1.g1.e1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g1.e2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g1.e3"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g1.e4"));
    svc.addPermission(addResource(PermissionType.EXECUTE, "pm1.sp1"));
    // pm1.g2
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, false, "pm1.g2.e1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g2.e2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g2.e3"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.CREATE, "pm1.g2.e4"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, false, "pm1.g2.e1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g2.e2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g2.e3"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.UPDATE, "pm1.g2.e4"));
    // pm1.g4
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.DELETE, "pm1.g4"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.DELETE, "pm1.g4.e1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.DELETE, "pm1.g4.e2"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1.sq1"));
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1.xyz"));
    svc.setAllowCreateTemporaryTables(true);
    return svc;
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata)

Aggregations

DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)47 Test (org.junit.Test)26 PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)24 List (java.util.List)14 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)13 DataPolicy (org.teiid.adminapi.DataPolicy)12 HashMap (java.util.HashMap)7 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)7 Map (java.util.Map)4 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)3 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)3 CommandContext (org.teiid.query.util.CommandContext)3 ArrayList (java.util.ArrayList)2 DataPermission (org.teiid.adminapi.DataPolicy.DataPermission)2 Translator (org.teiid.adminapi.Translator)2 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)2 Permission (org.teiid.metadata.Grant.Permission)2 Expression (org.teiid.query.sql.symbol.Expression)2