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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations