Search in sources :

Example 1 with SessionToken

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

the class TestSocketRemoting method testMethodInvocation.

@Test
public void testMethodInvocation() throws Exception {
    ClientServiceRegistryImpl csr = new ClientServiceRegistryImpl() {

        @Override
        public ClassLoader getCallerClassloader() {
            return getClass().getClassLoader();
        }
    };
    csr.registerClientService(ILogon.class, new ILogon() {

        public ResultsFuture<?> logoff() throws InvalidSessionException {
            ResultsFuture<?> result = new ResultsFuture<Void>();
            // $NON-NLS-1$
            result.getResultsReceiver().exceptionOccurred(new TeiidComponentException("some exception"));
            return result;
        }

        public LogonResult logon(Properties connectionProperties) throws LogonException, TeiidComponentException {
            return new LogonResult();
        }

        // tests asynch where we don't care about the result
        public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
            return null;
        }

        @Override
        public ResultsFuture<?> ping(Collection<String> sessions) throws TeiidComponentException, CommunicationException {
            return null;
        }

        @Override
        public void assertIdentity(SessionToken sessionId) throws InvalidSessionException, TeiidComponentException {
        }

        @Override
        public LogonResult neogitiateGssLogin(Properties connectionProperties, byte[] serviceToken, boolean createSession) throws LogonException {
            return null;
        }
    }, // $NON-NLS-1$
    "foo");
    // $NON-NLS-1$
    csr.registerClientService(FakeService.class, new FakeServiceImpl(), "foo");
    final FakeClientServerInstance serverInstance = new FakeClientServerInstance(csr);
    SocketServerConnection connection = createFakeConnection(serverInstance);
    ILogon logon = connection.getService(ILogon.class);
    Future<?> result = logon.ping();
    assertNull(result.get(0, TimeUnit.MILLISECONDS));
    result = logon.logoff();
    try {
        result.get(0, TimeUnit.MICROSECONDS);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof TeiidComponentException);
    }
    FakeService service = connection.getService(FakeService.class);
    Future<Integer> asynchInteger = service.asynchResult();
    assertEquals(new Integer(5), asynchInteger.get(0, TimeUnit.MILLISECONDS));
    try {
        service.exceptionMethod();
        // $NON-NLS-1$
        fail("exception expected");
    } catch (TeiidProcessingException e) {
    }
    DQP dqp = connection.getService(DQP.class);
    try {
        ResultsFuture<?> future = dqp.begin();
        future.get();
        // $NON-NLS-1$
        fail("exception expected");
    } catch (Exception e) {
        // $NON-NLS-1$
        assertTrue(e.getMessage().indexOf("Component not found:") != -1);
    }
}
Also used : LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) TeiidProcessingException(org.teiid.core.TeiidProcessingException) LogonException(org.teiid.client.security.LogonException) ExecutionException(java.util.concurrent.ExecutionException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) DQP(org.teiid.client.DQP) CommunicationException(org.teiid.net.CommunicationException) SessionToken(org.teiid.client.security.SessionToken) ILogon(org.teiid.client.security.ILogon) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) CommunicationException(org.teiid.net.CommunicationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(org.teiid.net.ConnectionException) ResultsFuture(org.teiid.client.util.ResultsFuture) TeiidComponentException(org.teiid.core.TeiidComponentException) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Example 2 with SessionToken

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

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

the class LogonImpl method neogitiateGssLogin.

@Override
public LogonResult neogitiateGssLogin(Properties connProps, byte[] serviceTicket, boolean createSession) throws LogonException {
    String vdbName = connProps.getProperty(BaseDataSource.VDB_NAME);
    String vdbVersion = connProps.getProperty(BaseDataSource.VDB_VERSION);
    String user = connProps.getProperty(BaseDataSource.USER_NAME);
    AuthenticationType authType = this.service.getAuthenticationType(vdbName, vdbVersion, user);
    if (!AuthenticationType.GSS.equals(authType)) {
        // $NON-NLS-1$
        throw new LogonException(RuntimePlugin.Event.TEIID40055, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40055, "Kerberos"));
    }
    // Using SPENGO security domain establish a token and subject.
    GSSResult result = neogitiateGssLogin(serviceTicket, vdbName, vdbVersion, user);
    if (!result.isAuthenticated() || !createSession) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        LogonResult logonResult = new LogonResult(new SessionToken(0, "temp"), "internal", "internal");
        logonResult.addProperty(ILogon.KRB5TOKEN, result.getServiceToken());
        logonResult.addProperty(ILogon.KRB5_ESTABLISHED, new Boolean(result.isAuthenticated()));
        if (result.isAuthenticated()) {
            logonResult.addProperty(GSSCredential.class.getName(), result.getDelegationCredential());
        }
        return logonResult;
    }
    // GSS API (jdbc) will make the session in one single call
    connProps.setProperty(TeiidURL.CONNECTION.USER_NAME, result.getUserName());
    connProps.put(ILogon.KRB5TOKEN, result.getServiceToken());
    if (result.getDelegationCredential() != null) {
        connProps.put(GSSCredential.class.getName(), result.getDelegationCredential());
    }
    LogonResult logonResult = logon(connProps);
    return logonResult;
}
Also used : GSSResult(org.teiid.security.GSSResult) SessionToken(org.teiid.client.security.SessionToken) GSSCredential(org.ietf.jgss.GSSCredential) LogonException(org.teiid.client.security.LogonException) LogonResult(org.teiid.client.security.LogonResult) AuthenticationType(org.teiid.net.socket.AuthenticationType)

