@SuppressWarnings({ "unchecked", "rawtypes" }) public SessionContextImpl(Session session, Set<AdminPrivilege> adminPrivileges, List<Long> lGroups, List<Long> mGroups, List<String> roles, SessionStats stats, Roles _roles, SessionContext previous) { this._roles = _roles; this.stats = stats; this.session = session; if (previous != null) { this.count = previous.count(); this.shareId = previous.getCurrentShareId(); } else { this.count = new SessionContext.Count(session.getUuid()); } this.adminPrivileges = ImmutableSet.copyOf(adminPrivileges); this.leaderOfGroups = Collections.unmodifiableList(new ArrayList( lGroups)); this.memberOfGroups = Collections.unmodifiableList(new ArrayList( mGroups)); this.roles = Collections.unmodifiableList(new ArrayList(roles)); // Force NPE getCurrentGroupPermissions(); }
@Transactional(readOnly = true) public Object doWork(org.hibernate.Session session, ServiceFactory sf) { /* user and group names may change while the session is open */ final LocalAdmin admin = (LocalAdmin) sf.getAdminService(); final Experimenter exp = admin.userProxy(ctx.getCurrentUserId()); final ExperimenterGroup grp = admin.groupProxy(ctx.getCurrentGroupId()); final Principal p = new Principal(exp.getOmeName(), grp.getName(), ctx.getCurrentEventType()); return executeSessionContextLookup(sf, p, exp, grp, ctx.getSession()); } });
@Transactional(readOnly = true) public Object doWork(org.hibernate.Session session, ServiceFactory sf) { if (ec.getCurrentShareId() != null) { sf.getShareService().deactivate(); } SessionContext sc = cache.getSessionContext(principal.getName()); Session s = sc.getSession(); // Store old value for rollback if (!sc.isCurrentUserAdmin() && id >= 0 && !sc.getMemberOfGroupsList().contains(id)) { StringBuilder sb = new StringBuilder(); sb.append("User "); sb.append(sc.getCurrentUserId()); sb.append(" is not a member of group "); sb.append(id); throw new SecurityViolation(sb.toString()); } group[0] = s.getDetails().getGroup(); s.getDetails().setGroup(sf.getAdminService().getGroup(id)); return s; } });
for (Annotation a : sc.getSession().linkedAnnotationList()) { if (a instanceof TextAnnotation) { if (roles.isRootUser(a.getDetails().getOwner())) { final long activeMethods = sc.stats().methodCount(); final Long shareId = sc.getCurrentShareId(); final Long groupId = sc.getCurrentGroupId(); ome.model.IObject prevCtx = null;
SessionContext context = cache.getSessionContext(principal.getName()); if (context != null) { context.count().increment(); return context.getSession(); // EARLY EXIT! String uuid = newctx.getCurrentSessionUuid(); cache.putSession(uuid, newctx); try { newctx.count().increment(); return newctx.getSession();
defaultGroup = ctx.getCurrentGroupName(); Principal principal = new Principal(ctx.getCurrentUserName(), defaultGroup, ctx.getCurrentEventType()); CreationRequest req = new CreationRequest(); req.principal = principal;
private List<Session> findByQuery(String query, Parameters p) { List<Object[]> ids_uuids = executeProjection(query, p); List<Session> rv = new ArrayList<Session>(); for (Object[] arr : ids_uuids) { String uuid = (String) arr[1]; try { SessionContext sc = cache.getSessionContext(uuid); rv.add(sc.getSession()); } catch (Exception e) { // skip } } return rv; }
/** * Set the share id on the current session context. * * Previously this method was used throughout the code base in order to * "open up" a session. This however, has issues since it can lead to data * leakage (8037). Using the omero.group functionality (3529), this method * no longer needs to be public. * * @see <a href="https://trac.openmicroscopy.org/ome/ticket/2219">ticket:2219</a> * @see <a href="https://trac.openmicroscopy.org/ome/ticket/3529">ticket:3529</a> * @see <a href="https://trac.openmicroscopy.org/ome/ticket/8037">ticket:8037</a> */ private Long setShareId(Long shareId) { String sessId = getSecuritySystem().getEventContext().getCurrentSessionUuid(); SessionContext sc = (SessionContext) sessionManager .getEventContext(new Principal(sessId)); Long old = sc.getCurrentShareId(); sc.setShareId(shareId); return old; }
public Session createFromRequest(CreationRequest request) { // If credentials exist as session, then return that if (request.credentials != null) { try { SessionContext context = cache .getSessionContext(request.credentials); if (context != null) { context.count().increment(); return context.getSession(); // EARLY EXIT! } } catch (SessionException se) { // oh well. } // Though trusted values, if we receive a null principal, not ok; boolean ok = request.principal == null ? false : executeCheckPassword( request.principal, request.credentials); if (!ok) { log.warn("Failed to authenticate: " + request.principal); throw new AuthenticationException("Authentication exception."); } } // authentication checked. Now delegating to the admin method (no pass) Session session = new Session(); define(session, UUID.randomUUID().toString(), "Initial message.", System.currentTimeMillis(), request); return createSession(request, session); }
public int getReferenceCount(String uuid) { SessionContext ctx = cache.getSessionContext(uuid); return ctx.count().get(); }
@Transactional(readOnly = false) public Object doWork(org.hibernate.Session __s, ServiceFactory sf) { final Long sudoerId; if (orig.getSudoer() == null) { sudoerId = null; } else { sudoerId = orig.getSudoer().getId(); } return sessionProvider.executeUpdate(sf, copy, internal_uuid, newctx.getCurrentUserId(), sudoerId); } });
public Session find(String uuid) { SessionContext sessionContext = cache.getSessionContext(uuid); checkIfShare(sessionContext); return (sessionContext == null) ? null : sessionContext.getSession(); }
public int detach(String uuid) { SessionContext ctx = cache.getSessionContext(uuid); return ctx.count().decrement(); }
Data(SessionContext sc, long last, long count) { this.sessionContext = sc; this.lastAccessTime = last; this.hitCount = count; // clear context sc.getSession().getDetails().setContexts(null); }
public int close(String uuid) { SessionContext ctx; try { ctx = cache.getSessionContext(uuid); } catch (SessionException se) { log.info("closeSession called but doesn't exist: " + uuid); return -1; // EARLY EXIT! } int refCount = ctx.count().decrement(); if (refCount < 1) { log.info("closeSession called and no more references: " + uuid); cache.removeSession(uuid); return -2; } else { log.info("closeSession called but " + refCount + " more references: " + uuid); return refCount; } }
private void checkIfShare(SessionContext sessionContext) { if (sessionContext.getSession() instanceof Share) { final Long id = sessionContext.getSession().getId(); final String uuid = sessionContext.getSession().getUuid(); final String prefix = String.format("Share:%s (%s)", id, uuid); List<Object[]> rv = executeProjection( "select s.active, s.timeToLive, s.started from Share s where s.id = :id", new Parameters().addId(sessionContext.getSession().getId())); if (rv.size() != 1) { throw new RuntimeException(prefix + " could not be found!"); } Object[] items = rv.get(0); Boolean active = (Boolean) items[0]; Long timeToLive = (Long) items[1]; Timestamp started = (Timestamp) items[2]; if (Boolean.FALSE.equals(active)) { throw new SecurityViolation(prefix + " is inactive"); } else if ((System.currentTimeMillis() - started.getTime()) > timeToLive) { String msg = String.format("%s has expired: %s, timeToLive=%s", prefix, started, timeToLive); throw new SecurityViolation(msg); } } }
/** * Will be called in a synchronized block by {@link SessionCache} in order * to allow for an update. */ @SuppressWarnings({"rawtypes" }) public SessionContext reload(final SessionContext ctx) { List list = (List) executor.execute(asroot, new Executor.SimpleWork( this, "reload", ctx.getSession().getUuid()) { @Transactional(readOnly = true) public Object doWork(org.hibernate.Session session, ServiceFactory sf) { /* user and group names may change while the session is open */ final LocalAdmin admin = (LocalAdmin) sf.getAdminService(); final Experimenter exp = admin.userProxy(ctx.getCurrentUserId()); final ExperimenterGroup grp = admin.groupProxy(ctx.getCurrentGroupId()); final Principal p = new Principal(exp.getOmeName(), grp.getName(), ctx.getCurrentEventType()); return executeSessionContextLookup(sf, p, exp, grp, ctx.getSession()); } }); if (list == null) { return null; } return createSessionContext(list, ctx); }
long start = ctx.getSession().getStarted().getTime(); long timeToIdle = ctx.getSession().getTimeToIdle(); long timeToLive = ctx.getSession().getTimeToLive();
final Session currentSession; if (context instanceof SessionContext) { currentSession = ((SessionContext) context).getSession(); } else { currentSession = null;
final Session currentSession; if (context instanceof SessionContext) { currentSession = ((SessionContext) context).getSession(); } else { currentSession = null;