Search in sources :

Example 11 with DQPWorkContext

use of org.teiid.dqp.internal.process.DQPWorkContext 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 12 with DQPWorkContext

use of org.teiid.dqp.internal.process.DQPWorkContext in project teiid by teiid.

the class TestSourceHints method testKeepAliases.

@Test
public void testKeepAliases() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT /*+ sh KEEP ALIASES bar:'leading(g)' */ e1 from pm1.g1 g order by e1 limit 1";
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setDQPWorkContext(new DQPWorkContext());
    cc.getDQPWorkContext().getSession().setVdb(RealMetadataFactory.example1VDB());
    ProcessorPlan plan = TestOptimizer.getPlan(TestOptimizer.helpGetCommand(sql, RealMetadataFactory.example1Cached(), null), RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder(), null, true, cc);
    TestOptimizer.checkAtomicQueries(new String[] { "SELECT /*+sh KEEP ALIASES bar:'leading(g)' */ g.e1 AS c_0 FROM pm1.g1 AS g ORDER BY c_0" }, plan);
    List<?>[] expected = new List[] {};
    helpProcess(plan, manager(null, "leading(g)"), expected);
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) CommandContext(org.teiid.query.util.CommandContext) List(java.util.List) Test(org.junit.Test)

Example 13 with DQPWorkContext

use of org.teiid.dqp.internal.process.DQPWorkContext in project teiid by teiid.

the class RealMetadataFactory method buildWorkContext.

public static DQPWorkContext buildWorkContext(QueryMetadataInterface metadata, VDBMetaData vdb) {
    DQPWorkContext workContext = new DQPWorkContext();
    SessionMetadata session = new SessionMetadata();
    workContext.setSession(session);
    session.setVDBName(vdb.getName());
    session.setVDBVersion(vdb.getVersion());
    session.setSessionId(String.valueOf(1));
    // $NON-NLS-1$
    session.setUserName("foo");
    session.setVdb(vdb);
    workContext.getVDB().addAttchment(QueryMetadataInterface.class, metadata);
    if (metadata instanceof TransformationMetadata) {
        workContext.getVDB().addAttchment(TransformationMetadata.class, (TransformationMetadata) metadata);
    }
    DQPWorkContext.setWorkContext(workContext);
    return workContext;
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata)

Example 14 with DQPWorkContext

use of org.teiid.dqp.internal.process.DQPWorkContext in project teiid by teiid.

the class TestLogonImpl method testLogonAuthenticationType.

@Test
public void testLogonAuthenticationType() throws Exception {
    VDBRepository repo = Mockito.mock(VDBRepository.class);
    VDBMetaData vdb = new VDBMetaData();
    vdb.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    vdb.setName("name");
    vdb.setVersion(1);
    vdb.setStatus(Status.ACTIVE);
    Mockito.stub(repo.getLiveVDB("name", "1")).toReturn(vdb);
    ssi.setVDBRepository(repo);
    ssi.setSecurityDomain("SC");
    // default transport - what Teiid has before TEIID-2863
    // this is transport default
    ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    Properties p = buildProperties("fred", "name");
    // $NON-NLS-1$
    LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
    LogonResult result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    // if no preference then choose USERPASSWORD
    // this is transport default
    ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    p = buildProperties("fred", "name");
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    // if user name is set to "GSS", then the preference is set to "GSS"
    // this is transport default
    ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    p = buildProperties("GSS", "name");
    // $NON-NLS-1$
    FakeGssLogonImpl fimpl = new FakeGssLogonImpl(ssi, "fakeCluster");
    fimpl.addToken("bytes".getBytes(), new Subject());
    p.put(ILogon.KRB5TOKEN, "bytes".getBytes());
    result = fimpl.logon(p);
    assertEquals("GSS", result.getUserName());
    // if the transport default defined as GSS, then preference is USERPASSWORD, additional challenge
    ssi.setAuthenticationType(AuthenticationType.GSS);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    p = buildProperties("fred", "name");
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    result = impl.logon(p);
    assertEquals(AuthenticationType.GSS, result.getProperty("authType"));
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LogonResult(org.teiid.client.security.LogonResult) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 15 with DQPWorkContext

use of org.teiid.dqp.internal.process.DQPWorkContext in project teiid by teiid.

the class TestLogonImpl method testLogonAuthenticationTypeByVDB.

@Test
public void testLogonAuthenticationTypeByVDB() throws Exception {
    VDBRepository repo = Mockito.mock(VDBRepository.class);
    ssi.setVDBRepository(repo);
    // when VDB value is is avavailble this will not be used
    ssi.setAuthenticationType(AuthenticationType.GSS);
    // default transport - what Teiid has before TEIID-2863
    addVdb(repo, "name", "SC", AuthenticationType.USERPASSWORD.name());
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    Properties p = buildProperties("fred", "name");
    // $NON-NLS-1$
    LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
    LogonResult result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    // if no preference then choose USERPASSWORD
    VDBMetaData metadata = addVdb(repo, "name1", "SC", AuthenticationType.USERPASSWORD.name());
    metadata.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties("fred", "name1");
    result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    p = buildProperties("GSS", "name1");
    // $NON-NLS-1$
    FakeGssLogonImpl fimpl = new FakeGssLogonImpl(ssi, "fakeCluster");
    fimpl.addToken("bytes".getBytes(), new Subject());
    p.put(ILogon.KRB5TOKEN, "bytes".getBytes());
    result = fimpl.logon(p);
    assertEquals("GSS", result.getUserName());
    // here preference is GSS
    try {
        p = buildProperties("GSS", "name");
        result = impl.logon(p);
        assertEquals("GSS", result.getUserName());
    } catch (LogonException e) {
    }
    // if the transport default defined as GSS, then preference is USERPASSWORD, additional challenge
    addVdb(repo, "name2", "SC", "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties("fred", "name2");
    result = impl.logon(p);
    assertEquals(AuthenticationType.GSS, result.getProperty("authType"));
    // doesn't match gss pattern
    metadata.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties(null, "name1");
    result = impl.logon(p);
    assertEquals("anonymous", result.getUserName());
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LogonException(org.teiid.client.security.LogonException) LogonResult(org.teiid.client.security.LogonResult) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Aggregations

DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)18 CommandContext (org.teiid.query.util.CommandContext)10 Test (org.junit.Test)8 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)5 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)5 List (java.util.List)4 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)4 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 DataPolicy (org.teiid.adminapi.DataPolicy)3 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)3 PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)3 LogonResult (org.teiid.client.security.LogonResult)3 Subject (javax.security.auth.Subject)2 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 VDBRepository (org.teiid.deployers.VDBRepository)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1