Example 4 with SessionToken

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

the class TestConnection method getMMConnection.

public static ConnectionImpl getMMConnection(String url) {
    ServerConnection mock = mock(ServerConnection.class);
    DQP dqp = mock(DQP.class);
    try {
        stub(dqp.start((XidImpl) Mockito.anyObject(), Mockito.anyInt(), Mockito.anyInt())).toAnswer(new Answer() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                return ResultsFuture.NULL_FUTURE;
            }
        });
        stub(dqp.rollback((XidImpl) Mockito.anyObject())).toAnswer(new Answer() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                return ResultsFuture.NULL_FUTURE;
            }
        });
        stub(dqp.rollback()).toAnswer(new Answer() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                return ResultsFuture.NULL_FUTURE;
            }
        });
    } catch (XATransactionException e) {
        throw new RuntimeException(e);
    }
    Properties props = new Properties();
    try {
        new InnerDriver(url).parseUrl(props);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    stub(mock.getService(DQP.class)).toReturn(dqp);
    // $NON-NLS-1$
    stub(mock.getLogonResult()).toReturn(new LogonResult(new SessionToken(1, "admin"), STD_DATABASE_NAME, "fake"));
    return new ConnectionImpl(mock, props, url);
}
Also used : DQP(org.teiid.client.DQP) SQLException(java.sql.SQLException) SessionToken(org.teiid.client.security.SessionToken) LogonResult(org.teiid.client.security.LogonResult) ServerConnection(org.teiid.net.ServerConnection) XATransactionException(org.teiid.client.xa.XATransactionException) Properties(java.util.Properties) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 5 with SessionToken

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

the class TestSocketServerConnection method createConnection.

private SocketServerConnection createConnection(final Throwable t, final HostInfo hostInfo, Properties p) throws CommunicationException, ConnectionException {
    ServerDiscovery discovery = new UrlServerDiscovery(new TeiidURL(hostInfo.getHostName(), hostInfo.getPortNumber(), false));
    SocketServerInstanceFactory instanceFactory = new SocketServerInstanceFactory() {

        FakeILogon logon = new FakeILogon(t);

        @Override
        public SocketServerInstance getServerInstance(HostInfo info) throws CommunicationException, IOException {
            SocketServerInstance instance = Mockito.mock(SocketServerInstance.class);
            Mockito.stub(instance.getCryptor()).toReturn(new NullCryptor());
            Mockito.stub(instance.getHostInfo()).toReturn(hostInfo);
            Mockito.stub(instance.getService(ILogon.class)).toReturn(logon);
            Mockito.stub(instance.getServerVersion()).toReturn("07.03");
            if (t != null) {
                try {
                    Mockito.doAnswer(new Answer<Void>() {

                        @Override
                        public Void answer(InvocationOnMock invocation) throws Throwable {
                            if (logon.t == null) {
                                return null;
                            }
                            throw logon.t;
                        }
                    }).when(instance).send((Message) Mockito.anyObject(), (ResultsReceiver<Object>) Mockito.anyObject(), (Serializable) Mockito.anyObject());
                } catch (Exception e) {
                }
            }
            Mockito.stub(instance.isOpen()).toReturn(true);
            return instance;
        }

        @Override
        public void connected(SocketServerInstance instance, SessionToken session) {
        }

        @Override
        public void disconnected(SocketServerInstance instance, SessionToken session) {
        }
    };
    SocketServerConnection connection = new SocketServerConnection(instanceFactory, false, discovery, p);
    return connection;
}
Also used : SessionToken(org.teiid.client.security.SessionToken) TeiidURL(org.teiid.net.TeiidURL) NullCryptor(org.teiid.core.crypto.NullCryptor) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) CommunicationException(org.teiid.net.CommunicationException) IOException(java.io.IOException) LogonException(org.teiid.client.security.LogonException) ConnectionException(org.teiid.net.ConnectionException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HostInfo(org.teiid.net.HostInfo)

Aggregations

SessionToken (org.teiid.client.security.SessionToken)9 LogonResult (org.teiid.client.security.LogonResult)5 Properties (java.util.Properties)4 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)4 InvalidSessionException (org.teiid.client.security.InvalidSessionException)4 LogonException (org.teiid.client.security.LogonException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 IOException (java.io.IOException)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 DQP (org.teiid.client.DQP)2 ResultsFuture (org.teiid.client.util.ResultsFuture)2 SessionService (org.teiid.dqp.service.SessionService)2 SessionServiceException (org.teiid.dqp.service.SessionServiceException)2 CommunicationException (org.teiid.net.CommunicationException)2 ConnectionException (org.teiid.net.ConnectionException)2 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 SQLException (java.sql.SQLException)1 ExecutionException (java.util.concurrent.ExecutionException)1