Search in sources :

Example 16 with CommunicationException

use of org.teiid.net.CommunicationException in project teiid by teiid.

the class TestCommSockets method testAnonSSLConnect.

@Test
public void testAnonSSLConnect() throws Exception {
    SSLContext context = SSLContext.getDefault();
    String[] ciphers = context.getServerSocketFactory().getSupportedCipherSuites();
    if (!Arrays.asList(ciphers).contains(SocketUtil.ANON_CIPHER_SUITE)) {
        // Cannot test anon if no cipher suite is available
        return;
    }
    SSLConfiguration config = new SSLConfiguration();
    config.setMode(SSLConfiguration.ENABLED);
    // ensure that this cipher suite is not used
    config.setEnabledCipherSuites("x");
    config.setAuthenticationMode(SSLConfiguration.ANONYMOUS);
    Properties p = new Properties();
    helpEstablishConnection(true, config, p);
    SocketServerConnection conn = helpEstablishConnection(true, config, p);
    conn.close();
    try {
        helpEstablishConnection(false, config, p);
        fail();
    } catch (CommunicationException e) {
    }
}
Also used : CommunicationException(org.teiid.net.CommunicationException) SSLContext(javax.net.ssl.SSLContext) Properties(java.util.Properties) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Example 17 with CommunicationException

use of org.teiid.net.CommunicationException in project teiid by teiid.

the class TestCommSockets method testSSLConnectWithNonSSLServer.

@Test
public void testSSLConnectWithNonSSLServer() throws Exception {
    // first make a non-ssl connection to ensure that it's not reused
    SocketServerConnection conn = helpEstablishConnection(false);
    conn.close();
    try {
        helpEstablishConnection(true);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (CommunicationException e) {
    }
}
Also used : CommunicationException(org.teiid.net.CommunicationException) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Example 18 with CommunicationException

use of org.teiid.net.CommunicationException in project teiid by teiid.

the class SocketClientInstance method receivedHahdshake.

private void receivedHahdshake(Handshake handshake) throws CommunicationException {
    String clientVersion = handshake.getVersion();
    this.workContext.setClientVersion(Version.getVersion(clientVersion));
    if (usingEncryption) {
        byte[] returnedPublicKey = handshake.getPublicKey();
        byte[] returnedPublicKeyLarge = handshake.getPublicKeyLarge();
        boolean large = false;
        // ensure the key information
        if (returnedPublicKey == null) {
            if (returnedPublicKeyLarge == null) {
                throw new CommunicationException(RuntimePlugin.Event.TEIID40052, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40052));
            }
            large = true;
            returnedPublicKey = returnedPublicKeyLarge;
        }
        if (LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL)) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            LogManager.logDetail(LogConstants.CTX_TRANSPORT, large ? "2048" : "1024", "key exchange being used.");
        }
        boolean useCbc = handshake.isCbc();
        try {
            // $NON-NLS-1$
            this.cryptor = keyGen.getSymmetricCryptor(returnedPublicKey, "08.03".compareTo(clientVersion) > 0, SocketClientInstance.class.getClassLoader(), large, useCbc);
        } catch (CryptoException e) {
            throw new CommunicationException(RuntimePlugin.Event.TEIID40053, e);
        }
        this.keyGen = null;
    } else {
        this.cryptor = new NullCryptor();
    }
}
Also used : CommunicationException(org.teiid.net.CommunicationException) CryptoException(org.teiid.core.crypto.CryptoException) NullCryptor(org.teiid.core.crypto.NullCryptor)

Example 19 with CommunicationException

use of org.teiid.net.CommunicationException in project teiid by teiid.

the class SocketClientInstance method onConnection.

public void onConnection() throws CommunicationException {
    Handshake handshake = new Handshake();
    handshake.setAuthType(csr.getAuthenticationType());
    if (usingEncryption) {
        keyGen = new DhKeyGenerator();
        byte[] publicKey;
        try {
            handshake.setPublicKeyLarge(keyGen.createPublicKey(true));
        } catch (CryptoException e) {
        // not supported on this platform
        }
        try {
            publicKey = keyGen.createPublicKey(false);
        } catch (CryptoException e) {
            throw new CommunicationException(RuntimePlugin.Event.TEIID40051, e);
        }
        handshake.setPublicKey(publicKey);
    }
    this.objectSocket.write(handshake);
}
Also used : CommunicationException(org.teiid.net.CommunicationException) DhKeyGenerator(org.teiid.core.crypto.DhKeyGenerator) CryptoException(org.teiid.core.crypto.CryptoException) Handshake(org.teiid.net.socket.Handshake)

Example 20 with CommunicationException

use of org.teiid.net.CommunicationException in project teiid by teiid.

the class TestJDBCSocketTransport method testSyncTimeout.

/**
 * Tests to ensure that a SynchronousTtl/synchTimeout does
 * not cause a cancel.
 * TODO: had to increase the values since the test would fail on slow machine runs
 * @throws Exception
 */
@Test
public void testSyncTimeout() throws Exception {
    TeiidDriver td = new TeiidDriver();
    td.setSocketProfile(new ConnectionProfile() {

        @Override
        public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
            SocketServerConnectionFactory sscf = new SocketServerConnectionFactory();
            sscf.initialize(info);
            try {
                return new ConnectionImpl(sscf.getConnection(info), info, url);
            } catch (CommunicationException e) {
                throw TeiidSQLException.create(e);
            } catch (ConnectionException e) {
                throw TeiidSQLException.create(e);
            }
        }
    });
    Properties p = new Properties();
    p.setProperty("user", "testuser");
    p.setProperty("password", "testpassword");
    ConnectorManagerRepository cmr = server.getConnectorManagerRepository();
    AutoGenDataService agds = new AutoGenDataService() {

        @Override
        public Object getConnectionFactory() throws TranslatorException {
            return null;
        }
    };
    // wait longer than the synch ttl/soTimeout, we should still succeed
    agds.setSleep(2000);
    cmr.addConnectorManager("source", agds);
    try {
        conn = td.connect("jdbc:teiid:parts@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), p);
        Statement s = conn.createStatement();
        assertTrue(s.execute("select * from parts"));
    } finally {
        server.setConnectorManagerRepository(cmr);
    }
}
Also used : SocketServerConnectionFactory(org.teiid.net.socket.SocketServerConnectionFactory) CommunicationException(org.teiid.net.CommunicationException) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) TeiidDriver(org.teiid.jdbc.TeiidDriver) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService) ConnectionException(org.teiid.net.ConnectionException) Test(org.junit.Test)

Aggregations

CommunicationException (org.teiid.net.CommunicationException)20 Test (org.junit.Test)9 ConnectionException (org.teiid.net.ConnectionException)9 IOException (java.io.IOException)7 ILogon (org.teiid.client.security.ILogon)6 LogonException (org.teiid.client.security.LogonException)6 TeiidComponentException (org.teiid.core.TeiidComponentException)6 Properties (java.util.Properties)5 TeiidException (org.teiid.core.TeiidException)5 UnknownHostException (java.net.UnknownHostException)4 InvalidSessionException (org.teiid.client.security.InvalidSessionException)4 SocketException (java.net.SocketException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 CryptoException (org.teiid.core.crypto.CryptoException)3 NullCryptor (org.teiid.core.crypto.NullCryptor)3 TeiidURL (org.teiid.net.TeiidURL)3 SocketServerConnection (org.teiid.net.socket.SocketServerConnection)3 ConnectException (java.net.ConnectException)2 MalformedURLException (java.net.MalformedURLException)2 DQP (org.teiid.client.DQP)2