Esempio n. 1
0
 public void VisitorR_with_missing_type_throws()
 {
     var mocks = new MockRepository();
     var visitor = mocks.CreateMock<IVisitorR<Transaction, int>>();
     Transaction t = new AuthTransaction();
     int a = t.Accept(visitor);
 }
Esempio n. 2
0
 public void VisitorR_with_default_value()
 {
     var mocks = new MockRepository();
     var visitor = mocks.CreateMock<IVisitorR<SaleTransaction, int>>();
     Transaction t = new AuthTransaction();
     Assert.AreEqual(100, t.Accept(visitor, 100));
 }
Esempio n. 3
0
 public void VisitorR_with_default_func_with_param()
 {
     var mocks = new MockRepository();
     var visitor = mocks.CreateMock<IVisitorR<SaleTransaction, int>>();
     Transaction t = new AuthTransaction {Id = 101};
     Assert.AreEqual(101, t.Accept(visitor, x => x.Id));
 }
Esempio n. 4
0
 public void Visitor_with_default_action()
 {
     var mocks = new MockRepository();
     var visitor = mocks.CreateMock<IVisitor<SaleTransaction>>();
     Transaction t = new AuthTransaction();
     string r = null;
     t.Accept(visitor, () => r = "hi");
     Assert.AreEqual("hi", r);
 }
Esempio n. 5
0
        /// <summary>
        /// Initiates an asynchronous operation to authenticate user credentials.
        /// </summary>
        /// <param name="realm">Specifies the authentication scope.</param>
        /// <param name="account">The account.</param>
        /// <param name="password">The password.</param>
        /// <param name="callback">The delegate to be called when the operation completes (or <c>null</c>).</param>
        /// <param name="state">Application defined state (or <c>null</c>).</param>
        /// <returns>The <see cref="IAsyncResult" /> instance to be used to track the operation.</returns>
        /// <remarks>
        /// <note>
        /// All successful calls to <see cref="BeginAuthenticate" /> must eventually be
        /// matched by a call to <see cref="EndAuthenticate" />.
        /// </note>
        /// </remarks>
        public IAsyncResult BeginAuthenticate(string realm, string account, string password, AsyncCallback callback, object state)
        {
            AsyncResult     arAuth = new AsyncResult(null, callback, state);
            AuthTransaction transaction;
            RadiusPacket    packet;
            string          userName;
            int             ID;
            IPEndPoint      binding;

            using (TimedLock.Lock(this))
            {
                userName = Helper.GetUserName(realmFormat, realm, account);

                ID = GetTransactionID();
                if (ID == -1)
                {
                    throw new RadiusException("RADIUS client cannot track more than 256 simultaneous authentication requests.");
                }

                binding = GetServerBinding(ref serverPos);
                if (binding == NetworkBinding.Any)
                {
                    throw new RadiusException("None of the RADIUS server hosts resolve to an IP address.");
                }

                packet = new RadiusPacket(RadiusCode.AccessRequest, ID, Crypto.Rand(16));
                packet.Attributes.Add(new RadiusAttribute(RadiusAttributeType.UserName, userName));
                packet.Attributes.Add(new RadiusAttribute(RadiusAttributeType.UserPassword, packet.EncryptUserPassword(password, secret)));
                packet.Attributes.Add(new RadiusAttribute(RadiusAttributeType.NasIpAddress, nasIPAddress));

                transaction      = new AuthTransaction(userName, packet, serverPos, SysTime.Now + retryInterval, arAuth);;
                transactions[ID] = transaction;
                sock.SendTo(transaction.Packet.ToArray(), binding);

                arAuth.Result = null;
                arAuth.Started();
            }

            return(arAuth);
        }
Esempio n. 6
0
 public void Visitor_with_default_action_with_param()
 {
     var mocks = new MockRepository();
     var visitor = mocks.CreateMock<IVisitor<SaleTransaction>>();
     Transaction t = new AuthTransaction {Id = 33};
     string r = null;
     t.Accept(visitor, x => r = x.Id.ToString());
     Assert.AreEqual("33", r);
 }
Esempio n. 7
0
 public void Visitor_with_missing_type_throws()
 {
     var mocks = new MockRepository();
     var visitor = mocks.CreateMock<IVisitor<SaleTransaction>>();
     Transaction t = new AuthTransaction();
     t.Accept(visitor);
 }
 public void Visit(AuthTransaction visitable)
 {
     throw new NotImplementedException();
 }