use of org.teiid.client.security.LogonResult in project teiid by teiid.
the class SocketServerConnection method logon.
private void logon(ILogon newLogon, boolean logoff) throws LogonException, TeiidComponentException, CommunicationException {
SocketServerInstance instance = this.serverInstance;
updateConnectionProperties(connProps, instance.getLocalAddress(), true);
LogonResult newResult = null;
// - if gss
if (connProps.contains(TeiidURL.CONNECTION.JAAS_NAME)) {
newResult = MakeGSS.authenticate(newLogon, connProps);
} else {
newResult = newLogon.logon(connProps);
}
AuthenticationType type = (AuthenticationType) newResult.getProperty(ILogon.AUTH_TYPE);
if (type != null) {
// server has issued an additional challange
if (type == AuthenticationType.GSS) {
newResult = MakeGSS.authenticate(newLogon, connProps);
} else {
throw new LogonException(JDBCPlugin.Event.TEIID20034, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20034, type));
}
}
if (logoff) {
LogonResult old = this.logonResults.remove(this.serverInstance.getHostInfo());
this.connectionFactory.disconnected(this.serverInstance, old.getSessionToken());
logoffAll();
}
this.logonResult = newResult;
this.logonResults.put(instance.getHostInfo(), this.logonResult);
this.connectionFactory.connected(instance, this.logonResult.getSessionToken());
}
use of org.teiid.client.security.LogonResult 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.LogonResult in project teiid by teiid.
the class TestLogonImpl method testLogonAuthenticationType.
@Test
public void testLogonAuthenticationType() throws Exception {
VDBRepository repo = Mockito.mock(VDBRepository.class);
VDBMetaData vdb = new VDBMetaData();
vdb.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
vdb.setName("name");
vdb.setVersion(1);
vdb.setStatus(Status.ACTIVE);
Mockito.stub(repo.getLiveVDB("name", "1")).toReturn(vdb);
ssi.setVDBRepository(repo);
ssi.setSecurityDomain("SC");
// default transport - what Teiid has before TEIID-2863
// this is transport default
ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
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
// this is transport default
ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
DQPWorkContext.setWorkContext(new DQPWorkContext());
p = buildProperties("fred", "name");
// $NON-NLS-1$
impl = new LogonImpl(ssi, "fakeCluster");
result = impl.logon(p);
assertEquals("fred", result.getUserName());
// if user name is set to "GSS", then the preference is set to "GSS"
// this is transport default
ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
DQPWorkContext.setWorkContext(new DQPWorkContext());
p = buildProperties("GSS", "name");
// $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());
// if the transport default defined as GSS, then preference is USERPASSWORD, additional challenge
ssi.setAuthenticationType(AuthenticationType.GSS);
DQPWorkContext.setWorkContext(new DQPWorkContext());
p = buildProperties("fred", "name");
// $NON-NLS-1$
impl = new LogonImpl(ssi, "fakeCluster");
result = impl.logon(p);
assertEquals(AuthenticationType.GSS, result.getProperty("authType"));
}
use of org.teiid.client.security.LogonResult 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());
}
use of org.teiid.client.security.LogonResult in project teiid by teiid.
the class TestLogonImpl method testLogonResult.
@Test
public void testLogonResult() throws Exception {
SessionService ssi = Mockito.mock(SessionService.class);
Mockito.stub(ssi.getAuthenticationType(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).toReturn(AuthenticationType.USERPASSWORD);
DQPWorkContext.setWorkContext(new DQPWorkContext());
// $NON-NLS-1$
String userName = "Fred";
// $NON-NLS-1$
String applicationName = "test";
Properties p = new Properties();
p.setProperty(TeiidURL.CONNECTION.USER_NAME, userName);
p.setProperty(TeiidURL.CONNECTION.APP_NAME, applicationName);
p.setProperty(TeiidURL.JDBC.VDB_NAME, "x");
p.setProperty(TeiidURL.JDBC.VDB_VERSION, "1");
SessionMetadata session = new SessionMetadata();
session.setUserName(userName);
session.setApplicationName(applicationName);
session.setSessionId(String.valueOf(1));
session.setSessionToken(new SessionToken(1, userName));
Mockito.stub(ssi.createSession("x", "1", AuthenticationType.USERPASSWORD, userName, null, applicationName, p)).toReturn(session);
// $NON-NLS-1$
LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
LogonResult result = impl.logon(p);
assertEquals(userName, result.getUserName());
assertEquals(String.valueOf(1), result.getSessionID());
}
Aggregations