Search in sources :

Example 1 with InvalidSessionException

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;
            }
        }
    }));
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) CommunicationException(org.teiid.net.CommunicationException) Method(java.lang.reflect.Method) ILogon(org.teiid.client.security.ILogon) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) SocketException(java.net.SocketException) CommunicationException(org.teiid.net.CommunicationException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ConnectionException(org.teiid.net.ConnectionException) ConnectionException(org.teiid.net.ConnectionException)

Example 2 with InvalidSessionException

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());
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SQLException(java.sql.SQLException) ServerConnection(org.teiid.net.ServerConnection) Connection(java.sql.Connection) ConnectionEventListener(javax.sql.ConnectionEventListener) Test(org.junit.Test)

Example 3 with InvalidSessionException

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);
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) Method(java.lang.reflect.Method)

Example 4 with 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);
    }
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Subject(javax.security.auth.Subject) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) SecurityHelper(org.teiid.security.SecurityHelper) Test(org.junit.Test)

Example 5 with InvalidSessionException

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);
    }
}
Also used : LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) TeiidProcessingException(org.teiid.core.TeiidProcessingException) LogonException(org.teiid.client.security.LogonException) ExecutionException(java.util.concurrent.ExecutionException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) DQP(org.teiid.client.DQP) CommunicationException(org.teiid.net.CommunicationException) SessionToken(org.teiid.client.security.SessionToken) ILogon(org.teiid.client.security.ILogon) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) CommunicationException(org.teiid.net.CommunicationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(org.teiid.net.ConnectionException) ResultsFuture(org.teiid.client.util.ResultsFuture) TeiidComponentException(org.teiid.core.TeiidComponentException) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Aggregations

InvalidSessionException (org.teiid.client.security.InvalidSessionException)11 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)5 LogonException (org.teiid.client.security.LogonException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 Properties (java.util.Properties)3 Test (org.junit.Test)3 SessionToken (org.teiid.client.security.SessionToken)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 UnknownHostException (java.net.UnknownHostException)2 Connection (java.sql.Connection)2 Subject (javax.security.auth.Subject)2 ILogon (org.teiid.client.security.ILogon)2 LogonResult (org.teiid.client.security.LogonResult)2 ResultsFuture (org.teiid.client.util.ResultsFuture)2 SessionServiceException (org.teiid.dqp.service.SessionServiceException)2 CommunicationException (org.teiid.net.CommunicationException)2 ConnectionException (org.teiid.net.ConnectionException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetSocketAddress (java.net.InetSocketAddress)1