/** Monitoring logic used by background thread */ public void run() { try { boolean cleanRemoteSessions = false; synchronized (servers) { for (Map.Entry<String, ServerInfo> server : servers.entrySet()) { ServerInfo info = server.getValue(); info.isUp = checkServerUp(info); if (!info.isUp) { downServers.add(info.id); } else { if (!downServers.isEmpty() && downServers.remove(info.id)) { cleanRemoteSessions = true; } } } } if (cleanRemoteSessions) { sessionService.cleanUpRemoteSessions(); } } catch (Exception ex) { sessionDebug.error( "cleanRemoteSessions Background thread has encountered an Exception: " + ex.getMessage(), ex); } }
/** * Instantiates a new razor server, its services, and starts the scheduler. This can be replaced * by a dynamic handler manager but has the benefit of simplicity. */ public RazorServer() { super(); SERVICES.put(Service.ACCOUNT, AccountService.getInstance()); SERVICES.put(Service.ALERT, AlertService.getInstance()); SERVICES.put(Service.ASSET, AssetService.getInstance()); SERVICES.put(Service.ATTRIBUTE, AttributeService.getInstance()); SERVICES.put(Service.AUDIT, AuditService.getInstance()); SERVICES.put(Service.CONTRACT, ContractService.getInstance()); SERVICES.put(Service.FINANCE, FinanceService.getInstance()); SERVICES.put(Service.JOURNAL, JournalService.getInstance()); SERVICES.put(Service.IMAGE, ImageService.getInstance()); SERVICES.put(Service.IMAGETEXT, ImageTextService.getInstance()); SERVICES.put(Service.LICENSE, LicenseService.getInstance()); SERVICES.put(Service.LOCATION, LocationService.getInstance()); SERVICES.put(Service.MAIL, MailService.getInstance()); SERVICES.put(Service.MONITOR, MonitorService.getInstance()); SERVICES.put(Service.PARTNER, PartnerService.getInstance()); SERVICES.put(Service.PARTY, PartyService.getInstance()); SERVICES.put(Service.PRICE, PriceService.getInstance()); SERVICES.put(Service.PRODUCT, ProductService.getInstance()); SERVICES.put(Service.RATE, RateService.getInstance()); SERVICES.put(Service.REPORT, ReportService.getInstance()); SERVICES.put(Service.RESERVATION, ReservationService.getInstance()); SERVICES.put(Service.SESSION, SessionService.getInstance()); SERVICES.put(Service.SMS, SmsService.getInstance()); SERVICES.put(Service.TASK, TaskService.getInstance()); SERVICES.put(Service.TAX, TaxService.getInstance()); SERVICES.put(Service.TEXT, TextService.getInstance()); SERVICES.put(Service.WORKFLOW, WorkflowService.getInstance()); // startScheduler(); // PartnerService.startSchedulers(); }
@Override @RequestMapping(value = "/admin/suspendAccount", method = RequestMethod.POST) public ResponseEntity suspendAccount( @RequestBody AccountSuspensionInfo suspendInfo, @RequestHeader(value = "token") String token) { String actionName = "AdminControllerImpl.suspendAccount"; try { if (!sessionService.isSessionActive(token)) { return new ResponseEntity<>(HttpStatus.FORBIDDEN); } String userRoleForToken = sessionService.getUserRoleByToken(token); String usernameForToken = sessionService.getUsernameByToken(token); try { if (permissionService.isOperationAvailable(actionName, userRoleForToken)) { adminService.suspendAccount(suspendInfo); auditService.addEvent( new AuditItem( usernameForToken, actionName, suspendInfo.toString(), Constants.ADMIN_SUSPEND, true)); return new ResponseEntity<>(HttpStatus.OK); } else { auditService.addEvent( new AuditItem( usernameForToken, actionName, suspendInfo.toString(), Constants.NO_PERMISSION, false)); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } } catch (ServiceException serviceException) { auditService.addEvent( new AuditItem( usernameForToken, actionName, suspendInfo.toString(), serviceException.getMessage(), false)); return new ResponseEntity<>(serviceException.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); } catch (NotFoundException notFoundException) { auditService.addEvent( new AuditItem( usernameForToken, actionName, suspendInfo.toString(), notFoundException.getMessage(), false)); return new ResponseEntity<>(notFoundException.getMessage(), HttpStatus.NOT_FOUND); } } catch (ServiceException serviceException) { return new ResponseEntity<>(serviceException.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { if (!validateRequest(request)) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } String op = request.getParameter(OP); if (op.equals(RECOVER_OP)) { HttpSession httpSession = request.getSession(false); if (httpSession != null) { if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message( "GetHttpSession.recover: " + "Old HttpSession is obtained"); } SessionID sid = new SessionID(request); if (!sid.isNull()) { SessionService.getSessionService().retrieveSession(sid, httpSession); } } else { SessionService.sessionDebug.error( "GetHttpSession.recover: " + "Old HttpSession is not obtained"); } } else if (op.equals(SAVE_OP)) { HttpSession httpSession = request.getSession(false); if (httpSession != null) { if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message("GetHttpSession.save: HttpSession is obtained"); } SessionID sid = new SessionID(request); if (!sid.isNull()) { int status = SessionService.getSessionService().handleSaveSession(sid, httpSession); response.setStatus(status); } } else { SessionService.sessionDebug.error("GetHttpSession.save: HttpSession is not obtained"); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } else if (op.equals(CREATE_OP)) { HttpSession httpSession = request.getSession(true); String domain = request.getParameter(DOMAIN); InternalSession is = SessionService.getSessionService().newInternalSession(domain, httpSession); if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message( "GetHttpSession.create: Created new session=" + is.getID()); } DataOutputStream out = new DataOutputStream(response.getOutputStream()); out.writeUTF(is.getID().toString()); out.flush(); out.close(); } else if (op.equals(INVALIDATE_OP)) { HttpSession httpSession = request.getSession(false); if (httpSession != null) { if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message( "GetHttpSession.invalidate: " + "HttpSession is obtained"); } try { httpSession.invalidate(); } catch (IllegalStateException ise) { if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message( "Exception:invalidateSession: the web " + "containers session timeout could be " + "shorter than the OpenSSO session " + "timeout", ise); } } } else { if (SessionService.sessionDebug.warningEnabled()) { SessionService.sessionDebug.warning( "GetHttpSession.invalidate: session is " + "not obtained"); } } } else if (op.equals(RELEASE_OP)) { SessionID sid = new SessionID(request); if (!sid.isNull()) { if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message("GetHttpSession.release: releasing session=" + sid); } int status = SessionService.getSessionService().handleReleaseSession(sid); response.setStatus(status); } else { if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message("GetHttpSession.release: missing session id"); } } } else if (op.equals(GET_RESTRICTED_TOKEN_OP)) { DataInputStream in = null; DataOutputStream out = null; SessionID sid = new SessionID(request); try { in = new DataInputStream(request.getInputStream()); TokenRestriction restriction = TokenRestrictionFactory.unmarshal(in.readUTF()); String token = SessionService.getSessionService().handleGetRestrictedTokenIdRemotely(sid, restriction); if (token != null) { if (SessionService.sessionDebug.messageEnabled()) { SessionService.sessionDebug.message( "GetHttpSession.get_restricted_token: " + "Created new session=" + token); } response.setStatus(HttpServletResponse.SC_OK); out = new DataOutputStream(response.getOutputStream()); out.writeUTF(token); out.flush(); } else { SessionService.sessionDebug.error( "GetHttpSession.get_restricted_token: " + "failed to create token"); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (Exception ex) { SessionService.sessionDebug.error( "GetHttpSession.get_restricted_token: " + "exception occured while create token", ex); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } finally { SessionService.closeStream(in); SessionService.closeStream(out); } } else { SessionService.sessionDebug.error("GetHttpSession: unknown operation requested"); response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); } }
public void unregisterIntentReceiver() { SessionService.getInstance().getContext().unregisterReceiver(ir); }
public void initIntentReceiver() { ir = new IntentReceiver(); Context context = SessionService.getInstance().getContext(); context.registerReceiver(ir, new IntentFilter(Const.INTENT_PREFIX + "login")); context.registerReceiver(ir, new IntentFilter(Const.INTENT_PREFIX + "logout")); }
public void initialize(XMPPConnection connection) { this.connection = connection; this.timeout = SessionService.getInstance().getPreferences().getLong("pref_xmpp_timeout", 10000); }