Search in sources :

Example 16 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class ODBCServerRemoteImpl method logon.

@Override
public void logon(String databaseName, String user, NullTerminatedStringDataInputStream data, SocketAddress remoteAddress) {
    try {
        java.util.Properties info = new java.util.Properties();
        info.put(TeiidURL.CONNECTION.USER_NAME, user);
        AuthenticationType authType = getAuthenticationType(user, databaseName);
        String password = null;
        if (authType.equals(AuthenticationType.USERPASSWORD)) {
            password = data.readString();
        } else if (authType.equals(AuthenticationType.GSS)) {
            byte[] serviceToken = data.readServiceToken();
            GSSResult result = this.logon.neogitiateGssLogin(serviceToken, databaseName, null, user);
            serviceToken = result.getServiceToken();
            if (result.isAuthenticated()) {
                info.put(ILogon.KRB5TOKEN, serviceToken);
                if (!result.isNullContinuationToken()) {
                    this.client.authenticationGSSContinue(serviceToken);
                }
                // if delegation is in progress, participate in it.
                if (result.getDelegationCredential() != null) {
                    info.put(GSSCredential.class.getName(), result.getDelegationCredential());
                }
            } else {
                this.client.authenticationGSSContinue(serviceToken);
                return;
            }
        } else {
            // $NON-NLS-1$
            throw new AssertionError("Unsupported Authentication Type");
        }
        // this is local connection
        // $NON-NLS-1$
        String url = "jdbc:teiid:" + databaseName;
        if (password != null) {
            info.put(TeiidURL.CONNECTION.PASSWORD, password);
        }
        String applicationName = this.props.getProperty(PgBackendProtocol.APPLICATION_NAME);
        if (applicationName == null) {
            applicationName = PgBackendProtocol.DEFAULT_APPLICATION_NAME;
            this.props.put(PgBackendProtocol.APPLICATION_NAME, applicationName);
        }
        info.put(TeiidURL.CONNECTION.APP_NAME, applicationName);
        if (remoteAddress instanceof InetSocketAddress) {
            SocketServerConnection.updateConnectionProperties(info, ((InetSocketAddress) remoteAddress).getAddress(), false);
        }
        this.connection = driver.connect(url, info);
        // Propagate so that we can use in pg methods
        SessionMetadata sm = ((LocalServerConnection) this.connection.getServerConnection()).getWorkContext().getSession();
        sm.addAttchment(ODBCServerRemoteImpl.class, this);
        setConnectionProperties(this.connection);
        int hash = this.connection.getConnectionId().hashCode();
        Enumeration<?> keys = this.props.propertyNames();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            this.connection.setExecutionProperty(key, this.props.getProperty(key));
        }
        StatementImpl s = this.connection.createStatement();
        try {
            // $NON-NLS-1$
            s.execute("select teiid_session_set('resolve_groupby_positional', true)");
        } finally {
            s.close();
        }
        this.client.authenticationSucess(hash, hash);
        ready();
    } catch (SQLException e) {
        errorOccurred(e);
        terminate();
    } catch (LogonException e) {
        errorOccurred(e);
        terminate();
    } catch (IOException e) {
        errorOccurred(e);
        terminate();
    }
}
Also used : Properties(java.util.Properties) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) SQLException(java.sql.SQLException) InetSocketAddress(java.net.InetSocketAddress) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) IOException(java.io.IOException) Properties(java.util.Properties) GSSResult(org.teiid.security.GSSResult) PreparedStatementImpl(org.teiid.jdbc.PreparedStatementImpl) StatementImpl(org.teiid.jdbc.StatementImpl) LogonException(org.teiid.client.security.LogonException) AuthenticationType(org.teiid.net.socket.AuthenticationType)

Example 17 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class TempTableDataManager method createWorkContext.

private DQPWorkContext createWorkContext(final CommandContext context, VDBMetaData vdb) {
    // $NON-NLS-1$
    SessionMetadata session = createTemporarySession(context.getUserName(), "asynch-mat-view-load", vdb);
    session.setSubject(context.getSubject());
    session.setSecurityDomain(context.getSession().getSecurityDomain());
    session.setSecurityContext(context.getSession().getSecurityContext());
    DQPWorkContext workContext = new DQPWorkContext();
    workContext.setAdmin(true);
    DQPWorkContext current = context.getDQPWorkContext();
    workContext.setSession(session);
    workContext.setPolicies(current.getAllowedDataPolicies());
    workContext.setSecurityHelper(current.getSecurityHelper());
    return workContext;
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata)

