コード例 #1
0
ファイル: NpamUserTests.cs プロジェクト: carathorys/npam
        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);
        }
コード例 #2
0
ファイル: NpamUserTests.cs プロジェクト: carathorys/npam
        public void TestGroupsForGoodUser()
        {
            var groups = NpamUser.GetGroups(NpamTestsCommon.TestUsernameGood);

            foreach (var theGroup in groups)
            {
                Assert.Equal(NpamTestsCommon.TestUsernameGood, theGroup.GroupName);
            }
        }
コード例 #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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: carathorys/npam
        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!");
            }
        }
コード例 #5
0
ファイル: NpamUserTests.cs プロジェクト: carathorys/npam
 public void TestGroupsFailForBadUser()
 {
     Assert.Equal(0, NpamUser.GetGroups(NpamTestsCommon.TestUsernameBad).ToList().Count);
 }
コード例 #6
0
ファイル: NpamUserTests.cs プロジェクト: carathorys/npam
 public void TestAuthFailForBadUser()
 {
     Assert.False(NpamUser.Authenticate(NpamTestsCommon.TestService, NpamTestsCommon.TestUsernameBad, NpamTestsCommon.TestPassword));
 }
コード例 #7
0
ファイル: NpamUserTests.cs プロジェクト: carathorys/npam
 public void TestAuthForGoodUser()
 {
     Assert.True(NpamUser.Authenticate(NpamTestsCommon.TestService, NpamTestsCommon.TestUsernameGood, NpamTestsCommon.TestPassword));
 }