Пример #1
0
        private static void OnAuthReceived(object sender, BasicDeliverEventArgs args)
        {
            var body  = args.Body;
            var token = Encoding.UTF8.GetString(body);

            var rabbitMqProducer = RabbitMqProducer.Create(StaticQueues.LoggingQueue);

            Console.WriteLine($"Gained token: {token}, Start writing messages.");
            while (true)
            {
                var message = Console.ReadLine();

                if (message == "q")
                {
                    break;
                }

                var payload = new LoggingMessage {
                    Sender = APPLICATIONID, Group = GROUPID, Body = message
                };
                var json            = JsonConvert.SerializeObject(payload);
                var basicProperties =
                    new BasicProperties {
                    Headers = new Dictionary <string, object> {
                        { "token", token }
                    }
                };
                rabbitMqProducer.SendMessage(json, basicProperties);
            }

            rabbitMqProducer.Disconnect();
        }
Пример #2
0
        private static void ConsumerOnReceived(object sender, BasicDeliverEventArgs e)
        {
            // Read the body into a UTF8 string.
            var body    = e.Body;
            var message = Encoding.UTF8.GetString(body);

            string json;

            try
            {
                json = EncryptProvider.AESDecrypt(message, KEY, IV);
                if (string.IsNullOrWhiteSpace(json))
                {
                    throw new ArgumentNullException(nameof(json));
                }
            }
            catch
            {
                Log.Warning("Invalid attempt to send message, wrong encryption Key and IV");
                return;
            }

            var service = JsonConvert.DeserializeObject <Service>(json);

            // Generate a new authentication token.
            var token = TokenProducer.ProduceToken();

            service.Token = token;

            SaveService(service);

            var producer = RabbitMqProducer.Create(service.ApplicationId);

            producer.SendMessage(token);
        }
Пример #3
0
        /// <summary>
        /// Main method ran when executing the program.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            ConfigureLogger();
            Log.Information("Setting up MicroMonitor Authentication Token Provider");
            _authProducer = RabbitMqProducer.Create(string.Empty, StaticQueues.IsAuthenticatedReply);
            _authReceiver = RabbitMqReceiver.Create(StaticQueues.IsAuthenticated, IsAuthenticatedOnReceived);

            _authReceiver.Run();
            Log.Information("Setup complete, waiting for request.");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AuthenticationFlow"/> class.
        /// </summary>
        public AuthenticationFlow(bool useAuthentication)
        {
            if (!useAuthentication)
            {
                return;
            }

            _unprocessed         = new Dictionary <string, string>();
            _authenticatedTokens = new Dictionary <string, Service>();
            _authSender          = RabbitMqProducer.Create(StaticQueues.IsAuthenticated);
            var faker = new Faker();

            _replyReceiver = RabbitMqReceiver.Create(faker.Random.AlphaNumeric(15), ConsumerOnReceived, StaticQueues.IsAuthenticatedReply);

            _replyReceiver.Run();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Test Client");
            Console.WriteLine("Waiting for services to start...\nPress enter when ready.");
            Console.ReadLine();

            authProducer = RabbitMqProducer.Create(StaticQueues.RequestAuth);

            authReceiver = RabbitMqReceiver.Create(APPLICATIONID, OnAuthReceived);

            var service = new Service {
                ApplicationId = APPLICATIONID, GroupId = GROUPID
            };

            var json = JsonConvert.SerializeObject(service);

            var encrypt = EncryptProvider.AESEncrypt(json, KEY, IV);

            authProducer.SendMessage(encrypt);
            Console.WriteLine("Waiting for response.");
        }