/** * Wrap a {@link Session} instance. * @param session the session to wrap */ private SessionEqualById(Session session) { this.session = session; this.sessionId = session.getId(); }
@Override public Long findSessionIdByUuid(String uuid) { for (final Map<String, Session> sessions : ImmutableList.of(openSessions, closedSessions)) { final Session session = sessions.get(uuid); if (session != null) { return session.getId(); } } return null; }
@Override public Session findSessionById(long id, ServiceFactory sf) { final SortedSet<Long> tries = new TreeSet<Long>(); /* in Java 8 maybe could use Stream instead of Iterables */ for (final Session session : Iterables.concat(openSessions.values(), closedSessions.values())) { if (session.getId().equals(id)) { return session; } else { tries.add(session.getId()); } } log.info("Requested unknown session ID {}. Found {} other sessions.", id, tries.size()); log.debug("Found sessions: {}", tries); return null; }
public Long getCurrentSessionId() { return getSession().getId(); }
@Override public Long findSessionIdByUuid(final String uuid, ServiceFactory sf) { final Session session = sf.getQueryService().findByString(Session.class, "uuid", uuid); return session == null ? null : session.getId(); }
/** * Determine the light administrator privileges associated with a session. * If the session originates via <q>sudo</q>, takes that into account. * Does <em>not</em> take account of if the relevant user is a member of <tt>system</tt>: * calculates assuming that the user is an administrator. * @param session an OMERO session * @param isCache if newly fetched privileges should be cached for future lookups * @return the light administrator privileges associated with the session */ private ImmutableSet<AdminPrivilege> getSessionPrivileges(Session session, boolean isCache) { final SessionEqualById wrappedSession = new SessionEqualById(session); try { if (isCache) { return PRIVILEGE_CACHE.get(wrappedSession); } else { final ImmutableSet<AdminPrivilege> privileges = PRIVILEGE_CACHE.getIfPresent(wrappedSession); if (privileges != null) { return privileges; } else { return getPrivileges(session); } } } catch (ExecutionException ee) { LOGGER.warn("failed to check privileges for session " + session.getId(), ee.getCause()); return ImmutableSet.of(); } }
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); } } }
final List<Long> leaderOfGroupsIds = admin.getLeaderOfGroupIds(exp); final List<String> userRoles = admin.getUserRoles(exp); final Session reloaded = sessionProvider.findSessionById(session.getId(), sf); final Experimenter sudoer = reloaded.getSudoer(); boolean hasAdminPrivileges = memberOfGroupsIds.contains(roles.getSystemGroupId());
final Set<Long> ids = new HashSet<Long>(); for (ome.model.meta.Session s : shares) { ids.add(s.getId());
return null; } else if (field.equals(ID)) { return getId(); } else if (field.equals(VERSION)) { return getVersion();
@Override public Session executeUpdate(ServiceFactory sf, Session session, String uuid, long userId, Long sudoerId) { Node node = nodeProvider.getManagerByUuid(uuid, sf); if (node == null) { node = new Node(0L, false); // Using default node. } if (session.getId() == null) { session.setId(executeNextSessionId()); } session.setNode(node); session.setOwner(new Experimenter(userId, false)); if (sudoerId == null) { session.setSudoer(null); } else { session.setSudoer(new Experimenter(sudoerId, false)); } /* put before remove so that the session is never missing altogether */ if (session.getClosed() == null) { openSessions.put(session.getUuid(), session); closedSessions.remove(session.getUuid()); } else { closedSessions.put(session.getUuid(), session); openSessions.remove(session.getUuid()); } log.debug("Registered Session:{} ({})", session.getId(), session.getUuid()); return session; }
target.setId(source.getId()); target.setClosed(source.getClosed()); target.setDefaultEventType(source.getDefaultEventType());