Exemplo n.º 1
0
        internal Group GetGroup(GlymaSecurityGroup securityGroup)
        {
            Group result = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (IGlymaSession glymaSession = new WebAppSPGlymaSession(this.WebUrl))
                {
                    using (IDbConnectionAbstraction connectionAbstraction = glymaSession.ConnectionFactory.CreateSecurityDbConnection())
                    {
                        using (SecurityServiceDataContext dataContext = new SecurityServiceDataContext(connectionAbstraction.Connection))
                        {
                            var groups = from g in dataContext.Groups
                                         where g.GroupId == securityGroup.GroupId &&
                                         g.SecurableContextId == securityGroup.SecurableContextId
                                         select g;

                            Group group = null; //default value if it doesn't exist
                            if (groups.Any())
                            {
                                group = groups.First();
                            }
                            result = group;
                        }
                    }
                }
            });
            return(result);
        }
Exemplo n.º 2
0
 public PermissionGroup(GlymaSecurityGroup group, bool? isSelected, bool isEnabled = true)
 {
     Group = group;
     _defaultValue = isSelected;
     _isSelected = isSelected;
     _isEneabled = isEnabled;
 }
Exemplo n.º 3
0
 public PermissionGroup(GlymaSecurityGroup group, bool?isSelected, bool isEnabled = true)
 {
     Group         = group;
     _defaultValue = isSelected;
     _isSelected   = isSelected;
     _isEneabled   = isEnabled;
 }
 private void AddUpdate(IManagementConsoleObject managementConsoleObject, GlymaSecurityGroup group, bool?value,
                        bool isUpdatable = true)
 {
     if (Updates.ContainsKey(managementConsoleObject))
     {
         if (Updates[managementConsoleObject].ContainsKey(group) &&
             Updates[managementConsoleObject][group].IsUpdatable == isUpdatable)
         {
             Updates[managementConsoleObject][group].IsChecked = value.HasValue && value.Value;
         }
         else
         {
             Updates[managementConsoleObject].Add(group,
                                                  new UpdateValue(value.HasValue && value.Value, isUpdatable));
         }
     }
     else
     {
         var newGroups = new Dictionary <GlymaSecurityGroup, UpdateValue>
         {
             { group, new UpdateValue(value.HasValue && value.Value, isUpdatable) }
         };
         Updates.Add(managementConsoleObject, newGroups);
     }
 }
Exemplo n.º 5
0
 public void ResetChange(GlymaSecurityGroup group)
 {
     foreach (var permissionGroup in PermissionGroups)
     {
         var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
         if (found != null)
         {
             found.ResetValue();
         }
     }
 }
Exemplo n.º 6
0
 public void LoadValue(GlymaSecurityGroup group, bool value)
 {
     foreach (var permissionGroup in PermissionGroups)
     {
         var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
         if (found != null)
         {
             found.SetValue(value);
         }
     }
 }
Exemplo n.º 7
0
 public bool GetValue(GlymaSecurityGroup group)
 {
     foreach (var permissionGroup in PermissionGroups)
     {
         var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
         if (found != null)
         {
             return(found.IsSelected.HasValue && found.IsSelected.Value);
         }
     }
     return(false);
 }
Exemplo n.º 8
0
        internal GlymaPermissionLevel GetGroupsPermissionLevel(GlymaSecurityGroup glGroup)
        {
            GlymaPermissionLevel result = GlymaPermissionLevel.None;

            IList <GlymaSecurityGroup> pmGroups = _groups[GlymaPermissionLevel.GlymaProjectManager];
            IList <GlymaSecurityGroup> mmGroups = _groups[GlymaPermissionLevel.GlymaMapManager];
            IList <GlymaSecurityGroup> maGroups = _groups[GlymaPermissionLevel.GlymaMapAuthor];
            IList <GlymaSecurityGroup> mrGroups = _groups[GlymaPermissionLevel.GlymaMapReader];

            foreach (GlymaSecurityGroup spGroup in pmGroups)
            {
                if (spGroup.GroupId == glGroup.GroupId)
                {
                    result = GlymaPermissionLevel.GlymaProjectManager;
                    return(result); // group has project manager permissions
                }
            }
            foreach (GlymaSecurityGroup spGroup in mmGroups)
            {
                if (spGroup.GroupId == glGroup.GroupId)
                {
                    result = GlymaPermissionLevel.GlymaMapManager;
                    return(result); // group has map manager permissions
                }
            }
            foreach (GlymaSecurityGroup spGroup in maGroups)
            {
                if (spGroup.GroupId == glGroup.GroupId)
                {
                    result = GlymaPermissionLevel.GlymaMapAuthor;
                    return(result); // group has map author permissions
                }
            }
            foreach (GlymaSecurityGroup spGroup in mrGroups)
            {
                if (spGroup.GroupId == glGroup.GroupId)
                {
                    result = GlymaPermissionLevel.GlymaMapReader;
                    return(result); // group has map reader permissions
                }
            }
            return(result);
        }
