Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserData"/> class by copying an existing instance.
 /// </summary>
 /// <param name="userData">The existing instance of the <see cref="UserData"/> class.</param>
 public UserData(UserData userData)
 {
     Clone(userData);
 }
Exemple #2
0
 /// <summary>
 /// Copies a new instance of the <see cref="UserData"/> class by copying an existing instance.
 /// </summary>
 /// <param name="userData">The existing instance of the <see cref="UserData"/> class.</param>
 public void Clone(UserData userData)
 {
     LoginID = userData.LoginID;
     Username = userData.Username;
     Password = userData.Password;
     FirstName = userData.FirstName;
     LastName = userData.LastName;
     CompanyName = userData.CompanyName;
     PhoneNumber = userData.PhoneNumber;
     EmailAddress = userData.EmailAddress;
     SecurityQuestion = userData.SecurityQuestion;
     SecurityAnswer = userData.SecurityAnswer;
     PasswordChangeDateTime = userData.PasswordChangeDateTime;
     AccountCreatedDateTime = userData.AccountCreatedDateTime;
     IsDefined = userData.IsDefined;
     IsExternal = userData.IsExternal;
     IsDisabled = userData.IsDisabled;
     IsLockedOut = userData.IsLockedOut;
     IsAuthenticated = userData.IsAuthenticated;
     Groups = new List<string>(userData.Groups);
     Roles = new List<string>(userData.Roles);
 }
Exemple #3
0
        private Dictionary<string, UserData> DeserializeCache(byte[] data)
        {
            Dictionary<string, UserData> cache = new Dictionary<string, UserData>(StringComparer.OrdinalIgnoreCase);

            using (MemoryStream stream = new MemoryStream(data))
            using (BinaryReader reader = new BinaryReader(stream, Encoding.Default))
            {
                if (reader.ReadBytes(CacheHeaderBytes.Length).CompareTo(CacheHeaderBytes) != 0)
                    throw new InvalidDataException("Unexpected data read from UserDataCache - file possibly corrupted.");

                int listLength, cacheLength = reader.ReadInt32();

                for (int i = 0; i < cacheLength; i++)
                {
                    UserData userData = new UserData();
                    string loginID;

                    loginID = reader.ReadString();
                    userData.Username = reader.ReadString();
                    userData.FirstName = reader.ReadString();
                    userData.LastName = reader.ReadString();
                    userData.CompanyName = reader.ReadString();
                    userData.PhoneNumber = reader.ReadString();
                    userData.EmailAddress = reader.ReadString();
                    userData.IsLockedOut = reader.ReadBoolean();
                    userData.IsDisabled = reader.ReadBoolean();
                    userData.PasswordChangeDateTime = new DateTime(reader.ReadInt64());
                    userData.AccountCreatedDateTime = new DateTime(reader.ReadInt64());

                    userData.Roles = new List<string>();
                    listLength = reader.ReadInt32();

                    for (int j = 0; j < listLength; j++)
                        userData.Roles.Add(reader.ReadString());

                    userData.Groups = new List<string>();
                    listLength = reader.ReadInt32();

                    for (int j = 0; j < listLength; j++)
                        userData.Groups.Add(reader.ReadString());

                    cache.Add(loginID, userData);
                }
            }

            return cache;
        }
Exemple #4
0
        /// <summary>
        /// Serializes the <paramref name="userData"/> for the given <paramref name="loginID"/> into the <see cref="UserDataCache"/>.
        /// </summary>
        /// <param name="loginID">Login ID of associated <see cref="UserData"/> to retrieve.</param>
        /// <param name="userData">Reference to <see cref="UserData"/> object to serialize into <see cref="UserDataCache"/>.</param>
        /// <remarks>
        /// <para>
        /// This will add an entry into the user data cache for <paramref name="loginID"/> if it doesn't exist;
        /// otherwise existing entry will be updated.
        /// </para>
        /// <para>
        /// Updates are automatically queued up for serialization so user does not need to call <see cref="Save"/>.
        /// </para>
        /// </remarks>
        public void SaveUserData(string loginID, UserData userData)
        {
            string hash = HashLoginID(loginID);

            // We wait until the cache is loaded before attempting to access it
            WaitForDataReady();

            // Wait for thread level lock on user data table
            lock (m_userDataTableLock)
            {
                // Assign new user information to user data table
                m_userDataTable[hash] = userData;
            }

            // Queue up a serialization for this new user information
            Save();
        }
Exemple #5
0
        /// <summary>
        /// Attempts to retrieve <see cref="UserData"/> for given <paramref name="loginID"/>.
        /// </summary>
        /// <param name="loginID">Login ID of associated <see cref="UserData"/> to retrieve.</param>
        /// <param name="userData">Reference to <see cref="UserData"/> object to populate if found.</param>
        /// <returns><c>true</c> if <see cref="UserData"/> for given <paramref name="loginID"/> was retrieved; otherwise <c>false</c>.</returns>
        public bool TryGetUserData(string loginID, out UserData userData)
        {
            string hash = HashLoginID(loginID);
            bool result;

            // We wait until the cache is loaded before attempting to access it
            WaitForDataReady();

            // Wait for thread level lock on user data table
            lock (m_userDataTableLock)
            {
                // Attempt to lookup persisted user data based on hash of login ID
                result = m_userDataTable.TryGetValue(hash, out userData);
            }

            return result;
        }
 /// <summary>
 /// Initializes a new instance of the security provider.
 /// </summary>
 /// <param name="username">Name that uniquely identifies the user.</param>
 /// <param name="canRefreshData">true if the security provider can refresh <see cref="UserData"/> from the backend data store, otherwise false.</param>
 /// <param name="canUpdateData">true if the security provider can update <see cref="UserData"/> in the backend data store, otherwise false.</param>
 /// <param name="canResetPassword">true if the security provider can reset user password, otherwise false.</param>
 /// <param name="canChangePassword">true if the security provider can change user password, otherwise false.</param>
 protected SecurityProviderBase(string username, bool canRefreshData, bool canUpdateData, bool canResetPassword, bool canChangePassword)
 {
     // Initialize member variables.
     m_userData = new UserData(username);
     m_canRefreshData = canRefreshData;
     m_canUpdateData = canUpdateData;
     m_canResetPassword = canResetPassword;
     m_canChangePassword = canChangePassword;
     m_applicationName = DefaultApplicationName;
     m_connectionString = DefaultConnectionString;
     m_persistSettings = DefaultPersistSettings;
     m_settingsCategory = DefaultSettingsCategory;
     m_logEvent = EventLog.WriteEntry;
 }