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