Example #1
0
        public GroupPermissions GetUnassignedAnyGroupPermissions()
        {
            GroupPermissions groupPermissions = null;
            GroupOperations  groupOps         = null;

            try
            {
                groupOps = new GroupOperations(Lcf);

                Logger.Log("Getting group security permission key value pairs ...");
                List <MGSecurityTag> groupContentList = groupOps.GetUnassignedAnyGroupContentDictionary();
                if (groupContentList == null)
                {
                    Logger.LogError(5, "Got NULL or empty list for group permissions that aren't assigned to to ANY group!");
                    return(null);
                }

                Logger.Log("Finished getting group security permission key value pairs.");

                groupPermissions = GetGroupPermissions(MGGroup.NO_GROUP, groupContentList);
                if (groupPermissions == null)
                {
                    Logger.LogError(5, "Failed to get group permissions that aren't assigned to ANY group!");
                    return(null);
                }
                Logger.Log("Finished getting group permissions that aren't assigned to ANY group.");
            }
            catch (Exception ex)
            {
                Logger.LogError(5, "Error getting all group permissions at " + ex.StackTrace);
                groupPermissions = null;
            }
            finally
            {
                if (groupOps != null)
                {
                    groupOps.Finish();
                }
            }
            return(groupPermissions);
        }
