private void checkAuth(HttpServletRequest req, HttpServletResponse resp, PersistenceManager pm) throws IOException { String idString = req.getRequestURI().substring("/check-auth/".length()); if (idString.isEmpty()) { LOGGER.warning("empty session id"); setResponse(resp, 418, "FAIL"); } else { long id = Long.parseLong(idString); SqlCloudSession sqlCloudSession = lookupCloudSessionById(id, pm); if (sqlCloudSession == null) { setResponse(resp, 418, "FAIL"); } else { DbUser user = persistenceHelper.getObjectById( pm, persistenceHelper.getDbUserClass(), sqlCloudSession.getUser()); setResponse(resp, 200, "OK\n" + sqlCloudSession.getRandomID() + "\n" + user.getEmail()); } } resp.flushBuffer(); }
private void recordSession( PersistenceManager pm, SqlCloudSession session, DbInvocation invocation) { Transaction tx; session.setInvocation(invocation); tx = pm.currentTransaction(); tx.begin(); try { pm.makePersistent(session); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } } }
private DbInvocation recordInvocation( PersistenceManager pm, LogIn loginMsg, SqlCloudSession session) { DbInvocation invocation = persistenceHelper.createDbInvocation(); invocation.setWho(session.getUser()); invocation.setStartTime(loginMsg.getAnalysisTimestamp()); Transaction tx = pm.currentTransaction(); tx.begin(); try { invocation = pm.makePersistent(invocation); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } } return invocation; }