public SerializableDictionary <string, UserAuthenticationTyp> GetUserList()
        {
            SerializableDictionary <string, UserAuthenticationTyp> users = new SerializableDictionary <string, UserAuthenticationTyp>();

            using (NpgsqlConnection con = GetPgConnection())
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM \"GetUserList\"()";

                    NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

                    while (reader.Read())
                    {
                        string username = reader["username"].ToString();
                        UserAuthenticationTyp authTyp = (UserAuthenticationTyp)Enum.Parse(typeof(UserAuthenticationTyp), reader["typ"].ToString());

                        if (authTyp == UserAuthenticationTyp.FormsAuthentication) //only allow forms authentication
                        {
                            users.Add(username, authTyp);
                        }
                    }

                    reader.Close();
                }
            }

            return(users);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="password">The password.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <param name="passwordIsHashed">if set to <c>true</c> password is hashed.</param>
 /// <param name="closeOpenSessions">if set to <c>true</c> close open sessions.</param>
 /// <remarks>Documented by Dev03, 2008-11-27</remarks>
 public UserStruct(string username, string password, UserAuthenticationTyp authTyp, bool passwordIsHashed, bool closeOpenSessions)
     : this(username)
 {
     Password           = passwordIsHashed ? password : Methods.GetHashedPassword(password);
     AuthenticationType = authTyp;
     CloseOpenSessions  = closeOpenSessions;
 }
 private void ChangeUserAuthType(UserAuthenticationTyp type)
 {
     if (type == UserAuthenticationTyp.FormsAuthentication)
     {
         labelPassword.Enabled   = true;
         textBoxPassword.Enabled = true;
     }
     else if (type == UserAuthenticationTyp.ListAuthentication)
     {
         labelPassword.Enabled   = false;
         textBoxPassword.Enabled = false;
         textBoxPassword.Text    = String.Empty;
     }
 }
