예제 #1
0
        /// <summary>
        /// Get named restricted view if it exists
        /// </summary>
        /// <param name="viewName"></param>
        /// <returns></returns>

        public static RestrictedDatabaseView GetRestrictedView(string viewName)
        {
            if (ViewDict == null)
            {
                ReadViews();
            }

            viewName = viewName.Trim().ToUpper();
            if (!RestrictedDatabaseView.ViewDict.ContainsKey(viewName))
            {
                return(null);
            }

            RestrictedDatabaseView v = RestrictedDatabaseView.ViewDict[viewName];

            if (v.MetaTables == null)
            {
                ReadViewMetaTables(v);
            }
            if (v.CorpIds == null)
            {
                ReadViewCorpIds(v);
            }
            return(v);
        }
예제 #2
0
        /// <summary>
        /// Do initial read of the list of views and the users for each view.
        /// </summary>
        public static void ReadViews()
        {
            StreamReader sr;

            ViewDict = new Dictionary <string, RestrictedDatabaseView>();

            bool restrictionsActive = ServicesIniFile.ReadBool("UseRestrictedDatabaseViews", false);

            if (!restrictionsActive)
            {
                return;
            }

            string dirName = ServicesDirs.MetaDataDir + @"\RestrictedDatabaseViews";

            if (!Directory.Exists(dirName))
            {
                return;                                         // throw new Exception("RestrictedDatabaseViews Directory does not exist: " + dirName);
            }
            string fileName = dirName + @"\ViewList.txt";

            if (!File.Exists(fileName))
            {
                return;
            }
            try
            {
                sr = new StreamReader(fileName);
            }
            catch (Exception ex)
            { return; }

            while (true)
            {
                string txt = sr.ReadLine();
                if (txt == null)
                {
                    break;
                }
                if (Lex.IsUndefined(txt) || txt.StartsWith(";"))
                {
                    continue;
                }

                string viewName = txt.Trim().ToUpper();

                RestrictedDatabaseView v = new RestrictedDatabaseView();
                ViewDict[viewName] = v;
                v.Name             = viewName;
                ReadViewUsers(v);
            }

            sr.Close();
        }
예제 #3
0
        public static void ReadViewCorpIds(RestrictedDatabaseView v)
        {
            StreamReader sr;
            int          corpId;

            v.CorpIds = new HashSet <int>();

            string dirName  = ServicesDirs.MetaDataDir + @"\RestrictedDatabaseViews";
            string fileName = dirName + @"\" + v.Name + "CorpIds.txt";

            if (!File.Exists(fileName))
            {
                throw new Exception("Missing file: " + fileName);
            }
            try
            {
                sr = new StreamReader(fileName);
            }
            catch (Exception ex)
            { return; }

            while (true)
            {
                string txt = sr.ReadLine();
                if (txt == null)
                {
                    break;
                }
                if (Lex.IsUndefined(txt) || txt.StartsWith(";"))
                {
                    continue;
                }

                string corpIdTxt = txt.Trim().ToUpper();
                if (!int.TryParse(corpIdTxt, out corpId))
                {
                    continue;
                }
                v.CorpIds.Add(corpId);
            }

            sr.Close();

            if (v.CorpIds.Contains(-1) && v.CorpIds.Count == 1)
            {
                v.CorpIds = null;                 // special keyword to include all CorpIds
            }
            return;
        }
예제 #4
0
        /// <summary>
        /// See if user authorized
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="domainName"></param>
        /// <returns></returns>

        public static bool IsAuthorized(
            string userName,
            string domainName,
            out UserInfo ui)
        {
            bool isAuthorized = false;

            if (Security.IsSpecialMobiusAccount(userName) ||              // see if special Mobius system account
                UAL.DbConnectionMx.NoDatabaseAccessIsAvailable)           // or if we aren't accessing any real databases
            {
                ui           = CreateDefaultMobiusAccountUserInfo(userName);
                isAuthorized = true;
            }

            else if (UseActiveDirectory)             // ActiveDirectory is new method
            {
                isAuthorized = ActiveDirectoryDao.IsAuthorizedAD(userName, domainName, out ui);
            }

            else
            {
                isAuthorized = IsAuthorizedOldMethod(userName, domainName, out ui);
            }

            if (isAuthorized)
            {
                RestrictedDatabaseView v = RestrictedDatabaseView.GetRestrictedViewForUser(userName);
                if (v != null)
                {
                    ui.RestrictedViewUsers             = v.Userids;
                    ui.RestrictedViewAllowedMetaTables = v.MetaTables;
                    ui.RestrictedViewAllowedCorpIds    = v.CorpIds;
                }

                ui.GenerallyRestrictedMetatables = RestrictedMetatable.GetUsersGenerallyRestrictedMetatables(userName, domainName);
            }

            return(isAuthorized);
        }
예제 #5
0
        public static void ReadViewMetaTables(RestrictedDatabaseView v)
        {
            StreamReader sr;
            string       tableNamePrefix;
            int          assay;
            bool         isSummary;

            v.MetaTables = new HashSet <string>();

            string dirName  = ServicesDirs.MetaDataDir + @"\RestrictedDatabaseViews";
            string fileName = dirName + @"\" + v.Name + "MetaTables.txt";

            if (!File.Exists(fileName))
            {
                throw new Exception("Missing file: " + fileName);
            }
            try
            {
                sr = new StreamReader(fileName);
            }
            catch (Exception ex)
            { return; }

            while (true)
            {
                string txt = sr.ReadLine();
                if (txt == null)
                {
                    break;
                }
                if (Lex.IsUndefined(txt) || txt.StartsWith(";"))
                {
                    continue;
                }

                string mtName = txt.Trim().ToUpper();
                v.MetaTables.Add(mtName);

                MetaTable.ParseMetaTableName(mtName, out tableNamePrefix, out assay, out isSummary);
                if (assay <= 0)
                {
                    continue;
                }
                if (isSummary)
                {
                    continue;
                }

                if (Lex.Eq(tableNamePrefix, "ASSAY"))
                {
                    string mtName2 = mtName + "_SUMMARY";
                    v.MetaTables.Add(mtName2);
                }
            }

            sr.Close();

            if (v.MetaTables.Contains("<ALL>") && v.MetaTables.Count == 1)
            {
                v.MetaTables = null;                 // special keyword to include all metatables
            }
            return;
        }