use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.
the class SocketServerConnection method getService.
public <T> T getService(Class<T> iface) {
return iface.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { iface }, new SocketServerInstanceImpl.RemoteInvocationHandler(iface, PropertiesUtils.getBooleanProperty(connProps, TeiidURL.CONNECTION.ENCRYPT_REQUESTS, false)) {
@Override
protected SocketServerInstance getInstance() throws CommunicationException {
if (failOver && System.currentTimeMillis() - lastPing > pingFailOverInterval) {
try {
ResultsFuture<?> future = selectServerInstance(false).getService(ILogon.class).ping();
future.get();
} catch (SingleInstanceCommunicationException e) {
closeServerInstance();
} catch (CommunicationException e) {
throw e;
} catch (InvalidSessionException e) {
disconnect();
closeServerInstance();
} catch (Exception e) {
closeServerInstance();
}
}
lastPing = System.currentTimeMillis();
try {
return selectServerInstance(false);
} catch (ConnectionException e) {
throw new CommunicationException(e);
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
return super.invoke(proxy, method, args);
} catch (Exception e) {
if (ExceptionUtil.getExceptionOfType(e, InvalidSessionException.class) != null) {
disconnect();
}
throw e;
}
}
}));
}
use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.
the class TestXAConnection method testNotification.
@Test
public void testNotification() throws Exception {
ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
Mockito.doThrow(new SQLException(new InvalidSessionException())).when(conn).commit();
XAConnectionImpl xaConn = new XAConnectionImpl(conn);
ConnectionEventListener cel = Mockito.mock(ConnectionEventListener.class);
xaConn.addConnectionEventListener(cel);
Connection c = xaConn.getConnection();
try {
c.commit();
} catch (SQLException e) {
}
Mockito.verify(cel).connectionErrorOccurred((ConnectionEvent) Mockito.anyObject());
}
use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.
the class TestSocketServiceRegistry method testSubclass.
public void testSubclass() throws Exception {
Method m = DQP.class.getMethod("getMetadata", new Class[] { Long.TYPE });
Throwable t = ExceptionUtil.convertException(m, new InvalidSessionException());
assertTrue(t instanceof InvalidSessionException);
}
use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.
the class TestLocalConnections method testPassThroughDifferentUsers.
@Test
public void testPassThroughDifferentUsers() throws Throwable {
MockSecurityHelper securityHelper = new MockSecurityHelper();
SecurityHelper current = server.getSessionService().getSecurityHelper();
server.getClientServiceRegistry().setSecurityHelper(securityHelper);
server.getSessionService().setSecurityHelper(securityHelper);
try {
final Connection c = server.createConnection("jdbc:teiid:PartsSupplier;PassthroughAuthentication=true");
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select session_id()");
Subject o = currentContext;
currentContext = null;
s.cancel();
currentContext = o;
rs.next();
String id = rs.getString(1);
rs.close();
assertEquals(4, securityHelper.calls);
server.getSessionService().pingServer(id);
currentContext = new Subject();
currentContext.getPrincipals().add(new SimplePrincipal("x"));
rs = s.executeQuery("select session_id()");
rs.next();
String id1 = rs.getString(1);
rs.close();
assertFalse(id.equals(id1));
try {
server.getSessionService().pingServer(id);
// should have logged off
fail();
} catch (InvalidSessionException e) {
}
} finally {
server.getClientServiceRegistry().setSecurityHelper(current);
server.getSessionService().setSecurityHelper(current);
}
}
use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.
the class TestSocketRemoting method testMethodInvocation.
@Test
public void testMethodInvocation() throws Exception {
ClientServiceRegistryImpl csr = new ClientServiceRegistryImpl() {
@Override
public ClassLoader getCallerClassloader() {
return getClass().getClassLoader();
}
};
csr.registerClientService(ILogon.class, new ILogon() {
public ResultsFuture<?> logoff() throws InvalidSessionException {
ResultsFuture<?> result = new ResultsFuture<Void>();
// $NON-NLS-1$
result.getResultsReceiver().exceptionOccurred(new TeiidComponentException("some exception"));
return result;
}
public LogonResult logon(Properties connectionProperties) throws LogonException, TeiidComponentException {
return new LogonResult();
}
// tests asynch where we don't care about the result
public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
return null;
}
@Override
public ResultsFuture<?> ping(Collection<String> sessions) throws TeiidComponentException, CommunicationException {
return null;
}
@Override
public void assertIdentity(SessionToken sessionId) throws InvalidSessionException, TeiidComponentException {
}
@Override
public LogonResult neogitiateGssLogin(Properties connectionProperties, byte[] serviceToken, boolean createSession) throws LogonException {
return null;
}
}, // $NON-NLS-1$
"foo");
// $NON-NLS-1$
csr.registerClientService(FakeService.class, new FakeServiceImpl(), "foo");
final FakeClientServerInstance serverInstance = new FakeClientServerInstance(csr);
SocketServerConnection connection = createFakeConnection(serverInstance);
ILogon logon = connection.getService(ILogon.class);
Future<?> result = logon.ping();
assertNull(result.get(0, TimeUnit.MILLISECONDS));
result = logon.logoff();
try {
result.get(0, TimeUnit.MICROSECONDS);
// $NON-NLS-1$
fail("exception expected");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof TeiidComponentException);
}
FakeService service = connection.getService(FakeService.class);
Future<Integer> asynchInteger = service.asynchResult();
assertEquals(new Integer(5), asynchInteger.get(0, TimeUnit.MILLISECONDS));
try {
service.exceptionMethod();
// $NON-NLS-1$
fail("exception expected");
} catch (TeiidProcessingException e) {
}
DQP dqp = connection.getService(DQP.class);
try {
ResultsFuture<?> future = dqp.begin();
future.get();
// $NON-NLS-1$
fail("exception expected");
} catch (Exception e) {
// $NON-NLS-1$
assertTrue(e.getMessage().indexOf("Component not found:") != -1);
}
}
Aggregations