use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class ODBCServerRemoteImpl method logon.
@Override
public void logon(String databaseName, String user, NullTerminatedStringDataInputStream data, SocketAddress remoteAddress) {
try {
java.util.Properties info = new java.util.Properties();
info.put(TeiidURL.CONNECTION.USER_NAME, user);
AuthenticationType authType = getAuthenticationType(user, databaseName);
String password = null;
if (authType.equals(AuthenticationType.USERPASSWORD)) {
password = data.readString();
} else if (authType.equals(AuthenticationType.GSS)) {
byte[] serviceToken = data.readServiceToken();
GSSResult result = this.logon.neogitiateGssLogin(serviceToken, databaseName, null, user);
serviceToken = result.getServiceToken();
if (result.isAuthenticated()) {
info.put(ILogon.KRB5TOKEN, serviceToken);
if (!result.isNullContinuationToken()) {
this.client.authenticationGSSContinue(serviceToken);
}
// if delegation is in progress, participate in it.
if (result.getDelegationCredential() != null) {
info.put(GSSCredential.class.getName(), result.getDelegationCredential());
}
} else {
this.client.authenticationGSSContinue(serviceToken);
return;
}
} else {
// $NON-NLS-1$
throw new AssertionError("Unsupported Authentication Type");
}
// this is local connection
// $NON-NLS-1$
String url = "jdbc:teiid:" + databaseName;
if (password != null) {
info.put(TeiidURL.CONNECTION.PASSWORD, password);
}
String applicationName = this.props.getProperty(PgBackendProtocol.APPLICATION_NAME);
if (applicationName == null) {
applicationName = PgBackendProtocol.DEFAULT_APPLICATION_NAME;
this.props.put(PgBackendProtocol.APPLICATION_NAME, applicationName);
}
info.put(TeiidURL.CONNECTION.APP_NAME, applicationName);
if (remoteAddress instanceof InetSocketAddress) {
SocketServerConnection.updateConnectionProperties(info, ((InetSocketAddress) remoteAddress).getAddress(), false);
}
this.connection = driver.connect(url, info);
// Propagate so that we can use in pg methods
SessionMetadata sm = ((LocalServerConnection) this.connection.getServerConnection()).getWorkContext().getSession();
sm.addAttchment(ODBCServerRemoteImpl.class, this);
setConnectionProperties(this.connection);
int hash = this.connection.getConnectionId().hashCode();
Enumeration<?> keys = this.props.propertyNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
this.connection.setExecutionProperty(key, this.props.getProperty(key));
}
StatementImpl s = this.connection.createStatement();
try {
// $NON-NLS-1$
s.execute("select teiid_session_set('resolve_groupby_positional', true)");
} finally {
s.close();
}
this.client.authenticationSucess(hash, hash);
ready();
} catch (SQLException e) {
errorOccurred(e);
terminate();
} catch (LogonException e) {
errorOccurred(e);
terminate();
} catch (IOException e) {
errorOccurred(e);
terminate();
}
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class TempTableDataManager method createWorkContext.
private DQPWorkContext createWorkContext(final CommandContext context, VDBMetaData vdb) {
// $NON-NLS-1$
SessionMetadata session = createTemporarySession(context.getUserName(), "asynch-mat-view-load", vdb);
session.setSubject(context.getSubject());
session.setSecurityDomain(context.getSession().getSecurityDomain());
session.setSecurityContext(context.getSession().getSecurityContext());
DQPWorkContext workContext = new DQPWorkContext();
workContext.setAdmin(true);
DQPWorkContext current = context.getDQPWorkContext();
workContext.setSession(session);
workContext.setPolicies(current.getAllowedDataPolicies());
workContext.setSecurityHelper(current.getSecurityHelper());
return workContext;
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class TestBufferManagerImpl method testTupleBufferSessionMax.
@Test
public void testTupleBufferSessionMax() throws Exception {
BufferManagerImpl bufferManager = new BufferManagerImpl();
bufferManager.setCache(new MemoryStorageManager() {
@Override
public long getMaxStorageSpace() {
return 64000;
}
});
bufferManager.setMaxReserveKB(10);
bufferManager.setMaxActivePlans(10);
bufferManager.setOptions(new Options().maxSessionBufferSizeEstimate(100000));
bufferManager.initialize();
CommandContext context = new CommandContext();
context.setSession(new SessionMetadata());
CommandContext.pushThreadLocalContext(context);
try {
List<TupleBuffer> tupleBuffers = new ArrayList<TupleBuffer>();
for (int i = 0; i < 36; i++) {
TupleBuffer tb = bufferManager.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, String.class)), "x", TupleSourceType.PROCESSOR);
try {
for (int j = 0; j < 50; j++) {
tb.addTuple(Arrays.asList("a"));
}
tb.saveBatch();
if (i % 2 == 0) {
tb.remove();
}
} catch (TeiidComponentException e) {
assertEquals(34, i);
return;
}
tupleBuffers.add(tb);
}
} finally {
CommandContext.popThreadLocalContext();
}
fail();
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class TestDQPWorkContext method testAnyAuthenticated.
@Test
public void testAnyAuthenticated() {
DQPWorkContext message = new DQPWorkContext();
SessionMetadata mock = Mockito.mock(SessionMetadata.class);
message.setSession(mock);
VDBMetaData vdb = new VDBMetaData();
DataPolicyMetadata dpm = new DataPolicyMetadata();
dpm.setAnyAuthenticated(true);
vdb.addDataPolicy(dpm);
Mockito.stub(mock.getVdb()).toReturn(vdb);
// unauthenticated
Map<String, DataPolicy> map = message.getAllowedDataPolicies();
assertEquals(0, map.size());
// authenticated
message = new DQPWorkContext();
Mockito.stub(mock.getSubject()).toReturn(new Subject());
message.setSession(mock);
map = message.getAllowedDataPolicies();
assertEquals(1, map.size());
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class TestSessionAwareCache method buildWorkContext.
public static DQPWorkContext buildWorkContext() {
DQPWorkContext workContext = new DQPWorkContext();
SessionMetadata session = new SessionMetadata();
workContext.setSession(session);
// $NON-NLS-1$
session.setVDBName("vdb-name");
session.setVDBVersion(1);
session.setSessionId(String.valueOf(1));
// $NON-NLS-1$
session.setUserName("foo");
return workContext;
}
Aggregations