Example #4
0
        /// <summary>
        /// Gets the db user.
        /// </summary>
        /// <param name="connection">A struct containing the connection info.</param>
        /// <param name="errorMessageDelegate">A delegate used to handle login errors.</param>
        /// <param name="standAlone">if set to <c>true</c> [stand alone].</param>
        /// <returns>A DB user which implements IUser</returns>
        /// <remarks>Documented by Dev03, 2008-11-25</remarks>
        private IUser GetDbUser(ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate, bool standAlone)
        {
            CheckConnection(connection);

            UserAuthenticationTyp authTyp = connector.GetAllowedAuthenticationModes().Value;

            bool       ldUserChecked = false;
            IUser      dbUser        = null;
            UserStruct?userStruct    = null;

            while (dbUser == null)
            {
                if (!IsWebService && !ldUserChecked && (authTyp & UserAuthenticationTyp.LocalDirectoryAuthentication) == UserAuthenticationTyp.LocalDirectoryAuthentication)
                {
                    ldUserChecked = true;
                    try { userStruct = GetLocalDirectoryUser(); }
                    catch (NoValidUserException) { userStruct = null; }
                }
                else
                {
                    userStruct = getLogin.Invoke(userStruct.HasValue ? userStruct.Value : new UserStruct(string.Empty, authTyp), ConnectionString);
                }

                if (userStruct.HasValue)
                {
                    UserStruct lastUser = userStruct.Value;
                    try { dbUser = new DbUser(userStruct, Parent, connection, errorMessageDelegate, standAlone); lastUser.LastLoginError = LoginError.NoError; }
                    catch (InvalidUsernameException) { lastUser.LastLoginError = LoginError.InvalidUsername; }
                    catch (InvalidPasswordException) { lastUser.LastLoginError = LoginError.InvalidPassword; }
                    catch (WrongAuthenticationException) { lastUser.LastLoginError = LoginError.WrongAuthentication; }
                    catch (ForbiddenAuthenticationException) { lastUser.LastLoginError = LoginError.ForbiddenAuthentication; }
                    catch (UserSessionCreationException) { lastUser.LastLoginError = LoginError.AlreadyLoggedIn; }
                    userStruct = lastUser;
                }
                else
                {
                    throw new NoValidUserException();
                }
            }

            return(dbUser);
        }
        public byte[] GetLearningModuleIndexEntry(int learningModuleId, string clientId)
        {
            try
            {
                if ((int)Session["uid"] < 0)
                {
                    throw new NoValidUserException();
                }

                string key   = string.Format("user-{0}", (int)Session["uid"]);
                string lmKey = string.Format("lm-{0}", learningModuleId);

                IUser user = null;
                lock (formatter)
                {
                    try
                    {
                        user = HttpContext.Current.Cache[key] as IUser;
                    }
                    catch { }
                    if (user == null)
                    {
                        user = UserFactory.Create((GetLoginInformation) delegate(UserStruct u, ConnectionStringStruct c)
                        {
                            if (u.LastLoginError != LoginError.NoError)
                            {
                                throw new InvalidCredentialsException("Some of the submited credentials are wrong!");
                            }

                            string username = Session["username"].ToString();
                            string password = Session["password"].ToString();
                            UserAuthenticationTyp authType = password == string.Empty ? UserAuthenticationTyp.ListAuthentication : UserAuthenticationTyp.FormsAuthentication;

                            return(new UserStruct(username, password, authType, true, true));
                        }, new ConnectionStringStruct(DatabaseType.PostgreSQL, ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, -1),
                                                  (DataAccessErrorDelegate) delegate { return; }, ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, true);

                        HttpContext.Current.Cache[key] = user;
                    }
                }

                IDictionary dic = new MLifter.DAL.DB.DbDictionary(learningModuleId, user);
                LearningModulesIndexEntry entry = new LearningModulesIndexEntry();
                entry.User             = user;
                entry.Dictionary       = dic;
                entry.DisplayName      = dic.Title;
                entry.Type             = LearningModuleType.Remote;
                entry.Type             = LearningModuleType.Remote;
                entry.ConnectionString = new ConnectionStringStruct(DatabaseType.PostgreSQL, dic.Connection, dic.Id, user.ConnectionString.SessionId);

                LearningModulesIndex.LoadEntry(entry);

                if (entry.Dictionary.ContentProtected)
                {
                    // MemoryLifter > 2.3 does not support DRM protected content
                    entry.IsAccessible        = false;
                    entry.NotAccessibleReason = LearningModuleNotAccessibleReason.Protected;
                }

                ConnectionStringStruct conString = entry.ConnectionString;
                conString.ConnectionString = string.Empty;
                entry.ConnectionString     = conString;

                MemoryStream stream = new MemoryStream();
                formatter.Serialize(stream, entry);

                return(stream.ToArray());
            }
            catch (Exception exp)
            {
                try
                {
                    WriteLogEntry(exp.ToString());
                }
                catch
                {
                    throw exp;
                }

                return(null);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <param name="closeOpenSessions">if set to <c>true</c> [close open sessions].</param>
 /// <remarks>Documented by Dev03, 2008-11-27</remarks>
 public UserStruct(string username, UserAuthenticationTyp authTyp, bool closeOpenSessions)
     : this(username)
 {
     AuthenticationType = authTyp;
     CloseOpenSessions  = closeOpenSessions;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="identifier">The identifier.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <remarks>
 /// Documented by CFI, 13.01.2009.
 /// </remarks>
 public UserStruct(string username, string identifier, UserAuthenticationTyp authTyp)
     : this(username)
 {
     Identifier         = identifier;
     AuthenticationType = authTyp;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <remarks>Documented by Dev03, 2008-11-27</remarks>
 public UserStruct(string username, UserAuthenticationTyp authTyp)
     : this(username)
 {
     AuthenticationType = authTyp;
 }
 private void ChangeUserAuthType(UserAuthenticationTyp type)
 {
     if (type == UserAuthenticationTyp.FormsAuthentication)
     {
         labelPassword.Enabled = true;
         textBoxPassword.Enabled = true;
     }
     else if (type == UserAuthenticationTyp.ListAuthentication)
     {
         labelPassword.Enabled = false;
         textBoxPassword.Enabled = false;
         textBoxPassword.Text = String.Empty;
     }
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="password">The password.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <param name="passwordIsHashed">if set to <c>true</c> password is hashed.</param>
 /// <param name="closeOpenSessions">if set to <c>true</c> close open sessions.</param>
 /// <remarks>Documented by Dev03, 2008-11-27</remarks>
 public UserStruct(string username, string password, UserAuthenticationTyp authTyp, bool passwordIsHashed, bool closeOpenSessions)
     : this(username)
 {
     Password = passwordIsHashed ? password : Methods.GetHashedPassword(password);
     AuthenticationType = authTyp;
     CloseOpenSessions = closeOpenSessions;
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <param name="closeOpenSessions">if set to <c>true</c> [close open sessions].</param>
 /// <remarks>Documented by Dev03, 2008-11-27</remarks>
 public UserStruct(string username, UserAuthenticationTyp authTyp, bool closeOpenSessions)
     : this(username)
 {
     AuthenticationType = authTyp;
     CloseOpenSessions = closeOpenSessions;
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="identifier">The identifier.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <remarks>
 /// Documented by CFI, 13.01.2009.
 /// </remarks>
 public UserStruct(string username, string identifier, UserAuthenticationTyp authTyp)
     : this(username)
 {
     Identifier = identifier;
     AuthenticationType = authTyp;
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserStruct"/> struct.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="authTyp">The auth typ.</param>
 /// <remarks>Documented by Dev03, 2008-11-27</remarks>
 public UserStruct(string username, UserAuthenticationTyp authTyp)
     : this(username)
 {
     AuthenticationType = authTyp;
 }