Search in sources :

Example 6 with SessionMetadata

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

the class TestArrayProcessing method testLargeArrays.

@Test(expected = TeiidProcessingException.class)
public void testLargeArrays() throws Exception {
    // $NON-NLS-1$
    String sql = "WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 70000 ) SELECT array_agg((n, n, n, n, n)) FROM t;";
    List<?>[] expected = new List[] { Arrays.asList(2080l) };
    FakeDataManager dataManager = new FakeDataManager();
    dataManager.setBlockOnce();
    sampleData1(dataManager);
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached());
    CommandContext cc = createCommandContext();
    cc.setSession(new SessionMetadata());
    cc.setSessionVariable(TempTableStore.TEIID_MAX_RECURSION, 100000);
    helpProcess(plan, cc, dataManager, expected);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with SessionMetadata

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

the class TempTableDataManager method createTemporarySession.

/**
 * Create an unauthenticated session
 * @param userName
 * @param app
 * @param vdb
 * @return
 */
public static SessionMetadata createTemporarySession(String userName, String app, VDBMetaData vdb) {
    long creationTime = System.currentTimeMillis();
    SessionMetadata newSession = new SessionMetadata();
    newSession.setSessionToken(new SessionToken(userName));
    newSession.setSessionId(newSession.getSessionToken().getSessionID());
    newSession.setUserName(userName);
    newSession.setCreatedTime(creationTime);
    newSession.setApplicationName(app);
    newSession.setVDBName(vdb.getName());
    newSession.setVDBVersion(vdb.getVersion());
    newSession.setVdb(vdb);
    newSession.setEmbedded(true);
    return newSession;
}
Also used : SessionToken(org.teiid.client.security.SessionToken) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata)

Example 8 with SessionMetadata

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

the class TestJBossSecurityHelper method validateSession.

public void validateSession(boolean securityEnabled) throws Exception {
    final ArrayList<String> domains = new ArrayList<String>();
    domains.add("somedomain");
    AuthenticationManager authManager = Mockito.mock(AuthenticationManager.class);
    Mockito.stub(authManager.isValid(new SimplePrincipal("steve"), "pass1", new Subject())).toReturn(true);
    final SecurityDomainContext securityContext = new SecurityDomainContext(authManager, null, null, null, null, null);
    SessionServiceImpl jss = new SessionServiceImpl() {

        @Override
        protected VDBMetaData getActiveVDB(String vdbName, String vdbVersion) throws SessionServiceException {
            return Mockito.mock(VDBMetaData.class);
        }
    };
    jss.setSecurityHelper(buildSecurityHelper("somedomain", securityContext));
    jss.setSecurityDomain("somedomain");
    try {
        jss.validateSession(String.valueOf(1));
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    SessionMetadata info = jss.createSession("x", "1", AuthenticationType.USERPASSWORD, "steve", new Credentials("pass1".toCharArray()), "foo", new Properties());
    if (securityEnabled) {
        Mockito.verify(authManager).isValid(new SimplePrincipal("steve"), "pass1", new Subject());
    }
    String id1 = info.getSessionId();
    jss.validateSession(id1);
    assertEquals(1, jss.getActiveSessionsCount());
    // $NON-NLS-1$
    assertEquals(0, jss.getSessionsLoggedInToVDB(new VDBKey("a", 1)).size());
    jss.closeSession(id1);
    try {
        jss.validateSession(id1);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
    try {
        jss.closeSession(id1);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionServiceImpl(org.teiid.services.SessionServiceImpl) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Subject(javax.security.auth.Subject) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) AuthenticationManager(org.jboss.security.AuthenticationManager) VDBKey(org.teiid.vdb.runtime.VDBKey) SimplePrincipal(org.jboss.security.SimplePrincipal) Credentials(org.teiid.security.Credentials)

Example 9 with SessionMetadata

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

the class TestSessionMetadata method testMapping.

@Test
public void testMapping() {
    SessionMetadata session = new SessionMetadata();
    session.setSessionId("test");
    session.setApplicationName("foo");
    session.setClientHostName("localhost");
    session.setCreatedTime(1234);
    session.setIPAddress("127.0.0.1");
    session.setVDBName("vdb-name");
    session.setVDBVersion(2);
    session.setSecurityContext("auth-domain");
    session.setUserName("user");
    ModelNode node = VDBMetadataMapper.SessionMetadataMapper.INSTANCE.wrap(session, new ModelNode());
    SessionMetadata session1 = VDBMetadataMapper.SessionMetadataMapper.INSTANCE.unwrap(node);
    assertEquals(session.getSessionId(), session1.getSessionId());
    assertEquals(session.getApplicationName(), session1.getApplicationName());
}
Also used : SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 10 with SessionMetadata

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

the class DQPCoreService method start.

@Override
public void start(final StartContext context) {
    this.transactionServerImpl.setWorkManager(getWorkManagerInjector().getValue());
    this.transactionServerImpl.setXaTerminator(getXaTerminatorInjector().getValue());
    this.transactionServerImpl.setTransactionManager(getTxnManagerInjector().getValue());
    this.transactionServerImpl.setDetectTransactions(true);
    setPreParser(preParserInjector.getValue());
    setAuthorizationValidator(authorizationValidatorInjector.getValue());
    this.dqpCore.setBufferManager(bufferManagerInjector.getValue());
    this.dqpCore.setTransactionService((TransactionService) LogManager.createLoggingProxy(LogConstants.CTX_TXN_LOG, transactionServerImpl, new Class[] { TransactionService.class }, MessageLevel.DETAIL, Thread.currentThread().getContextClassLoader()));
    this.dqpCore.setEventDistributor(getEventDistributorFactoryInjector().getValue().getReplicatedEventDistributor());
    this.dqpCore.setResultsetCache(getResultSetCacheInjector().getValue());
    this.dqpCore.setPreparedPlanCache(getPreparedPlanCacheInjector().getValue());
    this.dqpCore.start(this);
    // add vdb life cycle listeners
    getVdbRepository().addListener(new VDBLifeCycleListener() {

        @Override
        public void removed(String name, CompositeVDB vdb) {
            // terminate all the previous sessions
            SessionService sessionService = (SessionService) context.getController().getServiceContainer().getService(TeiidServiceNames.SESSION).getValue();
            Collection<SessionMetadata> sessions = sessionService.getSessionsLoggedInToVDB(vdb.getVDBKey());
            for (SessionMetadata session : sessions) {
                sessionService.terminateSession(session.getSessionId(), null);
            }
            // dump the caches.
            try {
                SessionAwareCache<?> value = getResultSetCacheInjector().getValue();
                if (value != null) {
                    value.clearForVDB(vdb.getVDBKey());
                }
                value = getPreparedPlanCacheInjector().getValue();
                if (value != null) {
                    value.clearForVDB(vdb.getVDBKey());
                }
            } catch (IllegalStateException e) {
            // already shutdown
            }
        }

        @Override
        public void added(String name, CompositeVDB vdb) {
        }

        @Override
        public void finishedDeployment(String name, CompositeVDB cvdb) {
        }

        @Override
        public void beforeRemove(String name, CompositeVDB cvdb) {
        }
    });
    LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50001, this.dqpCore.getRuntimeVersion(), new Date(System.currentTimeMillis()).toString()));
}
Also used : SessionService(org.teiid.dqp.service.SessionService) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) CompositeVDB(org.teiid.deployers.CompositeVDB) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) Collection(java.util.Collection) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener) Date(java.util.Date)

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