private static void sendEvent(Event event) { Bundle bundle = FrameworkUtil.getBundle(EventUtil.class); BundleContext bundleContext = bundle.getBundleContext(); String name = EventAdmin.class.getName(); ServiceTracker<EventAdmin, EventAdmin> tracker = new ServiceTracker<EventAdmin, EventAdmin>(bundleContext, name, null); tracker.open(); EventAdmin eventAdmin = tracker.getService(); tracker.close(); if (eventAdmin != null) { eventAdmin.sendEvent(event); } }
@Override public void process( Object message, Map<String, Object> headers, ReplyConnection replyConnection) { if (message instanceof byte[]) { OteEventMessage msg = new OteEventMessage((byte[]) message); UUID id = OteEventMessageUtil.getUUID(msg); if (!id.equals(MYID)) { OteEventMessageUtil.setUUID(msg, MYID); Map<String, Object> data = new HashMap<>(); data.put(OteEventMessageUtil.BYTE_KEY, msg.getData()); Event newevent = new Event(msg.getHeader().TOPIC.getValue(), data); eventAdmin.sendEvent(newevent); } } else { OseeLog.log( EventToJmsComponent.class, Level.SEVERE, "not a recognized message" + message.getClass()); } }
@Override public boolean send(String topic, Object data) { Event event = constructEvent(topic, data); Activator activator = Activator.getDefault(); if (activator == null) { if (logger != null) { logger.error(NLS.bind(ServiceMessages.NO_EVENT_ADMIN, event.toString())); } return false; } EventAdmin eventAdmin = activator.getEventAdmin(); if (eventAdmin == null) { if (logger != null) { logger.error(NLS.bind(ServiceMessages.NO_EVENT_ADMIN, event.toString())); } return false; } eventAdmin.sendEvent(event); return true; }
/** * Inject a token into the request/response, this assumes htat the getUserPrincipal() of the * request or the request.getRemoteUser() contain valid user ID's from which to generate the * request. * * @param req * @param resp * @param readOnlyToken if true, the session or cookie will only allow read only operations in the * server. */ public String injectToken( HttpServletRequest request, HttpServletResponse response, String tokenType, UserValidator userValidator) { if (testing) { calls.add(new Object[] {"injectToken", request, response}); return "testing"; } String userId = null; String remoteAddress = request.getRemoteAddr(); if (trustedProxyServerAddrSet.contains(remoteAddress)) { if (trustedHeaderName.length() > 0) { userId = request.getHeader(trustedHeaderName); if (userId != null) { LOG.debug( "Injecting Trusted Token from request: Header [{}] indicated user was [{}] ", 0, userId); } } if (userId == null && trustedParameterName.length() > 0) { userId = request.getParameter(trustedParameterName); if (userId != null) { LOG.debug( "Injecting Trusted Token from request: Parameter [{}] indicated user was [{}] ", trustedParameterName, userId); } } } if (userId == null) { Principal p = request.getUserPrincipal(); if (p != null) { userId = p.getName(); if (userId != null) { LOG.debug( "Injecting Trusted Token from request: User Principal indicated user was [{}] ", userId); } } } if (userId == null) { userId = request.getRemoteUser(); if (userId != null) { LOG.debug( "Injecting Trusted Token from request: Remote User indicated user was [{}] ", userId); } } if (userValidator != null) { userId = userValidator.validate(userId); } if (userId != null) { if (usingSession) { HttpSession session = request.getSession(true); if (session != null) { LOG.debug("Injecting Credentials into Session for " + userId); session.setAttribute(SA_AUTHENTICATION_CREDENTIALS, createCredentials(userId, tokenType)); } } else { addCookie(response, userId, tokenType); } Dictionary<String, Object> eventDictionary = new Hashtable<String, Object>(); eventDictionary.put(TrustedTokenService.EVENT_USER_ID, userId); // send an async event to indicate that the user has been trusted, things that want to create // users can hook into this. eventAdmin.sendEvent(new Event(TrustedTokenService.TRUST_USER_TOPIC, eventDictionary)); return userId; } else { LOG.warn("Unable to inject token; unable to determine user from request."); } return null; }
@Override public boolean send(String topic, Object data) { Event event = constructEvent(topic, data); eventAdmin.sendEvent(event); return true; }