Example 18 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class TestBufferManagerImpl method testTupleBufferSessionMax.

@Test
public void testTupleBufferSessionMax() throws Exception {
    BufferManagerImpl bufferManager = new BufferManagerImpl();
    bufferManager.setCache(new MemoryStorageManager() {

        @Override
        public long getMaxStorageSpace() {
            return 64000;
        }
    });
    bufferManager.setMaxReserveKB(10);
    bufferManager.setMaxActivePlans(10);
    bufferManager.setOptions(new Options().maxSessionBufferSizeEstimate(100000));
    bufferManager.initialize();
    CommandContext context = new CommandContext();
    context.setSession(new SessionMetadata());
    CommandContext.pushThreadLocalContext(context);
    try {
        List<TupleBuffer> tupleBuffers = new ArrayList<TupleBuffer>();
        for (int i = 0; i < 36; i++) {
            TupleBuffer tb = bufferManager.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, String.class)), "x", TupleSourceType.PROCESSOR);
            try {
                for (int j = 0; j < 50; j++) {
                    tb.addTuple(Arrays.asList("a"));
                }
                tb.saveBatch();
                if (i % 2 == 0) {
                    tb.remove();
                }
            } catch (TeiidComponentException e) {
                assertEquals(34, i);
                return;
            }
            tupleBuffers.add(tb);
        }
    } finally {
        CommandContext.popThreadLocalContext();
    }
    fail();
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ArrayList(java.util.ArrayList) TeiidComponentException(org.teiid.core.TeiidComponentException) Test(org.junit.Test)

Example 19 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class TestDQPWorkContext method testAnyAuthenticated.

@Test
public void testAnyAuthenticated() {
    DQPWorkContext message = new DQPWorkContext();
    SessionMetadata mock = Mockito.mock(SessionMetadata.class);
    message.setSession(mock);
    VDBMetaData vdb = new VDBMetaData();
    DataPolicyMetadata dpm = new DataPolicyMetadata();
    dpm.setAnyAuthenticated(true);
    vdb.addDataPolicy(dpm);
    Mockito.stub(mock.getVdb()).toReturn(vdb);
    // unauthenticated
    Map<String, DataPolicy> map = message.getAllowedDataPolicies();
    assertEquals(0, map.size());
    // authenticated
    message = new DQPWorkContext();
    Mockito.stub(mock.getSubject()).toReturn(new Subject());
    message.setSession(mock);
    map = message.getAllowedDataPolicies();
    assertEquals(1, map.size());
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) DataPolicy(org.teiid.adminapi.DataPolicy) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 20 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class TestSessionAwareCache method buildWorkContext.

public static DQPWorkContext buildWorkContext() {
    DQPWorkContext workContext = new DQPWorkContext();
    SessionMetadata session = new SessionMetadata();
    workContext.setSession(session);
    // $NON-NLS-1$
    session.setVDBName("vdb-name");
    session.setVDBVersion(1);
    session.setSessionId(String.valueOf(1));
    // $NON-NLS-1$
    session.setUserName("foo");
    return workContext;
}
Also used : SessionMetadata(org.teiid.adminapi.impl.SessionMetadata)

Aggregations

SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)35 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)9 Properties (java.util.Properties)6 InvalidSessionException (org.teiid.client.security.InvalidSessionException)6 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)5 SessionServiceException (org.teiid.dqp.service.SessionServiceException)5 List (java.util.List)4 LoginException (javax.security.auth.login.LoginException)4 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)4 LogonException (org.teiid.client.security.LogonException)4 SessionToken (org.teiid.client.security.SessionToken)4 Credentials (org.teiid.security.Credentials)4 ArrayList (java.util.ArrayList)3 Subject (javax.security.auth.Subject)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 SQLException (java.sql.SQLException)2 LogonResult (org.teiid.client.security.LogonResult)2 CompositeVDB (org.teiid.deployers.CompositeVDB)2 VDBLifeCycleListener (org.teiid.deployers.VDBLifeCycleListener)2