Exemplo n.º 1
0
        public void TestAuthForGoodUserThreaded()
        {
            const int TotalAuthCalls = 5000;

            Console.WriteLine("Running {0} threaded auth tests...", TotalAuthCalls);
            var       complete = 0;
            Stopwatch sw       = new Stopwatch();

            sw.Start();
            for (int i = 0; i < (TotalAuthCalls / 2); i++)
            {
                var thread1 = new Thread(() => { Assert.True(NpamUser.Authenticate(NpamTestsCommon.TestService, NpamTestsCommon.TestUsernameGood, NpamTestsCommon.TestPassword)); Interlocked.Increment(ref complete); });
                var thread2 = new Thread(() => { Assert.False(NpamUser.Authenticate(NpamTestsCommon.TestService, NpamTestsCommon.TestUsernameBad, NpamTestsCommon.TestPassword)); Interlocked.Increment(ref complete); });
                thread1.Start();
                thread2.Start();
            }
            while (complete < TotalAuthCalls)
            {
                Thread.Sleep(1);
            }
            sw.Stop();
            Console.WriteLine("Completed {0} threaded auth tests in {1} seconds.", complete, sw.Elapsed.TotalSeconds);
            Thread.Sleep(2000);
            Assert.Equal(TotalAuthCalls, complete);
        }
Exemplo n.º 2
0
        public void TestGroupsForGoodUser()
        {
            var groups = NpamUser.GetGroups(NpamTestsCommon.TestUsernameGood);

            foreach (var theGroup in groups)
            {
                Assert.Equal(NpamTestsCommon.TestUsernameGood, theGroup.GroupName);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Authenticates the provided credentials and returns the authenticated identity, if successful.
        /// </summary>
        /// <param name="credentials">Array of credentials ("username", "password")</param>
        /// <param name="authenticatedIdentity">Authenticated Identity</param>
        /// <returns>Indicates whether the authentication was successful.</returns>
        public bool Authenticate(Credential[] credentials, out RemotingIdentity authenticatedIdentity)
        {
            authenticatedIdentity = null;

            if (credentials == null)
            {
                return(false);
            }

            var userName =
                credentials
                .Where(c => c.Name.ToLower() == CREDENTIAL_TYPE_USERNAME)
                .Select(c => c.Value)
                .FirstOrDefault();

            var password =
                credentials
                .Where(c => c.Name.ToLower() == CREDENTIAL_TYPE_PASSWORD)
                .Select(c => c.Value)
                .FirstOrDefault();

            var isAuthenticated = NpamUser.Authenticate("passwd", userName, password);

            if (isAuthenticated)
            {
                var accountInfo = NpamUser.GetAccountInfo(userName);

                authenticatedIdentity =
                    new RemotingIdentity()
                {
                    Name            = accountInfo.Username,
                    IsAuthenticated = true,
                    Roles           = new [] { accountInfo.GroupID.ToString() }
                };

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            Console.Write("Username: "******"Password: "******"AUTHENTICATION - SUCCESS!");
                Console.WriteLine("\rUSER GROUPS:");
                foreach (var userGroup in NpamUser.GetGroups(user))
                {
                    Console.WriteLine("\t{0}", userGroup);
                }
                Console.WriteLine("\rUSER INFO:");
                Console.WriteLine("\t{0}", NpamUser.GetAccountInfo(user));
            }
            else
            {
                Console.WriteLine("AUTHENTICATION - FAILURE!");
            }
        }
Exemplo n.º 5
0
 public void TestGroupsFailForBadUser()
 {
     Assert.Equal(0, NpamUser.GetGroups(NpamTestsCommon.TestUsernameBad).ToList().Count);
 }
Exemplo n.º 6
0
 public void TestAuthFailForBadUser()
 {
     Assert.False(NpamUser.Authenticate(NpamTestsCommon.TestService, NpamTestsCommon.TestUsernameBad, NpamTestsCommon.TestPassword));
 }
Exemplo n.º 7
0
 public void TestAuthForGoodUser()
 {
     Assert.True(NpamUser.Authenticate(NpamTestsCommon.TestService, NpamTestsCommon.TestUsernameGood, NpamTestsCommon.TestPassword));
 }