Search in sources :

Example 16 with DQPWorkContext

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

the class TestLogonImpl method testLogonResult.

@Test
public void testLogonResult() throws Exception {
    SessionService ssi = Mockito.mock(SessionService.class);
    Mockito.stub(ssi.getAuthenticationType(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).toReturn(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    String userName = "Fred";
    // $NON-NLS-1$
    String applicationName = "test";
    Properties p = new Properties();
    p.setProperty(TeiidURL.CONNECTION.USER_NAME, userName);
    p.setProperty(TeiidURL.CONNECTION.APP_NAME, applicationName);
    p.setProperty(TeiidURL.JDBC.VDB_NAME, "x");
    p.setProperty(TeiidURL.JDBC.VDB_VERSION, "1");
    SessionMetadata session = new SessionMetadata();
    session.setUserName(userName);
    session.setApplicationName(applicationName);
    session.setSessionId(String.valueOf(1));
    session.setSessionToken(new SessionToken(1, userName));
    Mockito.stub(ssi.createSession("x", "1", AuthenticationType.USERPASSWORD, userName, null, applicationName, p)).toReturn(session);
    // $NON-NLS-1$
    LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
    LogonResult result = impl.logon(p);
    assertEquals(userName, result.getUserName());
    assertEquals(String.valueOf(1), result.getSessionID());
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionService(org.teiid.dqp.service.SessionService) SessionToken(org.teiid.client.security.SessionToken) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) Test(org.junit.Test)

Example 17 with DQPWorkContext

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

the class SessionCheckingProxy method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Throwable exception = null;
    try {
        DQPWorkContext workContext = DQPWorkContext.getWorkContext();
        if (workContext.getSession().isClosed() || workContext.getSessionId() == null) {
            if (method.getName().equals("closeRequest")) {
                // there's no need for this to raise an exception
                return ResultsFuture.NULL_FUTURE;
            }
            String sessionID = workContext.getSession().getSessionId();
            if (sessionID == null) {
                throw new InvalidSessionException(RuntimePlugin.Event.TEIID40041, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40041));
            }
            workContext.setSession(new SessionMetadata());
            throw new InvalidSessionException(RuntimePlugin.Event.TEIID40042, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40042, sessionID));
        }
        return super.invoke(proxy, method, args);
    } catch (InvocationTargetException e) {
        exception = e.getTargetException();
    } catch (Throwable t) {
        exception = t;
    }
    throw ExceptionUtil.convertException(method, exception);
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with DQPWorkContext

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

the class LogonImpl method updateDQPContext.

private void updateDQPContext(SessionMetadata s) {
    DQPWorkContext workContext = DQPWorkContext.getWorkContext();
    SessionMetadata old = workContext.getSession();
    if (old.getSessionId() != null) {
        old.setActive(false);
    }
    workContext.setSession(s);
    if (s.getSessionId() != null) {
        s.setActive(true);
    }
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata)

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