Example #2
0
        public GroupPermissions GetGroupPermissions(MGGroup group,
                                                    List <MGSecurityTag> groupContentSecKeyValPairs,
                                                    List <MGSecurityTag> groupDisplaySecKeyValPairs,
                                                    List <MGSecurityTag> groupFunctionSecKeyValPairs)
        {
            GroupPermissions groupPerms = null;

            try
            {
                groupPerms         = new GroupPermissions();
                groupPerms.GroupID = group.ID;

                if (groupContentSecKeyValPairs != null)
                {
                    groupPerms.GroupContentPermissions =
                        groupPerms.GetGroupContentPermissions(groupContentSecKeyValPairs);
                }

                if (groupDisplaySecKeyValPairs != null)
                {
                    groupPerms.GroupDisplayPermissions =
                        groupPerms.GetGroupDisplayPermissions(groupDisplaySecKeyValPairs);
                }

                if (groupFunctionSecKeyValPairs != null)
                {
                    groupPerms.GroupFunctionPermissions =
                        groupPerms.GetGroupFunctionPermissions(groupFunctionSecKeyValPairs);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(5, "Error getting group permissions for group with ID=" + group.ID + " at " + ex.StackTrace);
                groupPerms = null;
            }
            return(groupPerms);
        }
Example #3
0
        private Dictionary <int, GroupPermissions> GetAllGroupPermissions(List <MGGroup> allGroups,
                                                                          Dictionary <int, List <MGSecurityTag> > groupContentDict,
                                                                          Dictionary <int, List <MGSecurityTag> > groupDisplayDict,
                                                                          Dictionary <int, List <MGSecurityTag> > groupFunctionalityDict)
        {
            Dictionary <int, GroupPermissions> allGroupPermissions = new Dictionary <int, GroupPermissions>(allGroups.Count);

            try
            {
                GroupPermissions     groupPerms = null;
                List <MGSecurityTag> groupContentSecKeyValPairs  = null;
                List <MGSecurityTag> groupDisplaySecKeyValPairs  = null;
                List <MGSecurityTag> groupFunctionSecKeyValPairs = null;

                foreach (MGGroup group in allGroups)
                {
                    if (group == null)
                    {
                        Logger.LogError(5, "NULL MGGroup detected, skipping getting group permissions for this group ...");
                        continue;
                    }
                    else if (group.ID < 1)
                    {
                        Logger.LogError(5, "Invalid MGGroup.ID detected, skipping getting group permissions for this group ...");
                        continue;
                    }

                    groupContentSecKeyValPairs  = null;
                    groupDisplaySecKeyValPairs  = null;
                    groupFunctionSecKeyValPairs = null;

                    if (groupContentDict.ContainsKey(group.ID))
                    {
                        groupContentSecKeyValPairs = groupContentDict[group.ID];
                    }

                    if (groupDisplayDict.ContainsKey(group.ID))
                    {
                        groupDisplaySecKeyValPairs = groupDisplayDict[group.ID];
                    }

                    if (groupFunctionalityDict.ContainsKey(group.ID))
                    {
                        groupFunctionSecKeyValPairs = groupFunctionalityDict[group.ID];
                    }

                    groupPerms = GetGroupPermissions(group, groupContentSecKeyValPairs, groupDisplaySecKeyValPairs, groupFunctionSecKeyValPairs);
                    if (groupPerms == null)
                    {
                        Logger.LogError(5, "Failed to get GroupPermissions for group.ID=" + group.ID);
                        continue;
                    }
                    if (!allGroupPermissions.ContainsKey(group.ID))
                    {
                        allGroupPermissions.Add(group.ID, groupPerms);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(5, "Error getting all group permissions at " + ex.StackTrace);
                allGroupPermissions = null;
            }
            return(allGroupPermissions);
        }
Example #4
0
        public GroupPermissions GetGroupPermissions(MGGroup group, GroupAdministration.AssociationTypes associationType)
        {
            if (group == null)
            {
                Logger.LogError(5, "NULL  group found can not find permissions.");
                return(null);
            }
            GroupPermissions groupPermissions = null;
            GroupOperations  groupOps         = null;

            Logger.Log("Getting group permissions for group with ID " + group.ID + " and name " + group.Name + "...");
            try
            {
                Logger.Log("Getting group security permission key value pairs ...");

                // Extract the Application Level list of groups, along with the relevant cross references to Users and the content etc ...
                groupOps = new GroupOperations(Lcf);

                Logger.Log("Start getting groups->content lookup...");
                List <MGSecurityTag> groupContentList = groupOps.GetGroupContentDictionary(group.ID, associationType);
                if (groupContentList == null)
                {
                    Logger.LogError(5, "Got NULL list for group with name " + group.Name + " and ID " + group.ID + " groups->content lookup, abandoning getting group permissions!");
                    return(null);
                }

                Logger.Log("Start getting groups->display lookup...");
                List <MGSecurityTag> groupDisplayList = groupOps.GetGroupDisplayDictionary(group.ID, associationType);
                if (groupDisplayList == null)
                {
                    Logger.LogError(5, "Got NULL list for group with name " + group.Name + " and ID " + group.ID + " groups->display lookup, abandoning getting group permissions!");
                    return(null);
                }

                Logger.Log("Start getting groups->functionality lookup...");
                List <MGSecurityTag> groupFunctionalityList = groupOps.GetGroupFunctionalityDictionary(group.ID, associationType);
                if (groupFunctionalityList == null)
                {
                    Logger.LogError(5, "Got NULL list for group with name " + group.Name + " and ID " + group.ID + " groups->functionality lookup, abandoning getting group permissions!");
                    return(null);
                }

                Logger.Log("Finished getting group security permission key value pairs.");

                groupPermissions = GetGroupPermissions(group, groupContentList, groupDisplayList, groupFunctionalityList);
                if (groupPermissions == null)
                {
                    Logger.LogError(5, "Failed to get group permissions for group with name " + group.Name + " and ID " + group.ID + "!");
                    return(null);
                }
                Logger.Log("Finished getting group permissions for group with name " + group.Name + " and ID " + group.ID + ".");
            }
            catch (Exception ex)
            {
                Logger.LogError(5, "Error getting all group permissions at " + ex.StackTrace);
                groupPermissions = null;
            }
            finally
            {
                if (groupOps != null)
                {
                    groupOps.Finish();
                }
            }
            return(groupPermissions);
        }
Example #5
0
        public List <GroupPermissions> GetUserGroupPermissions(
            List <MGGroup> userGroups,
            AppSecurityContext appSecContext)
        {
            if (userGroups == null)
            {
                Logger.LogError(5, "Cannot get UserGroupPermissions for NULL userGroups list!");
                return(null);
            }

            List <GroupPermissions> userGroupPermissions = new List <GroupPermissions>();

            if (userGroups.Count == 0)
            {
                Logger.LogWarning("UserGroup List is empty, returning empty UserGroupPermissionsList!");
                return(userGroupPermissions);
            }

            if (appSecContext == null)
            {
                Logger.LogError(5, "Cannot get UserGroupPermissions with NULL AppSecurityContext!");
                return(null);
            }

            // Store appSecContext.AllGroupPermissions locally so we only read it once from DB.
            // TODO: if the Staging database context, read the permissions only for this group.
            bool isUsingStagingDb =
                (Lcf.DbConInfo.NAME == AppSecurityContext.StagingDbLcf.DbConInfo.NAME);

            Dictionary <int, GroupPermissions> allGroupPerms = null;

            if (!isUsingStagingDb)
            {
                allGroupPerms = appSecContext.AllGroupPermissions;
                if (allGroupPerms == null)
                {
                    Logger.LogError(5, "Cannot get UserGroupPermissions with NULL AppSecurityContext.AllGroupPermissions!");
                    return(null);
                }
                if (allGroupPerms.Count == 0)
                {
                    Logger.LogError(5, "AppSecurityContext.AllGroupPermissions is empty, returning empty UserGroupPermissionsList!");
                    return(userGroupPermissions);
                }
            }

            GroupPermissions groupPerms = null;

            foreach (MGGroup userGroup in userGroups)
            {
                if (userGroup == null)
                {
                    Logger.LogError(5, "NULL UserGroup detected, skipping it ...");
                    continue;
                }
                else if (userGroup.ID < 1)
                {
                    Logger.LogError(5, "Invalid UserGroup.ID detected, skipping it ...");
                    continue;
                }

                if (!isUsingStagingDb)
                {
                    if (!allGroupPerms.ContainsKey(userGroup.ID))
                    {
                        Logger.LogError(5, "UserGroup.ID " + userGroup.ID + " not present in AppSecurityContext.AllGroupPermissions, skipping it ...");
                        continue;
                    }

                    groupPerms = allGroupPerms[userGroup.ID];
                    if (groupPerms == null)
                    {
                        Logger.LogError(5, "NULL GroupPermissions for userGroup.ID = " + userGroup.ID + " detected, skipping adding it ...");
                        continue;
                    }
                }
                else
                {
                    groupPerms = appSecContext.GetGroupPermissions(userGroup);
                }

                if (userGroupPermissions.Contains(groupPerms))
                {
                    Logger.LogError(5, "GroupPermissions for userGroup.ID = " + userGroup.ID + " already added, skipping adding it ...");
                    continue;
                }

                userGroupPermissions.Add(groupPerms);
            }

            return(userGroupPermissions);
        }