Search in sources :

Example 11 with LogonException

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

the class SocketServerConnection method selectServerInstance.

/**
 * Implements a sticky random selection policy
 * TODO: make this customizable
 * TODO: put more information on hostinfo as to process response time, last successful connect, etc.
 * @throws ConnectionException
 */
public synchronized SocketServerInstance selectServerInstance(boolean logoff) throws CommunicationException, ConnectionException {
    if (closed) {
        throw new CommunicationException(JDBCPlugin.Event.TEIID20016, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20016));
    }
    if (this.serverInstance != null && (!failOver || this.serverInstance.isOpen())) {
        return this.serverInstance;
    }
    List<HostInfo> hostKeys = new ArrayList<HostInfo>(this.serverDiscovery.getKnownHosts(logonResult, null));
    boolean discoverHosts = true;
    closeServerInstance();
    List<HostInfo> hostCopy = new ArrayList<HostInfo>(hostKeys);
    int knownHosts = hostKeys.size();
    while (hostKeys.size() > 0) {
        HostInfo hostInfo = this.serverDiscovery.selectNextInstance(hostKeys);
        Exception ex = null;
        try {
            if (!hostInfo.isResolved()) {
                InetAddress inetAddress = hostInfo.getInetAddress();
                if (!hostInfo.isResolved()) {
                    // create a resolved version
                    hostInfo = new HostInfo(hostInfo.getHostName(), new InetSocketAddress(inetAddress, hostInfo.getPortNumber()));
                }
            }
            ILogon newLogon = connect(hostInfo);
            if (this.logonResult == null) {
                try {
                    logon(newLogon, logoff);
                    this.serverDiscovery.connectionSuccessful(hostInfo);
                    if (discoverHosts) {
                        List<HostInfo> updatedHosts = this.serverDiscovery.getKnownHosts(logonResult, this.serverInstance);
                        if (updatedHosts.size() > 1 && new HashSet<HostInfo>(updatedHosts).size() > new HashSet<HostInfo>(hostCopy).size()) {
                            hostKeys = updatedHosts;
                            closeServerInstance();
                            discoverHosts = false;
                            continue;
                        }
                    }
                } catch (LogonException e) {
                    // to give to the user
                    throw new ConnectionException(e);
                } catch (TeiidComponentException e) {
                    if (e.getCause() instanceof CommunicationException) {
                        throw (CommunicationException) e.getCause();
                    }
                    throw new CommunicationException(JDBCPlugin.Event.TEIID20018, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20018));
                }
            }
            return this.serverInstance;
        } catch (IOException e) {
            ex = e;
        } catch (SingleInstanceCommunicationException e) {
            ex = e;
        }
        this.serverDiscovery.markInstanceAsBad(hostInfo);
        if (knownHosts == 1) {
            // just a single host, use the exception
            if (ex instanceof UnknownHostException) {
                throw new SingleInstanceCommunicationException(JDBCPlugin.Event.TEIID20019, ex, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20019, hostInfo.getHostName()));
            }
            throw new SingleInstanceCommunicationException(JDBCPlugin.Event.TEIID20020, ex, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20020, hostInfo.getHostName(), String.valueOf(hostInfo.getPortNumber()), ex.getMessage()));
        }
        // $NON-NLS-1$
        log.log(Level.FINE, "Unable to connect to host", ex);
    }
    throw new CommunicationException(JDBCPlugin.Event.TEIID20021, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20021, hostCopy.toString()));
}
Also used : CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) SocketException(java.net.SocketException) CommunicationException(org.teiid.net.CommunicationException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ConnectionException(org.teiid.net.ConnectionException) ILogon(org.teiid.client.security.ILogon) LogonException(org.teiid.client.security.LogonException) TeiidComponentException(org.teiid.core.TeiidComponentException) HostInfo(org.teiid.net.HostInfo) InetAddress(java.net.InetAddress) ConnectionException(org.teiid.net.ConnectionException)

Example 12 with LogonException

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

the class ODBCServerRemoteImpl method initialize.

@Override
public void initialize(Properties props) {
    this.props = props;
    this.client.initialized(this.props);
    // $NON-NLS-1$
    String user = props.getProperty("user");
    // $NON-NLS-1$
    String database = props.getProperty("database");
    AuthenticationType authType = null;
    try {
        authType = getAuthenticationType(user, database);
    } catch (LogonException e) {
        errorOccurred(e);
        terminate();
        return;
    }
    if (authType.equals(AuthenticationType.USERPASSWORD)) {
        this.client.useClearTextAuthentication();
    } else if (authType.equals(AuthenticationType.GSS)) {
        this.client.useAuthenticationGSS();
    } else {
        // $NON-NLS-1$
        throw new AssertionError("Unsupported Authentication Type");
    }
}
Also used : LogonException(org.teiid.client.security.LogonException) AuthenticationType(org.teiid.net.socket.AuthenticationType)

Example 13 with LogonException

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

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

the class TestLogonImpl method testLogonAuthenticationTypeByVDB.

@Test
public void testLogonAuthenticationTypeByVDB() throws Exception {
    VDBRepository repo = Mockito.mock(VDBRepository.class);
    ssi.setVDBRepository(repo);
    // when VDB value is is avavailble this will not be used
    ssi.setAuthenticationType(AuthenticationType.GSS);
    // default transport - what Teiid has before TEIID-2863
    addVdb(repo, "name", "SC", AuthenticationType.USERPASSWORD.name());
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    Properties p = buildProperties("fred", "name");
    // $NON-NLS-1$
    LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
    LogonResult result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    // if no preference then choose USERPASSWORD
    VDBMetaData metadata = addVdb(repo, "name1", "SC", AuthenticationType.USERPASSWORD.name());
    metadata.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties("fred", "name1");
    result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    p = buildProperties("GSS", "name1");
    // $NON-NLS-1$
    FakeGssLogonImpl fimpl = new FakeGssLogonImpl(ssi, "fakeCluster");
    fimpl.addToken("bytes".getBytes(), new Subject());
    p.put(ILogon.KRB5TOKEN, "bytes".getBytes());
    result = fimpl.logon(p);
    assertEquals("GSS", result.getUserName());
    // here preference is GSS
    try {
        p = buildProperties("GSS", "name");
        result = impl.logon(p);
        assertEquals("GSS", result.getUserName());
    } catch (LogonException e) {
    }
    // if the transport default defined as GSS, then preference is USERPASSWORD, additional challenge
    addVdb(repo, "name2", "SC", "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties("fred", "name2");
    result = impl.logon(p);
    assertEquals(AuthenticationType.GSS, result.getProperty("authType"));
    // doesn't match gss pattern
    metadata.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties(null, "name1");
    result = impl.logon(p);
    assertEquals("anonymous", result.getUserName());
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LogonException(org.teiid.client.security.LogonException) LogonResult(org.teiid.client.security.LogonResult) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Aggregations

LogonException (org.teiid.client.security.LogonException)14 LogonResult (org.teiid.client.security.LogonResult)8 TeiidComponentException (org.teiid.core.TeiidComponentException)5 AuthenticationType (org.teiid.net.socket.AuthenticationType)5 Properties (java.util.Properties)4 CommunicationException (org.teiid.net.CommunicationException)4 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 InvalidSessionException (org.teiid.client.security.InvalidSessionException)3 SessionToken (org.teiid.client.security.SessionToken)3 ConnectionException (org.teiid.net.ConnectionException)3 GSSResult (org.teiid.security.GSSResult)3 UnknownHostException (java.net.UnknownHostException)2 Subject (javax.security.auth.Subject)2 LoginException (javax.security.auth.login.LoginException)2 GSSCredential (org.ietf.jgss.GSSCredential)2 Test (org.junit.Test)2 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)2 ILogon (org.teiid.client.security.ILogon)2 ResultsFuture (org.teiid.client.util.ResultsFuture)2