Exemplo n.º 9
0
        public GlymaSecurityAssociation CommitChange(GlymaSecurityGroup group, bool value)
        {
            foreach (var permissionGroup in PermissionGroups)
            {
                var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
                if (found != null)
                {
                    found.ResetValue(value);
                    return(new GlymaSecurityAssociation
                    {
                        BreakInheritance = this is RootMap,
                        GlymaSecurityGroup = group,
                        SecurableObject = new GlymaSecurableObject
                        {
                            SecurableObjectUid = Id,
                            SecurableParentUid = this is RootMap ? ParentId : Guid.Empty,
                        },

                        Value = value
                    });
                }
            }
            return(null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a list presenting the SharePoint Security Groups for the current web that have a specified permission associated with them
        /// </summary>
        /// <param name="webUrl">The URL for the SP site</param>
        /// <param name="permissionLevel">The permission level the groups must have</param>
        /// <returns>A list of groups (wrapped by a ResponseObject)</returns>
        internal GetSecurityGroupsResponse GetSecurityGroups(GlymaPermissionLevel permissionLevel)
        {
            GetSecurityGroupsResponse result = new GetSecurityGroupsResponse()
            {
                HasError = false
            };
            IList <GlymaSecurityGroup> results = new List <GlymaSecurityGroup>();

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(WebUrl))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            SPRoleDefinition roleDefinition = null;
                            try
                            {
                                // Check if the role exists, if it does a definition will exist
                                roleDefinition = web.RoleDefinitions[GlymaPermissionLevelHelper.GetPermissionLevelName(permissionLevel)];
                            }
                            catch (Exception)
                            {
                                //if unable to find the role definition it will throw an exception
                            }

                            if (roleDefinition != null)
                            {
                                SPRoleAssignmentCollection roleAssignments = web.RoleAssignments;
                                foreach (SPRoleAssignment roleAssignment in roleAssignments)
                                {
                                    bool hasRoleDefinition = false;
                                    foreach (
                                        SPRoleDefinition definition in roleAssignment.RoleDefinitionBindings)
                                    {
                                        if (definition.Id == roleDefinition.Id)
                                        {
                                            //The role exists for this role assignment
                                            hasRoleDefinition = true;
                                            break;
                                        }
                                    }

                                    if (hasRoleDefinition)
                                    {
                                        SPGroup group = roleAssignment.Member as SPGroup;
                                        //we only want to look at groups
                                        if (group != null)
                                        {
                                            GlymaSecurityGroup glymaGroup = new GlymaSecurityGroup();
                                            glymaGroup.DisplayName        = group.Name;

                                            SecurableContext securableContext = this.GetSecurableContext();
                                            glymaGroup.SecurableContextId     = securableContext.SecurableContextId;

                                            GlymaSecurityGroupContext sgc = new GlymaSecurityGroupContext(this, securableContext.SecurableContextId, group.ID, web.ID);
                                            Group glGroup = sgc.GetGroup(group.Name);
                                            if (glGroup == null)
                                            {
                                                glGroup = sgc.CreateGroup(group.Name);
                                            }
                                            if (glGroup != null)
                                            {
                                                glymaGroup.GroupId = glGroup.GroupId;
                                                results.Add(glymaGroup);
                                            }
                                            else
                                            {
                                                result.HasError     = true;
                                                result.ErrorMessage = "Failed to create the Group in the Glyma Security Database.";
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                results = new List <GlymaSecurityGroup>(); //there was no role by this name, it has no groups
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                //If an error occurs getting the group listing return no groups
                result.HasError     = true;
                result.ErrorMessage = ex.Message;
            }
            if (!result.HasError)
            {
                result.Result = results;
            }
            return(result);
        }
Exemplo n.º 11
0
 internal GlymaSecurityAssociationContext(SecurityContextManager context, GlymaSecurityGroup group, GlymaSecurableObject securableObject)
 {
     Group           = group;
     SecurableObject = securableObject;
     Context         = context;
 }
Exemplo n.º 12
0
 public void ResetChange(GlymaSecurityGroup group)
 {
     foreach (var permissionGroup in PermissionGroups)
     {
         var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
         if (found != null)
         {
             found.ResetValue();
         }
     }
 }
Exemplo n.º 13
0
 public GlymaSecurityAssociation CommitChange(GlymaSecurityGroup group, bool value)
 {
     foreach (var permissionGroup in PermissionGroups)
     {
         var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
         if (found != null)
         {
             found.ResetValue(value);
             return new GlymaSecurityAssociation
             {
                 BreakInheritance = this is RootMap,
                 GlymaSecurityGroup = group,
                 SecurableObject = new GlymaSecurableObject
                 {
                     SecurableObjectUid = Id,
                     SecurableParentUid = this is RootMap ? ParentId : Guid.Empty,
                 },
                 
                 Value = value
             };
         }
     }
     return null;
 }
Exemplo n.º 14
0
 public bool GetValue(GlymaSecurityGroup group)
 {
     foreach (var permissionGroup in PermissionGroups)
     {
         var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
         if (found != null)
         {
             return  found.IsSelected.HasValue && found.IsSelected.Value;
         }
     }
     return false;
 }
Exemplo n.º 15
0
 public void LoadValue(GlymaSecurityGroup group, bool value)
 {
     foreach (var permissionGroup in PermissionGroups)
     {
         var found = permissionGroup.FirstOrDefault(q => q.Id == group.GroupId);
         if (found != null)
         {
             found.SetValue(value);
         }
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Checks if the the group appears in a higher permission level
        /// </summary>
        /// <param name="group"></param>
        /// <param name="currentPermissionLevel"></param>
        /// <returns>True if the group is in a higher level</returns>
        private bool ExistsInHigherPermissionLevel(GlymaSecurityGroup group, GlymaPermissionLevel currentPermissionLevel)
        {
            bool result = false;

            IList <GlymaSecurityGroup> projectManagerGroups = _groups[GlymaPermissionLevel.GlymaProjectManager];
            IList <GlymaSecurityGroup> mapManagersGroups    = _groups[GlymaPermissionLevel.GlymaMapManager];
            IList <GlymaSecurityGroup> mapAuthorGroups      = _groups[GlymaPermissionLevel.GlymaMapAuthor];
            IList <GlymaSecurityGroup> oldMapAuthorsGroups  = _groups[GlymaPermissionLevel.GlymaMapAuthorOld];

            switch (currentPermissionLevel)
            {
            case GlymaPermissionLevel.GlymaMapManager:
                foreach (GlymaSecurityGroup securityGroup in projectManagerGroups)
                {
                    if (group.GroupId == securityGroup.GroupId)
                    {
                        result = true;
                        break;     //found match, break foreach loop early
                    }
                }
                break;

            case GlymaPermissionLevel.GlymaMapAuthor:
                foreach (GlymaSecurityGroup securityGroup in mapManagersGroups)
                {
                    if (group.GroupId == securityGroup.GroupId)
                    {
                        result = true;
                        break;     //found match, break foreach loop early
                    }
                }
                foreach (GlymaSecurityGroup securityGroup in projectManagerGroups)
                {
                    if (group.GroupId == securityGroup.GroupId)
                    {
                        result = true;
                        break;     //found match, break foreach loop early
                    }
                }
                break;

            case GlymaPermissionLevel.GlymaMapReader:
                foreach (GlymaSecurityGroup securityGroup in mapAuthorGroups)
                {
                    if (group.GroupId == securityGroup.GroupId)
                    {
                        result = true;
                        break;     //found match, break foreach loop early
                    }
                }
                foreach (GlymaSecurityGroup securityGroup in oldMapAuthorsGroups)
                {
                    if (group.GroupId == securityGroup.GroupId)
                    {
                        result = true;
                        break;     //found match, break foreach loop early
                    }
                }
                foreach (GlymaSecurityGroup securityGroup in mapManagersGroups)
                {
                    if (group.GroupId == securityGroup.GroupId)
                    {
                        result = true;
                        break;     //found match, break foreach loop early
                    }
                }
                foreach (GlymaSecurityGroup securityGroup in projectManagerGroups)
                {
                    if (group.GroupId == securityGroup.GroupId)
                    {
                        result = true;
                        break;     //found match, break foreach loop early
                    }
                }
                break;
            }
            return(result);
        }