Search in sources :

Example 6 with InvalidSessionException

use of org.teiid.client.security.InvalidSessionException 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 7 with InvalidSessionException

use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.

the class EmbeddedServer method startVDBRepository.

private void startVDBRepository() {
    this.repo.addListener(new VDBLifeCycleListener() {

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

        @Override
        public void removed(String name, CompositeVDB vdb) {
            if (replicator != null) {
                replicator.stop(vdb.getVDB().getAttachment(GlobalTableStore.class));
            }
            rs.clearForVDB(vdb.getVDBKey());
            ppc.clearForVDB(vdb.getVDBKey());
            for (SessionMetadata session : sessionService.getSessionsLoggedInToVDB(vdb.getVDBKey())) {
                try {
                    sessionService.closeSession(session.getSessionId());
                } catch (InvalidSessionException e) {
                }
            }
        }

        @Override
        public void finishedDeployment(String name, CompositeVDB vdb) {
            if (!vdb.getVDB().getStatus().equals(Status.ACTIVE)) {
                return;
            }
            GlobalTableStore gts = CompositeGlobalTableStore.createInstance(vdb, dqp.getBufferManager(), replicator);
            vdb.getVDB().addAttchment(GlobalTableStore.class, gts);
        }

        @Override
        public void beforeRemove(String name, CompositeVDB vdb) {
        }
    });
    this.repo.setSystemFunctionManager(SystemMetadata.getInstance().getSystemFunctionManager());
    this.repo.start();
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) CompositeVDB(org.teiid.deployers.CompositeVDB) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) CompositeGlobalTableStore(org.teiid.deployers.CompositeGlobalTableStore) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener)

Example 8 with InvalidSessionException

use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.

the class SessionServiceImpl method closeSession.

@Override
public void closeSession(String sessionID) throws InvalidSessionException {
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_SECURITY, MessageLevel.DETAIL)) {
        // $NON-NLS-1$
        LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] { "closeSession", sessionID });
    }
    SessionMetadata info = getSessionInfo(sessionID, true);
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_AUDITLOGGING, MessageLevel.DETAIL)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        LogManager.logDetail(LogConstants.CTX_AUDITLOGGING, new AuditMessage("session", "logoff", info));
    }
    if (info.getVDBName() != null) {
        try {
            dqp.terminateSession(info.getSessionId());
        } catch (Exception e) {
            LogManager.logWarning(LogConstants.CTX_SECURITY, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40018));
        }
    }
    info.setSecurityContext(null);
    info.setClosed();
    info.getSessionVariables().clear();
}
Also used : AuditMessage(org.teiid.logging.AuditMessage) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) LoginException(javax.security.auth.login.LoginException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionServiceException(org.teiid.dqp.service.SessionServiceException) LogonException(org.teiid.client.security.LogonException)

Example 9 with InvalidSessionException

use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.

the class TestFailover method createListener.

private SocketListener createListener(InetSocketAddress address, SSLConfiguration config) {
    ClientServiceRegistryImpl server = new ClientServiceRegistryImpl() {

        @Override
        public ClassLoader getCallerClassloader() {
            return getClass().getClassLoader();
        }
    };
    SessionService ss = mock(SessionService.class);
    server.registerClientService(ILogon.class, new // $NON-NLS-1$
    LogonImpl(// $NON-NLS-1$
    ss, // $NON-NLS-1$
    "fakeCluster") {

        @Override
        public LogonResult logon(Properties connProps) throws LogonException {
            logonAttempts++;
            return new LogonResult(new SessionToken("dummy"), "x", "z");
        }

        @Override
        public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
            return ResultsFuture.NULL_FUTURE;
        }

        @Override
        public void assertIdentity(SessionToken checkSession) throws InvalidSessionException, TeiidComponentException {
            throw new InvalidSessionException();
        }
    }, null);
    server.registerClientService(FakeService.class, new TestSocketRemoting.FakeServiceImpl(), null);
    return new SocketListener(new InetSocketAddress(address.getAddress().getHostAddress(), address.getPort()), 0, 0, 2, config, server, BufferManagerFactory.getStandaloneBufferManager());
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionToken(org.teiid.client.security.SessionToken) InetSocketAddress(java.net.InetSocketAddress) LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) ResultsFuture(org.teiid.client.util.ResultsFuture) SessionService(org.teiid.dqp.service.SessionService) LogonException(org.teiid.client.security.LogonException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 10 with InvalidSessionException

use of org.teiid.client.security.InvalidSessionException in project teiid by teiid.

the class SessionCheckingProxy method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Throwable exception = null;
    try {
        DQPWorkContext workContext = DQPWorkContext.getWorkContext();
        if (workContext.getSession().isClosed() || workContext.getSessionId() == null) {
            if (method.getName().equals("closeRequest")) {
                // there's no need for this to raise an exception
                return ResultsFuture.NULL_FUTURE;
            }
            String sessionID = workContext.getSession().getSessionId();
            if (sessionID == null) {
                throw new InvalidSessionException(RuntimePlugin.Event.TEIID40041, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40041));
            }
            workContext.setSession(new SessionMetadata());
            throw new InvalidSessionException(RuntimePlugin.Event.TEIID40042, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40042, sessionID));
        }
        return super.invoke(proxy, method, args);
    } catch (InvocationTargetException e) {
        exception = e.getTargetException();
    } catch (Throwable t) {
        exception = t;
    }
    throw ExceptionUtil.convertException(method, exception);
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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