Exemple #1
0
        /// <summary>
        /// Here we have two user authenticators that we need to run together, since we just purchased a competitor's site. They are, however, incompatible in their methods.
        /// </summary>
        public static void Main()
        {
            User clint = User.CreateUser("Clint Eastwood", "MakeMyDayPunk");

            IUserAuthenticator inHouseAuthenticator = new UserAuthenticator();

            if (inHouseAuthenticator.CanAuthenticate(clint))
            {
                Debug.WriteLine(clint.Name + " can access our site.");
            }
            else
            {
                // Go through the motions of the third-party authenticator, somewhat different to our in-house one.
                ThirdPartyAuthenticator thirdpartyAuthenticator = new ThirdPartyAuthenticator();
                thirdpartyAuthenticator.StoreCredentials(clint.Name, clint.Password);

                // ... and try to authenticate using them both
                if (thirdpartyAuthenticator.TryToAuthenciate())
                {
                    Debug.WriteLine(clint.Name + " can access this website");
                }
                else
                {
                    Debug.WriteLine(clint.Name + " cannot access this website");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// By introducing the ThirdPartyAuthenticatorAdapter-class we have effectively wrapped the third-party authenticator, and can now call them in the same fashion.
        /// </summary>
        private static void Main()
        {
            User clint = User.CreateUser("Clint Eastwood", "MakeMyDayPunk");

            IUserAuthenticator inHouseAuthenticator           = new UserAuthenticator();
            IUserAuthenticator thirdpartyAuthenticatorAdapter = new ThirdPartyAuthenticatorAdapter();

            if (inHouseAuthenticator.CanAuthenticate(clint) || thirdpartyAuthenticatorAdapter.CanAuthenticate(clint))
            {
                Debug.WriteLine(clint.Name + " can access our site.");
            }
            else
            {
                Debug.WriteLine(clint.Name + " cannot access this website");
            }
        }