internal GetAllSecurityGroupsResponse GetAllGlymaSecurityGroups() { GetAllSecurityGroupsResponse result = new GetAllSecurityGroupsResponse() { HasError = false }; IList <string> permissionLevelNames = new List <string>(); permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaProjectManager)); permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapManager)); permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthor)); permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReader)); permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReaderOld)); permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthorOld)); Dictionary <GlymaPermissionLevel, IList <GlymaSecurityGroup> > results = new Dictionary <GlymaPermissionLevel, IList <GlymaSecurityGroup> >(); foreach (string permissionLevelName in permissionLevelNames) { GlymaPermissionLevel permissionLevel = GlymaPermissionLevelHelper.GetPermissionLevelByName(permissionLevelName); GetSecurityGroupsResponse response = GetSecurityGroups(permissionLevel); if (!response.HasError) { IList <GlymaSecurityGroup> groups = response.Result; if (results.ContainsKey(permissionLevel)) { foreach (GlymaSecurityGroup group in groups) { if (!results[permissionLevel].Contains(group)) { results[permissionLevel].Add(group); } } } else { results.Add(permissionLevel, groups); } } else { result.HasError = true; result.ErrorMessage = response.ErrorMessage; break; //an error occurred so stop at this point } } if (!result.HasError) { GlymaSecurityGroupCollection groups = new GlymaSecurityGroupCollection(this, results); IDictionary <GlymaPermissionLevel, IList <GlymaSecurityGroup> > filteredGroups = groups.FilterGroups(); result.Result = filteredGroups; } return(result); }
private bool IsUserAuthorized(GlymaPermissionLevel permissionLevel) { bool hasAccess = false; try { IGlymaPermission highestPermissionLevel = this.GetHighestPermissionLevel(); if (GlymaPermissionLevelHelper.IsPermissionGreaterOrEqual(highestPermissionLevel.PermissionLevel, permissionLevel)) { hasAccess = true; } } catch (Exception) { hasAccess = false; } return(hasAccess); }
/// <summary> /// Gets the highest permission level that a user has /// </summary> /// <param name="webUrl"></param> /// <returns></returns> public GetPermissionNameResponse GetUsersPermissionLevelName(string webUrl) { GetPermissionNameResponse result = new GetPermissionNameResponse() { HasError = false }; GetPermissionLevelResponse response = GetUsersPermissionLevel(webUrl); if (!response.HasError) { result.Result = GlymaPermissionLevelHelper.GetPermissionLevelName(response.Result); } else { result.HasError = true; result.ErrorMessage = response.ErrorMessage; } return(result); }
/// <summary> /// Gets the highest permission (role) name that the current user has if they have access to the object /// </summary> /// <param name="webUrl">The URL for the SP site</param> /// <param name="securableObject">An object that contains the Parent and Object ID's /// SecurableParentUid: The ID of the securable parent (Guid.Empty for projects), /// SecurableObjectUid: The ID of the securable object (root map UID or project UID if securing a project)</param> /// <returns>The Glyma permission level name if the user has access or null if the user doens't have access</returns> public GetPermissionNameResponse GetPermissionNameForObject(string webUrl, GlymaSecurableObject securableObject) { GetPermissionNameResponse result = new GetPermissionNameResponse() { HasError = false }; GetPermissionLevelResponse response = GetPermissionLevelForObject(webUrl, securableObject); if (!response.HasError) { result.Result = GlymaPermissionLevelHelper.GetPermissionLevelName(response.Result); } else { result.HasError = true; result.ErrorMessage = response.ErrorMessage; } return(result); }
/// <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); }