public ResultsFuture<?> end(XidImpl xid, int flags) throws XATransactionException { DQPWorkContext workContext = DQPWorkContext.getWorkContext(); this.getTransactionService().end(workContext.getSessionId(), xid, flags, workContext.getSession().isEmbedded()); return ResultsFuture.NULL_FUTURE; } // global txn
void initialize(RequestMessage requestMsg, BufferManager bufferManager, ProcessorDataManager processorDataManager, TransactionService transactionService, TempTableStore tempTableStore, DQPWorkContext workContext, SessionAwareCache<PreparedPlan> planCache) { this.requestMsg = requestMsg; this.vdbName = workContext.getVdbName(); this.vdbVersion = workContext.getVdbVersion(); this.bufferManager = bufferManager; this.processorDataManager = processorDataManager; this.transactionService = transactionService; this.tempTableStore = tempTableStore; this.workContext = workContext; this.requestId = workContext.getRequestID(this.requestMsg.getExecutionId()); this.connectorManagerRepo = workContext.getVDB().getAttachment(ConnectorManagerRepository.class); this.planCache = planCache; }
public <V> V runInContext(Callable<V> callable) throws Throwable { FutureTask<V> task = new FutureTask<V>(callable); runInContext(task); try { return task.get(); } catch (ExecutionException e) { throw e.getCause(); } }
public CacheID(DQPWorkContext context, ParseInfo pi, String sql){ this(pi, sql, context.getVdbName(), context.getVdbVersion(), context.getSessionId(), context.getUserName()); }
@Override public void disconnected() { if (workContext.getSessionId() != null) { workContext.runInContext(new Runnable() { @Override public void run() { try { csr.getClientService(ILogon.class).logoff(); } catch (Exception e) { LogManager.logDetail(LogConstants.CTX_TRANSPORT, e, "Exception closing client instance"); //$NON-NLS-1$ } } }); } }
@Override public void run() { if (workContext.getSecurityHelper() != null) { //if using the inheritable thread local security or if unassocation has been sloppy, there may a security context associated workContext.getSecurityHelper().clearSecurityContext(); } workContext.runInContext(r); }
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 MetadataResult getMetadata(long requestID) throws TeiidComponentException, TeiidProcessingException { DQPWorkContext workContext = DQPWorkContext.getWorkContext(); MetaDataProcessor processor = new MetaDataProcessor(this, this.prepPlanCache, workContext.getVdbName(), workContext.getVdbVersion()); return processor.processMessage(workContext.getRequestID(requestID), workContext, null, true); }
DQPWorkContext workContext = new DQPWorkContext(); if (engine.localProfile != null) { workContext.setConnectionProfile(engine.localProfile); workContext.setUseCallingThread(true); workContext.setSession(session); workContext.setAdmin(true); workContext.runInContext(new Callable<Void>() { @Override public Void call() throws Exception {
public ResultsFuture<?> commit() throws XATransactionException { final String threadId = DQPWorkContext.getWorkContext().getSessionId(); Callable<Void> processor = new Callable<Void>() { @Override public Void call() throws Exception { getTransactionService().commit(threadId); return null; } }; return addWork(processor, 0); }
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; }
@Override public void visit(AlterView obj) { Table t = (Table)obj.getTarget().getMetadataID(); String sql = obj.getDefinition().toString(); if (getMetadataRepository(vdb, t.getParent().getName()) != null) { getMetadataRepository(vdb, t.getParent().getName()).setViewDefinition(workContext.getVdbName(), workContext.getVdbVersion(), t, sql); } alterView(vdb, t, sql, false); if (pdm.getEventDistributor() != null) { pdm.getEventDistributor().setViewDefinition(workContext.getVdbName(), workContext.getVdbVersion(), t.getParent().getName(), t.getName(), sql); } }
@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); } }
message.setSecurityHelper(sc); message.setSession(Mockito.mock(SessionMetadata.class)); final String currentSC = "teiid-security-context"; //$NON-NLS-1$ Mockito.stub(message.getSession().getSecurityContext()).toReturn(currentSC); message.runInContext(r);
@Test public void testClearPolicies() { DQPWorkContext message = new DQPWorkContext(); message.setSession(Mockito.mock(SessionMetadata.class)); Mockito.stub(message.getSession().getVdb()).toReturn(new VDBMetaData()); Map<String, DataPolicy> map = message.getAllowedDataPolicies(); map.put("role", Mockito.mock(DataPolicy.class)); //$NON-NLS-1$ assertFalse(map.isEmpty()); message.setSession(Mockito.mock(SessionMetadata.class)); Mockito.stub(message.getSession().getVdb()).toReturn(new VDBMetaData()); map = message.getAllowedDataPolicies(); assertTrue(map.isEmpty()); }
public static DQPWorkContext buildWorkContext(QueryMetadataInterface metadata, VDBMetaData vdb) { DQPWorkContext workContext = new DQPWorkContext(); SessionMetadata session = new SessionMetadata(); workContext.setSession(session); session.setVDBName(vdb.getName()); session.setVDBVersion(vdb.getVersion()); session.setSessionId(String.valueOf(1)); session.setUserName("foo"); //$NON-NLS-1$ session.setVdb(vdb); workContext.getVDB().addAttchment(QueryMetadataInterface.class, metadata); if (metadata instanceof TransformationMetadata) { workContext.getVDB().addAttchment(TransformationMetadata.class, (TransformationMetadata)metadata); } DQPWorkContext.setWorkContext(workContext); return workContext; }
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); } }
workContext.setSecurityHelper(csr.getSecurityHelper()); workContext.setUseCallingThread(useCallingThread); workContext.setSecurityContext(csr.getSecurityHelper().getSecurityContext()); authenticate(); passthrough = Boolean.valueOf(connectionProperties.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "false")); //$NON-NLS-1$ derived = true; workContext = context; this.result = new LogonResult(context.getSessionToken(), context.getVdbName(), null); passthrough = true;
public void setNewVDBState(DQPWorkContext newWorkContext) { this.vdbState = new VDBState(); VDBMetaData vdb = newWorkContext.getVDB(); GlobalTableStore actualGlobalStore = vdb.getAttachment(GlobalTableStore.class); this.vdbState.globalTables = actualGlobalStore; this.vdbState.session = newWorkContext.getSession(); this.vdbState.classLoader = vdb.getAttachment(ClassLoader.class); this.vdbState.vdbName = vdb.getName(); this.vdbState.vdbVersion = vdb.getVersion(); this.vdbState.dqpWorkContext = newWorkContext; TempMetadataAdapter metadata = new TempMetadataAdapter(vdb.getAttachment(QueryMetadataInterface.class), globalState.sessionTempTableStore.getMetadataStore()); metadata.setSession(true); this.vdbState.metadata = metadata; }
public HashMap<String, DataPolicy> getAllowedDataPolicies() { if (this.policies == null) { this.policies = new HashMap<String, DataPolicy>(); Set<String> userRoles = getUserRoles(); // get data roles from the VDB VDBMetaData vdb = getVDB(); TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class); Collection<? extends DataPolicy> allPolicies = null; if (metadata == null) { allPolicies = vdb.getDataPolicies(); } else { allPolicies = metadata.getPolicies().values(); } for (DataPolicy policy : allPolicies) { if (matchesPrincipal(userRoles, policy)) { this.policies.put(policy.getName(), policy); } } } return this.policies; }