예제 #1
0
        public void AuthServiceMsgs_Msg_AuthControlMsg()
        {
            EnhancedStream es = new EnhancedMemoryStream();
            AuthControlMsg msgIn, msgOut;

            msgOut = new AuthControlMsg("my command", "a=test1;b=test2;c=test3");

            Msg.Save(es, msgOut);
            es.Position = 0;
            msgIn       = (AuthControlMsg)Msg.Load(es);

            Assert.AreEqual("my command", msgIn.Command);
            Assert.AreEqual("test1", msgIn.Get("a", null));
            Assert.AreEqual("test2", msgIn.Get("b", null));
            Assert.AreEqual("test3", msgIn.Get("c", null));
            Assert.AreEqual("foobar", msgIn.Get("d", "foobar"));

            msgOut = new AuthControlMsg("hello", null);

            Msg.Save(es, msgOut);
            es.Position = 0;
            msgIn       = (AuthControlMsg)Msg.Load(es);

            Assert.AreEqual("my command", msgIn.Command);
        }
예제 #2
0
        public void OnMsg(AuthControlMsg msg)
        {
            try
            {
                using (TimedLock.Lock(this))
                {
                    if (!isOpen)
                    {
                        return;
                    }

                    switch (msg.Command)
                    {
                    case "auth-key-update":

                        publicKey = null;           // This will force the retrieval of a new key
                        break;                      // on the next auth request

                    case "cache-clear":

                        if (cache != null)
                        {
                            cache.Clear();
                        }

                        break;

                    case "cache-remove-realm":

                        if (cache != null)
                        {
                            CacheRemove(msg.Get("realm", string.Empty) + "\t");
                        }

                        break;

                    case "lock-account":
                    case "cache-remove-account":

                        if (cache != null)
                        {
                            CacheRemove(msg.Get("realm", string.Empty) + "\t" + msg.Get("account", string.Empty) + "\t");
                        }

                        break;

                    default:

                        SysLog.LogWarning("Unexpected authentication control command [{0}].", msg.Command);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                SysLog.LogException(e);
            }
        }
예제 #3
0
        /// <summary>
        /// Broadcasts a message that commands all authentication client and service instances on the network
        /// to reload their realm maps.
        /// </summary>
        public void BroadcastLoadRealmMap()
        {
            AuthControlMsg msg;

            using (TimedLock.Lock(this))
            {
                if (!isOpen)
                {
                    throw new AuthenticationException(NotOpenMsg);
                }

                msg = new AuthControlMsg("load-realm-map", null);
                router.BroadcastTo(AbstractAuthEP, msg);
            }
        }
예제 #4
0
        /// <summary>
        /// Broadcasts a message that commands all authentication client and service instances on the network
        /// to lock an account.
        /// </summary>
        /// <param name="realm">The authentication realm.</param>
        /// <param name="account">The account.</param>
        /// <param name="lockTTL">The lock duration.</param>
        public void BroadcastAccountLock(string realm, string account, TimeSpan lockTTL)
        {
            AuthControlMsg msg;

            using (TimedLock.Lock(this))
            {
                if (!isOpen)
                {
                    throw new AuthenticationException(NotOpenMsg);
                }

                msg = new AuthControlMsg("lock-account", string.Format("realm={0};account={1};source-id={2};lock-ttl={3}",
                                                                       realm, account, Helper.NewGuid(), Serialize.ToString(lockTTL)));
                router.BroadcastTo(AbstractAuthEP, msg);
            }
        }