Search in sources :

Example 1 with LogonImpl

use of org.teiid.transport.LogonImpl in project teiid by teiid.

the class TransportService method start.

@Override
public void start(StartContext context) throws StartException {
    this.setVDBRepository(this.getVdbRepository());
    SessionService ss = sessionServiceInjector.getValue();
    this.setSecurityHelper(ss.getSecurityHelper());
    // create the necessary services
    // $NON-NLS-1$
    this.logon = new LogonImpl(ss, "teiid-cluster");
    DQP dqpProxy = proxyService(DQP.class, getDQP(), LogConstants.CTX_DQP);
    this.registerClientService(ILogon.class, logon, LogConstants.CTX_SECURITY);
    this.registerClientService(DQP.class, dqpProxy, LogConstants.CTX_DQP);
    this.setAuthenticationType(ss.getDefaultAuthenticationType());
    if (this.socketConfig != null) {
        /*
    		try {
				// this is to show the bound socket port in the JMX console
				SocketBinding socketBinding = getSocketBindingInjector().getValue();
				ManagedServerSocketBinding ss = (ManagedServerSocketBinding)socketBinding.getSocketBindings().getServerSocketFactory().createServerSocket(socketBinding.getName());
				socketBinding.getSocketBindings().getNamedRegistry().registerBinding(ss);
			}  catch (IOException e) {
				throw new StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50013));
			}
    		*/
        this.address = getSocketBindingInjector().getValue().getSocketAddress();
        this.socketConfig.setBindAddress(this.address.getHostName());
        this.socketConfig.setPortNumber(this.address.getPort());
        boolean sslEnabled = false;
        if (this.socketConfig.getSSLConfiguration() != null) {
            sslEnabled = this.socketConfig.getSSLConfiguration().isSslEnabled();
        }
        if (socketConfig.getProtocol() == WireProtocol.teiid) {
            this.socketListener = new SocketListener(address, this.socketConfig, this, getBufferManagerInjector().getValue());
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50012, this.transportName, address.getHostName(), String.valueOf(address.getPort()), (sslEnabled ? "ON" : "OFF")));
        } else if (socketConfig.getProtocol() == WireProtocol.pg) {
            TeiidDriver driver = new TeiidDriver();
            driver.setLocalProfile(new ConnectionProfile() {

                @Override
                public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
                    try {
                        LocalServerConnection sc = new LocalServerConnection(info, true) {

                            @Override
                            protected ClientServiceRegistry getClientServiceRegistry(String name) {
                                return TransportService.this;
                            }
                        };
                        return new ConnectionImpl(sc, info, url);
                    } catch (CommunicationException e) {
                        throw TeiidSQLException.create(e);
                    } catch (ConnectionException e) {
                        throw TeiidSQLException.create(e);
                    }
                }
            });
            ODBCSocketListener odbc = new ODBCSocketListener(address, this.socketConfig, this, getBufferManagerInjector().getValue(), getMaxODBCLobSizeAllowed(), this.logon, driver);
            this.socketListener = odbc;
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50037, this.transportName, address.getHostName(), String.valueOf(address.getPort()), (sslEnabled ? "ON" : "OFF")));
        } else {
            throw new StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50013));
        }
    } else {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50038, LocalServerConnection.jndiNameForRuntime(transportName)));
    }
}
Also used : DQP(org.teiid.client.DQP) CommunicationException(org.teiid.net.CommunicationException) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) SessionService(org.teiid.dqp.service.SessionService) LogonImpl(org.teiid.transport.LogonImpl) SocketListener(org.teiid.transport.SocketListener) ODBCSocketListener(org.teiid.transport.ODBCSocketListener) TeiidDriver(org.teiid.jdbc.TeiidDriver) StartException(org.jboss.msc.service.StartException) LocalServerConnection(org.teiid.transport.LocalServerConnection) ODBCSocketListener(org.teiid.transport.ODBCSocketListener) ConnectionException(org.teiid.net.ConnectionException)

Example 2 with LogonImpl

use of org.teiid.transport.LogonImpl in project teiid by teiid.

the class TestLocalConnections method testSimulateGSSWithODBC.

@Test
public void testSimulateGSSWithODBC() throws Throwable {
    SecurityHelper securityHelper = new MockSecurityHelper();
    SecurityHelper current = server.getSessionService().getSecurityHelper();
    server.getClientServiceRegistry().setSecurityHelper(securityHelper);
    server.getSessionService().setSecurityHelper(securityHelper);
    server.getSessionService().setAuthenticationType(AuthenticationType.GSS);
    final byte[] token = "This is test of Partial GSS API".getBytes();
    final AtomicBoolean set = new AtomicBoolean(true);
    LogonImpl login = new LogonImpl(server.getSessionService(), null) {

        @Override
        public LogonResult logon(Properties connProps) throws LogonException {
            if (set.get()) {
                this.gssServiceTickets.put(Base64.encodeBytes(MD5(token)), currentContext);
                set.set(false);
            }
            return super.logon(connProps);
        }
    };
    server.getClientServiceRegistry().registerClientService(ILogon.class, login, LogConstants.CTX_SECURITY);
    try {
        Properties prop = new Properties();
        prop.put(ILogon.KRB5TOKEN, token);
        final Connection c = server.createConnection("jdbc:teiid:PartsSupplier;user=GSS", prop);
        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();
    } finally {
        server.getSessionService().setAuthenticationType(AuthenticationType.USERPASSWORD);
        server.getClientServiceRegistry().setSecurityHelper(current);
        server.getSessionService().setSecurityHelper(current);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogonImpl(org.teiid.transport.LogonImpl) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Properties(java.util.Properties) Subject(javax.security.auth.Subject) SecurityHelper(org.teiid.security.SecurityHelper) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)2 LogonImpl (org.teiid.transport.LogonImpl)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Subject (javax.security.auth.Subject)1 StartException (org.jboss.msc.service.StartException)1 Test (org.junit.Test)1 DQP (org.teiid.client.DQP)1 SessionService (org.teiid.dqp.service.SessionService)1 ConnectionImpl (org.teiid.jdbc.ConnectionImpl)1 ConnectionProfile (org.teiid.jdbc.ConnectionProfile)1 TeiidDriver (org.teiid.jdbc.TeiidDriver)1 CommunicationException (org.teiid.net.CommunicationException)1 ConnectionException (org.teiid.net.ConnectionException)1 SecurityHelper (org.teiid.security.SecurityHelper)1 LocalServerConnection (org.teiid.transport.LocalServerConnection)1 ODBCSocketListener (org.teiid.transport.ODBCSocketListener)1 SocketListener (org.teiid.transport.SocketListener)1