target = newShare(); } else { target = new Session(); target.setId(source.getId()); target.setClosed(source.getClosed()); target.setDefaultEventType(source.getDefaultEventType()); target.getDetails().shallowCopy(source.getDetails()); target.setMessage(source.getMessage()); target.setNode(source.getNode()); target.setStarted(source.getStarted()); target.setTimeToIdle(source.getTimeToIdle()); target.setTimeToLive(source.getTimeToLive()); target.setUserAgent(source.getUserAgent()); target.setUuid(source.getUuid());
return null; } else if (field.equals(ID)) { return getId(); } else if (field.equals(VERSION)) { return getVersion(); } else if (field.equals(NODE)) { return getNode(); } else if (field.equals(UUID)) { return getUuid(); } else if (field.equals(OWNER)) { return getOwner(); } else if (field.equals(SUDOER)) { return getSudoer(); } else if (field.equals(TIMETOIDLE)) { return getTimeToIdle(); } else if (field.equals(TIMETOLIVE)) { return getTimeToLive(); } else if (field.equals(STARTED)) { return getStarted(); } else if (field.equals(CLOSED)) { return getClosed(); } else if (field.equals(MESSAGE)) { return getMessage(); } else if (field.equals(DEFAULTEVENTTYPE)) { return getDefaultEventType(); } else if (field.equals(USERAGENT)) { return getUserAgent(); } else if (field.equals(USERIP)) { return getUserIP();
@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. } session.setNode(node); session.setOwner(new Experimenter(userId, false)); if (sudoerId == null) { session.setSudoer(null); } else { session.setSudoer(new Experimenter(sudoerId, false)); } Session rv = sf.getUpdateService().saveAndReturnObject(session); rv.putAt("#2733", session.retrieve("#2733")); return rv; }
public Session( ome.model.meta.Node _node,java.lang.String _uuid,ome.model.meta.Experimenter _owner,java.lang.Long _timeToIdle,java.lang.Long _timeToLive,java.sql.Timestamp _started,java.lang.String _defaultEventType ) { this(null, true); setNode(_node); setUuid(_uuid); setOwner(_owner); setTimeToIdle(_timeToIdle); setTimeToLive(_timeToLive); setStarted(_started); setDefaultEventType(_defaultEventType); }
protected void define(Session s, String uuid, String message, long started, long idle, long live, String eventType, String agent, String ip) { s.getDetails().setPermissions(Permissions.PRIVATE); s.setUuid(uuid); s.setMessage(message); s.setStarted(new Timestamp(started)); s.setTimeToIdle(idle); s.setTimeToLive(live); s.setDefaultEventType(eventType); s.setUserAgent(agent); s.setUserIP(ip); }
@Override public void executeCloseSession(String uuid) { Session session = openSessions.get(uuid); if (session == null) { if (closedSessions.containsKey(uuid)) { log.debug("attempt to close session {} but is already closed", uuid); } else { log.warn("attempt to close session {} but is no longer cached", uuid); } } else { session.setClosed(new Timestamp(System.currentTimeMillis())); closedSessions.put(session.getUuid(), session); openSessions.remove(session.getUuid()); log.debug("closed session {}", uuid); } }
return; } else if (field.equals(ID)) { setId((Long) value); } else if (field.equals(VERSION)) { setVersion((Integer) value); } else if (field.equals(NODE)) { setNode((ome.model.meta.Node)value); } else if (field.equals(UUID)) { setUuid((java.lang.String)value); } else if (field.equals(OWNER)) { setOwner((ome.model.meta.Experimenter)value); } else if (field.equals(SUDOER)) { setSudoer((ome.model.meta.Experimenter)value); } else if (field.equals(TIMETOIDLE)) { setTimeToIdle((java.lang.Long)value); } else if (field.equals(TIMETOLIVE)) { setTimeToLive((java.lang.Long)value); } else if (field.equals(STARTED)) { setStarted((java.sql.Timestamp)value); } else if (field.equals(CLOSED)) { setClosed((java.sql.Timestamp)value); } else if (field.equals(MESSAGE)) { setMessage((java.lang.String)value); } else if (field.equals(DEFAULTEVENTTYPE)) { setDefaultEventType((java.lang.String)value); } else if (field.equals(USERAGENT)) { setUserAgent((java.lang.String)value); } else if (field.equals(USERIP)) { setUserIP((java.lang.String)value);
params.put("ttl", session.getTimeToLive()); params.put("tti", session.getTimeToIdle()); params.put("start", session.getStarted()); params.put("type", session.getDefaultEventType()); params.put("uuid", session.getUuid()); params.put("node", nodeId); params.put("owner", roles.getRootId()); params.put("agent", session.getUserAgent()); params.put("ip", session.getUserIP()); int count = sql.insertSession(params); if (count == 0) { throw new InternalException( "Failed to insert new session: " + session.getUuid()); Long id = sql.sessionId(session.getUuid()); session.setNode(new Node(nodeId, false)); session.setOwner(new Experimenter(roles.getRootId(), false)); session.setId(id); return session;
@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; }
@Override public ServantHolder call() { return new ServantHolder(s.getUuid(), servantsPerSession); } });
@Override public Session executeInternalSession(final String uuid, Session session) { Node node = (Node) executor.executeSql(new Executor.SimpleSqlWork(this, "executeInternalSession") { @Transactional(readOnly = true) public Object doWork(SqlAction sql) { final Long nodeId = nodeProvider.getManagerIdByUuid(uuid, sql); return nodeId == null ? null : new Node(nodeId, false); } }); session.setId(executeNextSessionId()); log.debug("Created session: {}", session); log.debug("Setting node: {}", node); session.setNode(node); session.setOwner(new Experimenter(roles.getRootId(), false)); openSessions.put(session.getUuid(), session); return session; }
if ( ! session.isLoaded()) { return session; } else if (acl == null) { return new Session(session.getId(), false); } else { EventContext ec = current.getCurrentEventContext(); if (!ec.isCurrentUserAdmin()) { Long uid = session.getOwner().getId(); if (!ec.getCurrentUserId().equals(uid)) { return new Session(session.getId(), false);
@Transactional(readOnly = true) public Object doWork(Session session, ServiceFactory sf) { final Long sessionId = sessionProvider.findSessionIdByUuid(userId, sf); final ome.model.meta.Session s = sessionId == null ? null : sessionProvider.findSessionById(sessionId, sf); IQuery q = sf.getQueryService(); Experimenter e = null; if (s != null) { e = s.getOwner(); if (!e.isLoaded()) { e = q.get(Experimenter.class, e.getId()); } data.add(String.format("user=%s", e.getOmeName())); } else { e = q.findByString(Experimenter.class, "omeName", userId); if (e != null) { data.add(String.format("id=%s", e.getId())); } } if (s != null) { data.add(String.format("created=%s", s.getStarted())); data.add(String.format("closed=%s", s.getClosed())); } return null; } });
public Session call() throws Exception { final CreationRequest req = new CreationRequest(); req.principal = principal; req.agent = "createSession"; if (currentSession != null) { final Experimenter sudoer = currentSession.getSudoer(); if (sudoer != null) { req.sudoer = sudoer.getId(); } } final Session session = mgr.createFromRequest(req); session.setTimeToIdle(timeToIdleMs); session.setTimeToLive(timeToLiveMs); return mgr.update(session, false); }}); return ex.get(future);
/** * 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. * Assumes that <tt>root</tt> has all light administrator privileges. * @param session an OMERO session * @return the light administrator privileges associated with the session */ private ImmutableSet<AdminPrivilege> getPrivileges(Session session) { final Set<AdminPrivilege> privileges = new HashSet<>(getAllPrivileges()); removeUserPrivileges(session.getSudoer(), privileges); removeUserPrivileges(session.getOwner(), privileges); return ImmutableSet.copyOf(privileges); }
public Session update(final Session session, final boolean trusted) { if (session == null || !session.isLoaded() || session.getUuid() == null) { throw new RemovedSessionException("Cannot update; No uuid."); final String uuid = session.getUuid(); final Details details = session.getDetails(); final SessionContext ctx = cache.getSessionContext(uuid); if (ctx == null) {
session.setTimeToLive(timeToLive); } else { + maxUserTimeToLive); session.setTimeToLive(activeTTL); session.setTimeToIdle(timeToIdle); } else { long activeTTI = Math.min(maxUserTimeToIdle, timeToIdle); + maxUserTimeToIdle); session.setTimeToIdle(activeTTI);
/** * Wrap a {@link Session} instance. * @param session the session to wrap */ private SessionEqualById(Session session) { this.session = session; this.sessionId = session.getId(); }
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); } } }
long start = ctx.getSession().getStarted().getTime(); long timeToIdle = ctx.getSession().getTimeToIdle(); long timeToLive = ctx.getSession().getTimeToLive();