/** * 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; }
return null; SessionMetadata session = new SessionMetadata(); if (node.has(APPLICATION_NAME)) { session.setApplicationName(node.get(APPLICATION_NAME).asString()); session.setCreatedTime(node.get(CREATED_TIME).asLong()); session.setClientHostName(node.get(CLIENT_HOST_NAME).asString()); session.setIPAddress(node.get(IP_ADDRESS).asString()); session.setLastPingTime(node.get(LAST_PING_TIME).asLong()); session.setSessionId(node.get(SESSION_ID).asString()); session.setUserName(node.get(USER_NAME).asString()); session.setVDBName(node.get(VDB_NAME).asString()); session.setVDBVersion(node.get(VDB_VERSION).asInt()); if (node.has(SECURITY_DOMAIN)) { session.setSecurityDomain(node.get(SECURITY_DOMAIN).asString()); session.setClientHardwareAddress(node.get(CLIENT_HARDWARE_ADRESS).asString());
if (session.getApplicationName() != null) { node.get(APPLICATION_NAME).set(session.getApplicationName()); node.get(CREATED_TIME).set(session.getCreatedTime()); if (session.getClientHostName() != null) { node.get(CLIENT_HOST_NAME).set(session.getClientHostName()); if (session.getIPAddress() != null) { node.get(IP_ADDRESS).set(session.getIPAddress()); node.get(LAST_PING_TIME).set(session.getLastPingTime()); node.get(SESSION_ID).set(session.getSessionId()); node.get(USER_NAME).set(session.getUserName()); node.get(VDB_NAME).set(session.getVDBName()); node.get(VDB_VERSION).set(session.getVDBVersion()); if (session.getSecurityDomain() != null){ node.get(SECURITY_DOMAIN).set(session.getSecurityDomain()); if (session.getClientHardwareAddress() != null) { node.get(CLIENT_HARDWARE_ADRESS).set(session.getClientHardwareAddress());
private void updateDQPContext(SessionMetadata s) { DQPWorkContext workContext = DQPWorkContext.getWorkContext(); SessionMetadata old = workContext.getSession(); if (old.getSessionId() != null) { old.setActive(false); } workContext.setSession(s); if (s.getSessionId() != null) { s.setActive(true); } }
public Collection<SessionMetadata> getSessionsLoggedInToVDB(VDBKey key, String username) { ArrayList<SessionMetadata> results = new ArrayList<SessionMetadata>(); for (SessionMetadata info : this.sessionCache.values()) { if (info.getVdb() != null && key.equals(info.getVdb().getAttachment(VDBKey.class)) && (username == null || info.getUserName().equals(username))) { results.add(info); } } return results; }
SessionMetadata newSession = new SessionMetadata(); newSession.setSessionToken(new SessionToken(userName)); newSession.setSessionId(newSession.getSessionToken().getSessionID()); newSession.setUserName(userName); newSession.setCreatedTime(creationTime); newSession.setApplicationName(applicationName); newSession.setClientHostName(hostName); newSession.setIPAddress(ipAddress); newSession.setClientHardwareAddress(clientMac); newSession.setSecurityDomain(securityDomain); if (vdb != null) { newSession.setVDBName(vdb.getName()); newSession.setVDBVersion(vdb.getVersion()); newSession.setSubject(subject); newSession.setSecurityContext(securityContext); newSession.setVdb(vdb); if (LogManager.isMessageToBeRecorded(LogConstants.CTX_SECURITY, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] {"Logon successful, created", newSession }); //$NON-NLS-1$ this.sessionCache.put(newSession.getSessionId(), newSession); if (LogManager.isMessageToBeRecorded(LogConstants.CTX_AUDITLOGGING, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_AUDITLOGGING, new AuditMessage("session", "logon-success", newSession)); //$NON-NLS-1$ //$NON-NLS-2$
public static DQPWorkContext buildWorkContext() { DQPWorkContext workContext = new DQPWorkContext(); SessionMetadata session = new SessionMetadata(); workContext.setSession(session); session.setVDBName("vdb-name"); //$NON-NLS-1$ session.setVDBVersion(1); session.setSessionId(String.valueOf(1)); session.setUserName("foo"); //$NON-NLS-1$ return workContext; } }
private DQPWorkContext createWorkContext(final CommandContext context, VDBMetaData vdb) { SessionMetadata session = createTemporarySession(context.getUserName(), "asynch-mat-view-load", vdb); //$NON-NLS-1$ 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; }
public static DQPWorkContext example() { DQPWorkContext message = new DQPWorkContext(); message.getSession().setVDBName("vdbName"); //$NON-NLS-1$ message.getSession().setVDBVersion(1); message.getSession().setApplicationName("querybuilder"); //$NON-NLS-1$ message.getSession().setSessionId(String.valueOf(5)); message.getSession().setUserName("userName"); //$NON-NLS-1$ return message; }
private ResultsMessage execute(String userName, int sessionid, RequestMessage reqMsg) throws InterruptedException, ExecutionException, TimeoutException, TeiidProcessingException { DQPWorkContext.getWorkContext().getSession().setSessionId(String.valueOf(sessionid)); DQPWorkContext.getWorkContext().getSession().setUserName(userName); Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg); assertNotNull(core.getClientState(String.valueOf(sessionid), false)); ResultsMessage results = message.get(500000, TimeUnit.MILLISECONDS); return results; } }
@Override public void closeSession(String sessionID) throws InvalidSessionException { if (LogManager.isMessageToBeRecorded(LogConstants.CTX_SECURITY, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] {"closeSession", sessionID}); //$NON-NLS-1$ } SessionMetadata info = getSessionInfo(sessionID, true); if (LogManager.isMessageToBeRecorded(LogConstants.CTX_AUDITLOGGING, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_AUDITLOGGING, new AuditMessage("session", "logoff", info)); //$NON-NLS-1$ //$NON-NLS-2$ } if (info.getVDBName() != null) { try { dqp.terminateSession(info.getSessionId()); } catch (Exception e) { LogManager.logWarning(LogConstants.CTX_SECURITY,e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40018)); } } info.setSecurityContext(null); info.setClosed(); info.getSessionVariables().clear(); }
private void monitorSessions() { long currentTime = System.currentTimeMillis(); for (SessionMetadata info : sessionCache.values()) { try { if (CHECK_PING && !info.isEmbedded() && !info.isActive() && currentTime - info.getLastPingTime() > ServerConnection.PING_INTERVAL * 5) { LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40007, info.getSessionId())); closeSession(info.getSessionId()); } else if (sessionExpirationTimeLimit > 0 && currentTime - info.getCreatedTime() > sessionExpirationTimeLimit) { LogManager.logInfo(LogConstants.CTX_SECURITY,RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40008, info.getSessionId())); closeSession(info.getSessionId()); } } catch (Exception e) { LogManager.logDetail(LogConstants.CTX_SECURITY, e, "error running session monitor, unable to monitor:", info.getSessionId()); //$NON-NLS-1$ } } }
@Test(expected=TeiidProcessingException.class) public void testMaxRecursive() throws Exception { String sql = "WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 64 ) SELECT sum(n) FROM t;"; //$NON-NLS-1$ List<?>[] expected = new List[] { Arrays.asList(2080l), }; FakeDataManager dataManager = new FakeDataManager(); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached()); CommandContext cc = createCommandContext(); cc.setSession(new SessionMetadata()); cc.setSessionVariable(TempTableStore.TEIID_MAX_RECURSION, 10); helpProcess(plan, cc, dataManager, expected); }
public static void setWorkContext(DQPWorkContext context) { LogManager.removeMdc(TEIID_SESSION); LogManager.removeMdc(TEIID_VDB); if (context == null) { CONTEXTS.remove(); } else { if (context.session != null) { LogManager.putMdc(TEIID_SESSION, context.session.getSessionId()); if (context.session.getVdb() != null) { LogManager.putMdc(TEIID_VDB, context.session.getVdb().getFullName()); } } CONTEXTS.set(context); } }
@BeforeClass public static void setUpOnce() { token.getSession().setVDBName("foo"); //$NON-NLS-1$ token.getSession().setVDBVersion(1); token2.getSession().setVDBName("foo"); //$NON-NLS-1$ token2.getSession().setVDBVersion(2); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Throwable exception = null; try { DQPWorkContext workContext = DQPWorkContext.getWorkContext(); if (workContext.getSession().isClosed() || workContext.getSessionId() == null) { if (method.getName().equals("closeRequest")) { //$NON-NLS-1$ //the client can issue close request effectively concurrently with close session //there's no need for this to raise an exception return ResultsFuture.NULL_FUTURE; } String sessionID = workContext.getSession().getSessionId(); if (sessionID == null) { throw new InvalidSessionException(RuntimePlugin.Event.TEIID40041, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40041)); } workContext.setSession(new SessionMetadata()); throw new InvalidSessionException(RuntimePlugin.Event.TEIID40042, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40042, sessionID)); } return super.invoke(proxy, method, args); } catch (InvocationTargetException e) { exception = e.getTargetException(); } catch(Throwable t){ exception = t; } throw ExceptionUtil.convertException(method, exception); } }
@Test public void testInvokeUser() throws Exception { CommandContext c = new CommandContext(); c.setUserName("foodude"); //$NON-NLS-1$ c.setSession(new SessionMetadata()); c.getSession().setSecurityDomain("x"); helpInvokeMethod("user", new Class<?>[] {}, new Object[] {}, c, "foodude@x"); //$NON-NLS-1$ //$NON-NLS-2$ }
public String getSecurityDomain() { return this.session.getSecurityDomain(); }
|| (passthrough && !workContext.getSession().isClosed() && workContext.getSession().getSecurityDomain() != null && !sameSubject(workContext)))) { LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40115, workContext.getSession().getSessionId())); reconnect = false; authenticate();
public String getSessionId() { return this.session.getSessionId(); }