protected void define(Session s, String uuid, String message, long started, CreationRequest req) { Long idle = req.timeToIdle == null ? defaultTimeToIdle : req.timeToIdle; Long live = req.timeToLive == null ? defaultTimeToLive : req.timeToLive; if (req.groupsLed != null) { CommentAnnotation ca = new CommentAnnotation(); ca.setNs(GROUP_SUDO_NS); StringBuilder sb = new StringBuilder(); for (int i = 0; i < req.groupsLed.size(); i++) { if (i > 0) { sb.append(","); } sb.append(req.groupsLed.get(i)); } ca.setTextValue(sb.toString()); s.linkAnnotation(ca); } define(s, uuid, message, started, idle, live, req.principal.getEventType(), req.agent, req.ip); }
public Share createShare(Principal principal, boolean enabled, long timeToLive, String eventType, String description, long groupId) { Share share = newShare(); define(share, UUID.randomUUID().toString(), description, System .currentTimeMillis(), defaultTimeToIdle, timeToLive, eventType, "Share", null); share.setGroup(new ExperimenterGroup(groupId, false)); share.setActive(enabled); share.setData(new byte[] {}); share.setItemCount(0L); CreationRequest req = new CreationRequest(); req.principal = principal; return (Share) createSession(req, share); }
/** * Initialization method called by the Spring run-time to acquire an initial * {@link Session}. */ public void init() { try { asroot = new Principal(internal_uuid, "system", "Sessions"); // Create a basic session Session session = new Session(); define(session, internal_uuid, "Session Manager internal", System.currentTimeMillis(), Long.MAX_VALUE, 0L, "Sessions", "Internal", null); session = sessionProvider.executeInternalSession(internal_uuid, session); internalSession = new InternalSessionContext(session, LightAdminPrivileges.getAllPrivileges(), roles); cache.putSession(internal_uuid, internalSession); } catch (UncategorizedSQLException uncat) { log.warn("Assuming that this is read-only"); } catch (DataAccessException dataAccess) { throw new RuntimeException( " " + "=====================================================\n" + "Data access exception: Did you create your database? \n" + "=====================================================\n", dataAccess); } }
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); }