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()));
}
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");
}
}
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());
}
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());
}
Aggregations