@Override public Action inspect(final AtmosphereResource r) { final SecurityContext context = (SecurityContext) r.getRequest().getSession() .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); SecurityContextHolder.setContext(context); return Action.CONTINUE; }
@Override public Action inspect(final AtmosphereResource r) { final SecurityContext context = (SecurityContext) r.getRequest().getSession() .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); SecurityContextHolder.setContext(context); return Action.CONTINUE; }
private String getCurrentUserId(AtmosphereResource resource) { if (resource.getRequest().getSession() == null) { return null; } String userId = CurrentUser.getUserId(resource.getRequest()); if (userId != null && userId.trim().length() > 0) { return userId; } return null; }
@Override public Action suspended(AtmosphereRequest request, AtmosphereResponse response) throws IOException, ServletException { Action a = super.suspended(request, response); if (framework.getAtmosphereConfig().isSupportSession()) { AtmosphereResource r = request.resource(); HttpSession s = request.getSession(true); if (s != null) { sessions.put(r.uuid(), request.getSession(true)); } } return a; }
@Override public Action suspended(AtmosphereRequest request, AtmosphereResponse response) throws IOException, ServletException { Action a = super.suspended(request, response); if (framework.getAtmosphereConfig().isSupportSession()) { AtmosphereResource r = request.resource(); HttpSession s = request.getSession(true); if (s != null) { sessions.put(r.uuid(), request.getSession(true)); } } return a; }
private final void addContextValue(AtmosphereRequest request, String name, Object value) { if (request.resource().transport().equals(AtmosphereResource.TRANSPORT.WEBSOCKET)) { request.setAttribute(name, value); } else { request.getSession().setAttribute(name, value); } }
private final Object getContextValue(AtmosphereRequest request, String name) { if (request.resource().transport().equals(AtmosphereResource.TRANSPORT.WEBSOCKET)) { return request.getAttribute(name); } else { return request.getSession().getAttribute(name); } }
private void flushData(AtmosphereResponse r, byte[] data) throws IOException { BlockingQueue<AtmosphereResource> queue = (BlockingQueue<AtmosphereResource>) request.getSession().getAttribute("PendingResource"); if (queue != null) { AtmosphereResource resource; try { resource = queue.take(); } catch (InterruptedException e) { throw new IOException(e); } resource.getResponse().getOutputStream().write(data); resource.resume(); r.flushBuffer(); } else { r.write(data); } }
@Override public HttpSession getSession(boolean create) { if (atmResource.session() != null) { return atmResource.session(); } else if (atmResource.getRequest() != null) { return atmResource.getRequest().getSession(create); } else { return null; } }
@Override public HttpSession getSession(boolean create) { if (atmResource.session() != null) { return atmResource.session(); } else if (atmResource.getRequest() != null) { return atmResource.getRequest().getSession(create); } else { return null; } }
/** * {@inheritDoc} */ @Override public void action(AtmosphereResourceImpl actionEvent) { super.action(actionEvent); if (actionEvent.isInScope() && actionEvent.action().type() == Action.TYPE.RESUME) { try { RequestResponseKey rrk = (RequestResponseKey) actionEvent.getRequest().getSession().getAttribute(RRK); AbstractAsyncServlet.notify(rrk, null); } catch (IOException ex) { logger.debug("action failed", ex); } } }
if (queue == null) { queue = new LinkedBlockingQueue<AtmosphereResource>(); request.getSession().setAttribute(SUSPENDED_RESPONSE, queue);
@Override public BroadcastAction filter(String broadcasterId, AtmosphereResource r, Object originalMessage, Object message) { ensureInitialized(); try { if (message == null || r.isCancelled()) { return new BroadcastAction(BroadcastAction.ACTION.ABORT, null); } JSONObject json = new JSONObject(message.toString()); if (shouldSendMessage(json, r.getRequest().getSession())) { return new BroadcastAction(message); } else { return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); } } catch (JSONException e) { LOGGER.error("Failed to filter message:\n" + originalMessage, e); return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); } }
BlockingQueue<AtmosphereResource> queue = (BlockingQueue<AtmosphereResource>) request.getSession().getAttribute("PendingResource"); if (queue == null) { queue = new LinkedBlockingQueue<AtmosphereResource>(); request.getSession().setAttribute("PendingResource", queue); List<AtmosphereRequest> list = new ArrayList<AtmosphereRequest>(); if (handshakeTx.replaceAll(" ", "").startsWith("{\"handshake\"")) { request.getSession().invalidate(); HandshakeMessage handshakeMessage = mapper.readValue(data, HandshakeMessage.class); String identity = UUID.randomUUID().toString(); request.getSession().setAttribute("swaggersocket.identity", identity); request.setAttribute("swaggersocket.handshake", identity); Message swaggerSocketMessage = mapper.readValue(data, Message.class); String identity = (String) request.getSession().getAttribute("swaggersocket.identity");
if (queue == null) { queue = new LinkedBlockingQueue<AtmosphereResource>(); request.getSession().setAttribute(SUSPENDED_RESPONSE, queue); logger.debug("Client disconnected {}, cleaning session {}", identity); try { Enumeration<String> e = request.getSession().getAttributeNames(); while (e.hasMoreElements()) { request.getSession().removeAttribute(e.nextElement()); request.getSession().invalidate(); } catch (Exception ex) { logger.warn("", ex);
private void onDisconnectOrClose(AtmosphereResourceEvent event) { // If POST /logout was called first the session will be invalidated. if (event.getResource() == null || event.getResource().getRequest() == null || event.getResource().getRequest().getSession() == null) { return; } boolean lastSession = decrementUserSessionCount(event.getResource()); if (lastSession) { String userId = getCurrentUserId(event.getResource()); LOGGER.info("last session for user %s", userId); setStatus(event.getResource(), UserStatus.OFFLINE); auditService.auditLogout(userId); } }